包中包含具有相同名称的对象和包 [英] Package contains object and package with same name

查看:737
本文介绍了包中包含具有相同名称的对象和包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Maven或Eclipse编译Scala时遇到问题,我尝试从包含命名空间和同名类的Java jar导入类。

我可以用<$编译但是,c $ c> scalac 。

I am having problems compiling some Scala with Maven or Eclipse where I try to import a class from a Java jar which contains both a namespace and class of the same name.
I can compile with scalac, however.

例如Java项目(jar)包含:

E.g. the Java project (jar) contains:

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 )。

Using Maven 3.0.03/Eclipse 3.7.1 with Scala 2.9.0.1 (and maven-scala-plugin).

我遇到问题的jar是 jenkins-core-1.399.jar - 它肯定包含几个实例哪里有一个名称空间和名称相同的对象。

我试图在Scala中编写一个Jenkins插件(我可以用Java做这个但是更喜欢scala,因为我们所有的库都在scala中),这取决于使用Maven -

https:// wiki .jenkins-ci.org / display / JENKINS / Plugin + tutorial

The jar which I am having problems with is jenkins-core-1.399.jar - it definitely contains several instances where there is a namespace and object of the same name.
I am attempting to write a Jenkins plugin in Scala (I could do this in Java but would prefer scala since all of our libraries are in scala), which is dependent on using Maven -
https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial.

推荐答案

概述了这种限制在 SI-4695:包文件在类文件存在的情况下行为异常

SI-2089(命名限制)中所述使一些罐子无法使用),您可以尝试使用 resolve-term-conflict ,在 changeset 25145 中实施:

As suggested in SI-2089 (naming restriction makes some jars unusable), you could try and use the "resolve-term-conflict", as implemented in changeset 25145:


添加了一个 -Y 选项来解决包和对象之间的命名空间冲突。

这是一个生硬的工具:如果人们有很多这些冲突,他们需要以个别细致的方式解决,他们可能仍然没有运气。

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.

这篇关于包中包含具有相同名称的对象和包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆