tags:

views:

344

answers:

1

I have an old J2EE application (J2EE 1.3), which packages into an EAR, and in the EAR, there are WARs and EJB JARs. Now one of the EJB JARs needs to refer to some 3rd party library JARs, so what's the best place to package those JARs and how?

+2  A: 

They go in the ear file, at the root or you can create a lib directory to store them. Any project (EJB or WAR) that needs to reference them must include them in the Class-Path: of the manifest file.

Ear contents

  - log4j.jar
  - lib
     - commons-lang.jar
  - MyEJBProj.jar
  - MyWAR.war

MyEJBProj contents

 - classes
 - META-INF
    - MANIFEST.MF

MANIFEST.MF

    Manifest-Version: 1.0
    Class-Path: log4j.jar lib/commons-lang.jar
Robin
The official filename is MANIFEST.MF, and the formatting of that file can be quite picky. You need all the content on the same line (or use a single space character as a prefix on following lines for continuation), and you need to delimit paths with ",". In other words:Class-Path: log4j.jar, lib/commons-lang.jar
bkail
Correct on the name (edited to reflect that), should be all caps, but the classpath can simply be separated by spaces, even on the same line. Just make sure there is not a space after the last entry as it indicates a continuation. Eclipse, for example will write/display the classpath with one jar per line and a space at the end of each line if another follows.
Robin
Don't forget to include two line breaks at the end of the MANIFEST.MF. I remember an old bug where this was necessary, because otherwise some of the content above would be ignored...
Martin Klinke
That is why I let my IDE write the thing whenever possible ;-)
Robin