简体   繁体   中英

How to give priority to a jar file in eclipse classpath?

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 .

您可以按类路径顺序向上移动(右键单击项目,选择Build Path,然后选择Configure Build Path,然后选择Order and Export)

  • Go into your Project Properties > Build Path .
  • In the Order and Export tab , find 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 above servlet-api-2.3.jar .
  • Finally press OK .

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.

  1. remove servlet-api-2.3.jar, you don't need it.
  2. or move j2ee-6.1.jar higher up than servlet-api-2.3.jar in the lib list.

我不知道它是否是规范的一部分,但是当我在过去完成此操作时,在类路径上更早地放置“更高”的优先级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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM