Where To Put JAR Files To Avoid Conflicts?

白昼怎懂夜的黑 提交于 2019-12-13 00:28:54

问题


Windows XP Pro WebLogic 11g Tomcat 7 JDK 1.6

I've been putting supplemental JAR files in

JAVA_HOME/jre/lib/ext ( a JDK installation )

for years. It is much more convenient than altering my CLASSPATH and everything I develop has access to one set of stuff in one place.

I need a different or better approach though.

I recently installed WebLogic 11g on on my computer. Since I do not like having multiple JDKs or JVMs on my machine I set my JAVA_HOME variable to point to there.

I then put a servlet-api.jar there to compile my webapps. All was well.

Then I installed Tomcat 7. Tomcat 7 has its own servlet-api.jar in CATALINA_HOME/lib. Having a servlet-api.jar in CATALINA_HOME/lib and one in JAVA_HOME/jre/lib/ext causes Tomcat 7 to throw errors. However, I need one in JAVA_HOME/jre/lib/ext to compile my webapps.

Is there a more graceful solution than deleting servelt-api.jar from CATALINA_HOME/lib ?

Thanks


回答1:


Don't put the Jar in /ext, but compile against your actual EE framework. In that way you won't run into problems when the version of the .jars delivered with your Tomcat (or other EE installation) changes. So don't put the .jar in ext anymore and change the build path to your actual EE environment.




回答2:


From the Java Tutorial: The Extension Mechanism:

The extension mechanism provides a standard, scalable way to make custom APIs available to all applications running on the Java platform. Java extensions are also referred to as optional packages. This trail may use both terms interchangeably.

Extensions are groups of packages and classes that augment the Java platform through the extension mechanism. The extension mechanism enables the runtime environment to find and load extension classes without the extension classes having to be named on the class path. In that respect, extension classes are similar to the Java platform's core classes. That's also where extensions get their name -- they, in effect, extend the platform's core API.

Since this mechanism extends the platform's core API, its use should be judiciously applied. Most commonly it is used for well standarized interfaces such as those defined by the Java Community Process, although it may also be appropriate for site wide interfaces.



来源:https://stackoverflow.com/questions/10953031/where-to-put-jar-files-to-avoid-conflicts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!