Take the 2-minute tour ×

Can we never refer any external 3rd party jar in independent ejb module (except copying the jar file in our appserver/lib)? This seems so illogical doesn't it? I don't want to create a Enterprise application. Why am i being forced to create an Enterprise application if i have to use any jar files?

Are there no alternatives available?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Well, I think I gave you a pretty good explanation in my previous answer:

EJBs don't have an equivalent of WEB-INF/lib and while packaging libraries inside an EJB-JAR might work with some application server, this is not part of the JAR specification1 and does not comply with Sun's standards regarding J2EE packaging.

I don't know what to add, if you want to write portable applications, you have to follow the rules. Whether they are due to technical limitations (see footnote), that's not the question, rules are rules.

The alternative would be to unpack the library in your EJB-JAR and that's incredibly ugly (copying your library in the application server classpath is IMO not an alternative for portable applications).

That being said, if you are using Java EE 6, you can now use a WAR instead of an EAR.

1 As explained in this thread, the jar spec does not support jar files within jar files (technically Java's URL support only goes one level deep: eg jar:url/to/file!path/ in/jar is allowed, but jar:jar:url/to/file!path/in/jar!path/in/jar is not) so while you could copy the jar files inside your ejb jar, nothing will be loaded from it.

share|improve this answer
Hi Pascal, undoubtedly you give very nice explanation. But i think this is one of the major limitation. Anyways, i don't have any option :(. Temporarily i have copied the log4j in my server's lib folder. Thanks again! –  TCM May 30 '10 at 5:54

You've already selected an answer, but I'll mention that "installed optional packages" might offer a solution, depending on the features available in your server.

share|improve this answer
Is that standard? My answer was about the standard, I didn't include app server specific features (like application library support in WLS 9+) –  Pascal Thivent May 31 '10 at 14:19
Java EE platform spec, section EE.8.2: "Java EE products are required to support the use of bundled and installed libraries as specified in the Extension Mechanism Architecture and Optional Package Versioning specifications (available at java.sun.com/j2se/5.0/docs/guide/extensions) and the JAR File Specification (available at java.sun.com/j2se/5.0/docs/guide/jar/jar.html)."; –  bkail Jun 1 '10 at 13:48
Do you mean using <java-home>\lib\ext?? –  Pascal Thivent Jun 1 '10 at 15:36
JAVA_HOME/lib/ext/ is one implementation. WAS also allows interaction with shared libraries (I don't know if any other vendors have something similar): publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/… –  bkail Jun 1 '10 at 16:07

Your Answer


