java - 包包含具有相同名称的对象和包

标签 java eclipse scala jenkins maven-3

我在使用 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/

相关文章:

c++ - 如何总是用 Eclipse 编译一个 cpp 文件?

scala - 使用 Scala 的 ObservableMap

scala - 如何解释此 Scala 语法 "Class[_ >: Float with Int with Double]"

java - 在 Scala 中,除了继承之外,是否有一种技术可以知道何时调用了基类方法?

eclipse - 如何以编程方式从 IProject 获取所有 Eclipse 的链接文件夹

java - 在 google.Internal 服务器错误中添加联系人时出现异常

java - 如何在运行时更改文件扫描分隔符?

java - 简单的java层次结构问题

java - 使用 Java 而非 FCM 控制台发送 Firebase 通知

eclipse - 适用于 Eclipse 的 ColdFusion 9 行调试器