如何优先考虑eclipse类路径中的jar文件?
我的两个 jar 文件下有一个类文件 TagAttributeInfo
。
j2ee-6.1.jar,servlet-api-2.3.jar .
现在我需要从 j2ee-6.1.jar
调用该类,但在运行时,它采用 servlet-api-2.3.jar
的类,但我不这样做不想要。 任何人都可以帮我确定类路径中 jar 文件的优先级,以便我优先考虑 j2ee-6.1.jar
。
There is a class file TagAttributeInfo
which is under two of my jar files.
j2ee-6.1.jar,servlet-api-2.3.jar .
Now i need that class to be called from j2ee-6.1.jar
but in runtime ,it is taking the class of servlet-api-2.3.jar
,which i don't want.
Can anybody help me to prioritize the jar file in class path so that i will give first priority to j2ee-6.1.jar
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以将其按类路径顺序向上移动(右键单击项目,选择“构建路径”,然后选择“配置构建路径”,然后选择“排序和导出”)
You move it up in the classpath order (right click on the project, select Build Path, followed by Configure Build Path and then Order and Export)
j2ee-6.1.jar
,然后按向上按钮将其在类路径顺序中向上移动。继续按向上键,直到它位于servlet-api-2.3.jar
上方。确定
。j2ee-6.1.jar
and press the Up button to move it higher up in the class path order. Keep pressing Up until it is aboveservlet-api-2.3.jar
.OK
.将使用它在类路径上找到的第一个包含它要查找的类的 jar。因此,您可以通过将类的 jar 放在类路径的开头来确定类的优先级。
我不确定如何在 Eclipse 中执行此操作,但可能有一些与类路径上的 jar 相对应的项目依赖项列表,希望您可以对该列表中的元素进行排序并将 jar 放在顶部。尝试在项目设置面板中查找它。
The first jar that it finds on the classpath that has the class it's looking for will be used. So you can prioritize your class by putting its jar at the beginning of the classpath.
How exactly you would do this in Eclipse I'm not sure, but there's probably some list of project dependencies that correspond to the jars on the classpath, and hopefully you can order the elements on that list and put your jar on the top. Try looking for it in the project settings panel.
我不知道它是否是规范的一部分,但是当我过去这样做时,将“更高”优先级的 jar 放在类路径的前面是可行的。
I don't know if it's part of the spec but placing the "higher" priority jar earlier on the classpath works when I've done this in the past.
您确定需要这两个 jar 文件吗?
无论如何,在“构建路径”对话框中,您可以指定要搜索的 jar 文件的顺序。
Are you sure you need both jar files?
Anyway, in the Build Path dialog you can specify the order for jar files to be searched.
您的类路径中应该只有这些 jar 之一,以便能够编译您的类。但在运行时,该 jar 将位于您的应用程序服务器类路径中,并且您将无法将其替换为另一个。
如果您的容器是 JEE6 容器,则它使用 servlet 3.0,并且 servlet-api-2.3.jar 已过时,不应位于类路径中。如果您的容器仅支持 servlet api 2.3,那么您将无法在此容器中使用 jee6 jar 中的类。
Only one of these jars should be in your classpath, to be able to compile your classes. But at runtime, the jar will be in your application server classpath, and you won't be able to replace it with the other one.
If your container is a JEE6 container, then it uses servlet 3.0 and the servlet-api-2.3.jar is obsolete and should not be in the classpath. If your container only supports servlet api 2.3, then you won't be able to use classes from the jee6 jar in this container.