简体   繁体   中英

Library dependencies outside WAR file

I have a requirement where i need to pack all the common classes of various web services and make them as dependencies(To avoid duplicates for multiple services). The structure of my EAR file is as follows:

  META-INF/MANIFEST.MF META-INF/application.xml commons-codec-1.2.jar MyWebService1.war MyWebService2.war MyWebService1.jar MyWebService2.jar EJB_Bean.jar 

Now i have included the dependency jar's under WAR file's Manifest as follows(Not sure if appropriate), `

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_51-b13 (Oracle Corporation)
Class-Path: MyWebService1.jar

In the stated structure when i try to deploy the EAR file onto web-logic server, i get java.lang.NoClassDefFoundError , But whereas if i move the dependency jars under WEB-INF/lib folder of my WAR and repack my EAR file, Deployment goes fine as expected.

Is there any way i can include my WAR file dependency libraries outside WAR file or even outside my EAR file is my question. Any help or suggestion would be appreciated.

A simple way to set the libraries of an EAR package is to create a lib folder right under the the EAR root and put your libraries inside.

In this case you will have something like this in your EAR:

META-INF/MANIFEST.MF
META-INF/application.xml
MyWebService1.war
MyWebService2.war
lib/commons-codec-1.2.jar
lib/MyWebService1.jar
lib/MyWebService2.jar
EJB_Bean.jar

In tomcat jar files can be placed inside the lib directory and these jar files gets available to all the applications deployed on that server. In web-logic there must be the similar way to do it. A lib folder from where the web-logic server loads all the jar files.

My first advice would be to use some kind of dependency management such as Maven , Gradle or Ivy - doing that by yourself is very difficult and error prone.

A simpler solution in your case would be to take your "common jars" (especially if they are shared between multiple applications), and add them to the shared library of your webserver. As an example, Tomcat will load all librairies that are placed under tomcat-dir/common/lib directory.

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