views:

146

answers:

1

Hi,

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  A: 

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.

Pascal Thivent
Sorry read one thing and typed another, that is in the ear as well though:D:\Repository\App\AppEA\App-ear\target\App-ear.ear\CoreJms-1.0-SNAPSHOT.jar\com\company\app\jms\IJmsSessionFactory.class
James
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?
James
@James Please provide the requested information and ping me after update.
Pascal Thivent
@Pascal Thivent 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.
James
@Pascal Thivent Thanks to your answer I think I am almost there. I was not understanding the need to specifiy the dependencies in the ear pom I thought it would pick them up from the individual module pom's. I am getting, what I hope is, one last issue which I can't explain. This error:javax.enterprise.system.tools.deployment.org.glassfish.deployment.commad-1;|Error in annotation processing: java.lang.NoClassDefFoundError: org/springframework/beans/factory/BeanNameAware|#]is stumping me, I am not using the springframework and it looks like it is glassfish which requires this.Any ideas?
James
@James To my knowledge, GlassFish doesn't use Spring. It must be something else. Are you sure this is not a transitive dependency of your code?
Pascal Thivent
@Pascal Thivent based on your comment I have looked for a dependency and can't find one. I have looked at the dependency graph of the ear pom and nothing spring appears there. Even if I do a text search for 'springframework' in the project I get nothing. Is there any way to see what annotation the processing is failing on? Or anyway I can figure out what is going on here.
James
@James I have no idea from where this unsatisfied dependency is coming from. Could you paste the full log to http://pastie.org or something like that? (not sure I'll be able to help though).
Pascal Thivent
@Pascal Thivent Thank you for the help. I have narrowed down the issue and think it is because I am using activemq. I am just using the activemq-all jar which does not need any other dependancies, but I think there must be some annotations to the classes in the jar that have a depedency on spring. I am looking at ways to including the activemq jars in glassfish so I don't get this issue. Thanks
James