tags:

views:

522

answers:

2

I'm getting a java.lang.ClassNotFoundException: javax.ejb.EJBObject error when I'm running my application as a JAR file. When running it in Eclipse everything is working fine.

The application properly access the main class and the main method. But when it tries to load the application context it cannot resolve a reference to an EJB bean. I then get the following error:

Error creating bean with name 'bc' defined in class path resource [blabla.xml]:
    Initialization of bean failed; 
nested exception is 
    java.lang.NoClassDefFoundError: javax/ejb/EJBObject 
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) 
        ... 
Caused by: 
    java.lang.ClassNotFoundException: javax.ejb.EJBObject

I've included all runtime-scoped dependencies with Maven in the JAR file.

Do you know any further information regarding this error?

+1  A: 

The application properly access the main class and the main method.

Thus, you're executing it as a "plain vanilla" client Java application? EJB's are supposed to run in an EJB container, like Glassfish, JBoss AS, etcetera. This exception inticates that no EJB implementation can be found in the classpath.

What is it, that you're trying to achieve?

BalusC
A: 

A little list of things to check:

  • Is the EJBObjectclass located in a dependency with provided scope?
  • Is the JAR containing the EJBObject class really on the classpath? I.e., do you either add it to the class path when running the JAR, or do you use the onejar-plugin to put your dependencies into the JAR?
  • If you are using onejar: Are you really running the JAR created by onejar (myproject.one-jar.jar), and not the one without the dependencies (myproject.jar)?
Henning
Of course the JAR containing EJBObject was not on the classpath. Although specified in the pom.xml with the scope "compile", the maven-jar-plugin didn't include it in the classpath. This was due to the JAR being also specified in the parent pom als "provided". Strangely the setting of the parent pom did overrule the one of the child.
Bernhard V