Error deploying ear to Glassfish

2019-08-02 14:11发布

问题:

We have a EAR with 3 EJB modules. I am trying to deploy to glassfish but am hitting an error I can't explain or work out how best to identify.

[#|2010-08-03T14:39:15.570+0100|INFO|glassfish3.0.1|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|[AutoDeploy] Selecting file /export/home/myapp/apps/domains/myapp/autodeploy/App-ear.ear for autodeployment.|#]

[#|2010-08-03T14:39:18.654+0100|WARNING|glassfish3.0.1|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: com/company/app/controller/IMessagingProcessor|#]

[#|2010-08-03T14:39:20.470+0100|SEVERE|glassfish3.0.1|global|_ThreadID=28;_ThreadName=Thread-1;|Class [ Lcom/company/app/jms/IJmsSessionFactory; ] not found. Error while loading [ class com.company.app.eventprocessor.provider.EventProvider ]|#]

I have checked the classes mentioned in the ClassNotFoundException and they are definetly in a Jar in the ear and I have no compilation issues in eclipse/maven.

D:\Repository\App\AppEA\App-ear\target\App-ear.ear\CoreJms-1.0-SNAPSHOT.jar\com\company\app\controller\IMessagingProcessor.class

D:\Repository\App\AppEA\App-ear\target\App-ear.ear\EventProcessor-ejb-1.0-SNAPSHOT.jar\com\company\app\eventprocessor\provider\EventProvider.class

Any pointers are much appreciated.

James

回答1:

Actually, you're not getting a ClassNotFoundException, you're getting a NoClassDefFoundError and I suspect some dependencies to be missing, as suggested by:

Class [ Lcom/company/app/jms/IJmsSessionFactory; ] not found. Error while loading [ class com.company.app.eventprocessor.provider.EventProvider 

Where is that com.company.app.jms.IJmsSessionFactory?


I have now cut the ear down to a single ejb module and am getting the NoClassDef for Lorg/apache/log4j/Logger however the log4j jar is also in the ear. It feels like I must be missing something fundamental here?

Where is the log4j.jar exactly? In /lib? Can you actually show the structure of your EAR? And please also show the MANIFEST.MF of your EJB-JAR.

Just in case, here is a relevant quote from Packaging EJB 3 Applications:

Packaging EJB-JAR

...

The EJB-JAR file must include the interfaces and bean classes. It may also include any helper classes. Optionally the helper classes may be packaged in a separate JAR file in the EAR file. You have two options:

  • The JAR containing helper classes may be packaged in the lib directory of the EAR file. Using this approach, the packaged classes will be automatically visible to all modules in the EAR module.
  • If you want to limit the visibility to only a specific EJB-JAR or WAR module, you can create an entry in the Manifest.mf file of the module that contains a Class-Path attribute to the JAR file.

Now that you know the structure of EJB-JAR and how to package it, let's look at the elements of ejb-jar.xml.


Based on your comments I think I am understadning my issue. It would appear I am not packaging the ear correctly, I don't think the maven dependencies are referenced correctly. If I simply build my ejb jar it does not include any of the dependant jars. Should I be specifying something in the pom to include the jars ejb-jar? I have the build plugin <artifactId>maven-ejb-plugin</artifactId> and packaging <packaging>ejb</packaging> set.

Bundling dependencies into an EJB-JAR is not supported (see MEJB-3) mostly because jar-within-jar is not part of the JAR specification (and might not be supported by all EJB container) and does not comply with Sun's advice regarding J2EE packaging in general.

So while you may ignore this rule (see this trick or this one), the standard way would be to package the EJB-JAR and all the JARs it depends on in an EAR. This is my recommendation and I think that this post might help: Because I always forget how to use maven-ear-plugin.