开发者

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

开发者 https://www.devze.com 2023-04-09 19:47 出处:网络
开发者_JAVA百科There is a class file TagAttributeInfo which is under two of my jar files. j2ee-6.1.jar,servlet-api-2.3.jar .
开发者_JAVA百科

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.


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)


  • 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消