6

I have a JAR file for authorization. I need it for each of my WAR files. All the WAR files are packaged in an EAR file. Do I have to repeat this common JAR in every WAR, or is there a structure for common libraries?

So my example looks something like this...

big.ear
  - META-INF
    - MANIFEST.MF
    - application.xml
  - appl1.war
    - META-INF
      - MANIFEST.MF
    - WEB-INF
      - web.xml
      - lib
        - unique1.jar
        - unique2.jar
        - unique3.jar
        - common1.jar
    - jsps/html/etc
  - appl2.war
    - META-INF
      - MANIFEST.MF
    - WEB-INF
      - web.xml
      - lib
        - unique3.jar
        - unique4.jar
        - common1.jar
    - jsps/html/etc
  - appl3.war
    - META-INF
      - MANIFEST.MF
    - WEB-INF
      - web.xml
      - lib
        - unique5.jar
        - common1.jar
    - jsps/html/etc

Each of my WAR applications can see common1.jar, but it is in the EAR three times.

Where in the EAR structure could I put common1.jar so that appl1, appl2, and appl3 could see it without repeating it three times?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dacracot
  • 22,002
  • 26
  • 104
  • 152

3 Answers3

6

The standard way is to put the JARs at the root of your EAR and reference them in the Class-Path attribute of the WARs' META-INF/MANIFEST.MF. See this article.

Check your container's documentation to make sure it is supported.

Olivier
  • 1,232
  • 6
  • 10
1

It’s in the JEE5 spec, chapter EE 8.2.1:

A .ear file may contain a directory that contains libraries packaged in JAR files. The library-directory element of the .ear file’s deployment descriptor contains the name of this directory. If a library-directory element isn’t specified, or if the .ear file does not contain a deployment descriptor, the directory named lib is used.

Strinder
  • 2,111
  • 2
  • 21
  • 34
-4

Your app server should have a folder like shared/lib where you can put jar files that can be shared by multiple webapps in the same instance.

neesh
  • 5,167
  • 6
  • 29
  • 32
  • This will probably work, but I consider it bad practice. The EAR should be self contained. – dacracot Jan 16 '09 at 16:51
  • 1
    Definitely a bad practice. What if you want to upgrade this jar? You should be able to do that with a deployment, you shouldn't have to alter the server setup. – cynicalman Jan 16 '09 at 16:53