views:

34

answers:

2

Hello,

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?

+1  A: 

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.

Pascal Thivent
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!
Ankit Rathod
A: 

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.

bkail
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
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 http://java.sun.com/j2se/5.0/docs/guide/extensions) and the JAR File Specification (available at http://java.sun.com/j2se/5.0/docs/guide/jar/jar.html)."
bkail
Do you mean using `<java-home>\lib\ext`??
Pascal Thivent
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): http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.multiplatform.doc/info/ae/ae/ccws_installoptpkg.html
bkail