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?
Asked
Active
Viewed 1.3k times
12
-
3Excellent question. Why is the deployment/structure of EJB/EAR packaging so much more difficult than WAR??? This should be an automatic, quite typical, use case. – Roboprog Feb 20 '13 at 00:05
1 Answers
18
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
- 24,062
- 5
- 49
- 58
-
1The 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 – Brett Kail Sep 03 '09 at 05:24
-
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 Sep 03 '09 at 13:30
-
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 Sep 03 '09 at 13:36
-
1