我在使用 Maven 或 Eclipse 编译某些 Scala 时遇到问题,我尝试从 Java jar 中导入一个类,该类同时包含 namespace 和同名类。
不过,我可以使用 scalac
进行编译。
例如Java 项目 (jar) 包含:
src/foo/bar.java
src/foo/bar/some_resource.txt
-> foobar.jar
Scala project references foobar.jar
Foobartest.scala:
import foo.bar
class foobartest {
}
编译器提示:
package foo contains object and package with same name: bar
one of them needs to be removed from classpath
将 Maven 3.0.03/Eclipse 3.7.1 与 Scala 2.9.0.1(和 maven-scala-plugin
)结合使用。
我遇到问题的 jar 是 jenkins-core-1.399.jar
- 它肯定包含多个实例,其中有一个 namespace 和同名对象。
我正在尝试在 Scala 中编写一个 Jenkins 插件(我可以在 Java 中执行此操作,但我更喜欢 scala,因为我们所有的库都在 scala 中),这取决于使用 Maven -
https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial .
最佳答案
SI-4695: package object misbehaves in the presence of classfiles 中概述了这种限制.
如 SI-2089 (naming restriction makes some jars unusable) 中的建议,您可以尝试使用“resolve-term-conflict
”,如 changeset 25145 中所实现的那样:
Added a
-Y
option to resolve namespace collisions between package and object.
It's a blunt instrument: if people have lots of these conflicts they need to resolve in individually nuanced fashion, they'll probably remain out of luck.
val termConflict = ChoiceSetting ("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", 113 List("package", "object", "error"), "error")
// Some jars (often, obfuscated ones) include a package and
// object with the same name. Rather than render them unusable,
// offer a setting to resolve the conflict one way or the other.
// This was motivated by the desire to use YourKit probes, which
// require `yjp.jar` at runtime. See SI-2089.
关于java - 包包含具有相同名称的对象和包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8984730/