Glassfish - Deploying two JARs with mutual dependencies
I'm a newcomer to Java EE so perhaps this is a dummy question. But I'm deploying a WAR and a JAR containing EJBs to a Glassfish 3.1. server. WAR has a reference to one of the EJBs in the JAR file. Is it mandatory to include the EJB JAR in the WAR file's lib
di开发者_JS百科rectory in order to make this work? Since both WAR and JAR will be running on the same app server, I was hoping that I wouldn't need to take care of these dependencies. However, I am getting a java.lang.NoClassDefFoundError
when I deploy the WAR if it doesn't include the EJB JAR (even though the EJB JAR is already deployed on the app server).
One of the cornerstones of Java EE is the notion that different components can run in containers which do not share a namespace, even though the components may be running in the same JVM. If you have modules that need to share a namespace, they need to be bundled into an EAR (prior to Java EE 6) or combined into a single WAR (a special case established by Java EE 6 for web applications that need to leverage EJBs).
This is a significant change from what folks familiar with Java SE development "know". For most Java SE programs, the container is the JVM process.
So, the answer to your question is, "No. You do not need to put the EJB jar in the lib directory of the WAR file. You could create an EAR file that would contain BOTH archives."
This may clarify the situation for you...
myEar.ear
+ myEJBs.jar
+ myWAR.war
+ lib
+ a-jar-that-has-classes-used-in-both-archives-above.jar
Have you tried packaging the WAR and JAR file together into an EAR file? The EAR file can have a lib directory where you can put JAR files to be loaded on the classpath FBO of the enterprise application.
This should solve your classloader issue.
精彩评论