更改 Eclipse 项目中 jars 的顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26539196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
changing the order of jars in eclipse project
提问by CodeMed
I recently converted an eclipse Java project into a dynamic web project. The imported jars listed in both the before and after projects are the same, but the change to dynamic web project causes the following compilation error:
我最近将 Eclipse Java 项目转换为动态 Web 项目。前后项目中列出的导入jar包是一样的,但是改成动态web项目会导致如下编译错误:
W3C_XML_SCHEMA_NS_URI cannot be resolved or is not a field
to be thrown by the following line of code:
由以下代码行抛出:
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
I have researched this error, and it seems to be thrown by conflicting versions of javax.xml.XMLConstants
in different jars, but I compared the lists of jars in both projects and they are identical, so I think one has to change the order of the jars. How does one do this?
我已经研究过这个错误,它似乎是由javax.xml.XMLConstants
不同 jar 中的冲突版本引发的,但是我比较了两个项目中的 jar 列表,它们是相同的,所以我认为必须更改 jar 的顺序。如何做到这一点?
Part of the solution might logically involve figuring out which jars include a package named javax.xml.XMLConstants
. So I followed @DiogoSantana's advice and used the Type wizard to get the results in the following print screen:
部分解决方案可能在逻辑上涉及找出哪些 jar 包含名为javax.xml.XMLConstants
. 所以我遵循@DiogoSantana 的建议并使用类型向导在以下打印屏幕中获得结果:
I then followed DiogoSantana's advice and ran mvn dependency:tree
and got the following results:
然后我按照 DiogoSantana 的建议运行mvn dependency:tree
并得到以下结果:
I next made the following change to the pom.xml
:
我接下来对 进行了以下更改pom.xml
:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
<exclusions>
<exclusion>
<groupId>jsr173_api</groupId>
</exclusion>
</exclusions>
</dependency>
And then I ran mvn clean install
before refreshing the eclipse project and even doing maven..update project
from within eclipse, but the error remains.
然后我mvn clean install
在刷新 eclipse 项目之前运行,甚至maven..update project
在 eclipse 中运行,但错误仍然存在。
Note: a search for the string infoset
in the pom
did not produce any results, so I tried the next higher level jar
.
注:为字符串搜索infoset
在pom
没有产生任何结果,所以我想下一个更高级别jar
。
采纳答案by Steve C
These days (in Java 6 and newer), you do not need any explicit JAXB, JAX-WS, XML Streaming API (JSR-173) or SAAJ jars because they are all included in the JDK. There are many other non-xml related APIs generally available too, such as javax.activation for example.
现在(在 Java 6 和更新版本中),您不需要任何显式的 JAXB、JAX-WS、XML Streaming API (JSR-173) 或 SAAJ jar,因为它们都包含在 JDK 中。还有许多其他非 xml 相关的 API 通常也可用,例如 javax.activation。
You should exclude anything to do with these if your environment is Java 6 or newer.
如果您的环境是 Java 6 或更新版本,您应该排除与这些有关的任何事情。
回答by user4572219
I had the same problem and was able to solve it by doing the following :
我遇到了同样的问题,并且能够通过执行以下操作来解决它:
- Right click the module which contains the file with error.
- Click "Properties"
- From left, select "Java Build Path"
- Now on right, select the "Order and Export" tab
- Click on the "JRE System Library" and click on the "Up" button to move it to the top of "Maven Dependencies"
- 右键单击包含错误文件的模块。
- 点击“属性”
- 从左侧选择“Java Build Path”
- 现在在右侧,选择“订购和导出”选项卡
- 点击“JRE System Library”,点击“Up”按钮,将其移至“Maven Dependencies”的顶部
回答by Ahmed MANSOUR
To fix this, open up the Build-Path menu of your project, switch to "Order and Export" tab, and ensure that the Java System library is in the top of the list than the Maven dependencies.
要解决此问题,请打开项目的 Build-Path 菜单,切换到“Order and Export”选项卡,并确保 Java System 库位于列表顶部而不是 Maven 依赖项。
回答by DiogoSantana
Fisrt use mvn dependency:tree to determine the dependency that depends of jsr173_api.
首先使用 mvn dependency:tree 来确定依赖于 jsr173_api 的依赖。
Supposed it is hibernate, like you mentioned (I don't know if that is true, didn't check it out). You need to exclude the jsr173_api like this:
假设它是休眠的,就像你提到的(我不知道这是不是真的,没有检查出来)。您需要像这样排除 jsr173_api:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
<exclusions>
<exclusion>
<groupId>jsr173_api</groupId>
</exclusion>
</exclusions>
</dependency>
回答by Harsha
Just to skip the error & proceed to execute the code just include the below line in your code. It will work.
只是为了跳过错误并继续执行代码,只需在代码中包含以下行。它会起作用。
final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema";