Rodrigo Menezes
Rodrigo Menezes

Reputation: 245

java.lang.NoClassDefFoundError Erro with a maven dependency on EJB project in Jboss 7

I have a EAR project linked to a War and Ejb project.

I'm trying to add Xstream dependence do EJB project via pom:

    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.7</version>
    </dependency>

The project compile fine and the Ejbs jars are deployed to EAR deploy dir:

             Pasta de C:\dev\jboss-as-web-7.0.1.Final\standalone\deployments\ProjectXYZWebEAR.ear

            20/10/2014  18:03    <DIR>          .
            20/10/2014  18:03    <DIR>          ..
            09/04/2012  19:40           443.432 antlr-2.7.6.jar
            09/04/2012  19:40            43.033 asm-3.1.jar
            09/04/2012  19:40           608.376 c3p0-0.9.1.jar
            09/04/2012  19:40           278.682 cglib-2.2.jar
            09/04/2012  19:40           559.366 commons-collections-3.1.jar
            09/04/2012  19:40            94.636 commons-dbcp-20030825.184428.jar
            09/04/2012  19:40           159.509 commons-io-2.0.1.jar
            09/04/2012  19:40           243.016 commons-lang-2.2.jar
            09/04/2012  19:40            38.815 commons-pool-20030825.183949.jar
            09/04/2012  19:40           313.898 dom4j-1.6.1.jar
            28/04/2014  14:13            45.024 hamcrest-core-1.3.jar
            23/08/2012  10:32           365.546 hibernate-annotations-3.5.6-Final.jar
            23/08/2012  10:31             6.413 hibernate-c3p0-3.6.8.Final.jar
            09/04/2012  19:40            71.283 hibernate-commons-annotations-3.2.0.Final.jar
            23/08/2012  10:32         3.119.425 hibernate-core-3.6.8.Final.jar
            23/08/2012  10:32           426.283 hibernate-entitymanager-3.6.8.Final.jar
            09/04/2012  19:40           100.884 hibernate-jpa-2.0-api-1.0.0.Final.jar
            23/08/2012  10:31           366.592 hibernate-validator-4.2.0.Final.jar
            09/04/2012  19:40           446.045 javassist-3.1.jar
            09/04/2012  19:40            15.071 jta-1.1.jar
            20/10/2014  18:03    <DIR>          META-INF
            20/10/2014  18:03    <DIR>          ProjectXYZWebEJB-2.27.46.7.jar
            20/10/2014  18:03    <DIR>          ProjectXYZWebWAR-2.27.46.7.war
            09/04/2012  19:40            25.689 slf4j-api-1.6.2.jar
            28/04/2014  14:13             7.668 slf4j-simple-1.6.2.jar
            09/04/2012  19:40            47.433 validation-api-1.0.0.GA.jar
            20/10/2014  10:05             7.188 xmlpull-1.1.3.1.jar
            09/04/2012  19:45            24.956 xpp3_min-1.1.4c.jar
            20/10/2014  10:05           531.571 xstream-1.4.7.jar

But in runtime I got this error when invoke a Stateless EJB method: 18:14:49,977 ERROR [stderr] (http--0.0.0.0-8084-2) Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.XStream from [Module "deployment.PortalScopeWebEAR.ear.PortalScopeWebEJB-2.27.46.7.jar:main" from Service Module Loader]

If I add the xstream dependence to WAR project I can invoke Xstream classes with no error.

Ty in advance.

Upvotes: 1

Views: 3724

Answers (1)

mendieta
mendieta

Reputation: 3500

I think the problem is that your are not placing your ejb jar dependencies in a lib folder inside your ear. If you are using maven ear plugin, try the following

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <!-- Tell Maven we are using Java EE 6 -->
        <version>6</version>
        <!-- Use Java EE ear libraries as needed. Java EE ear libraries are 
            in easy way to package any libraries needed in the ear, and automatically 
            have any modules (EJB-JARs and WARs) use them -->
        <defaultLibBundleDir>lib</defaultLibBundleDir>
        <modules>
            <ejbModule>
                <groupId>xx</groupId>
                <artifactId>xx</artifactId>
                <bundleFileName>xx</bundleFileName>
            </ejbModule>
            <webModule>
                <groupId>xx</groupId>
                <artifactId>xx</artifactId>
                <contextRoot>xx</contextRoot>
            </webModule>
        </modules>
    </configuration>
</plugin>

Also, check your poms, you are copying jars that are provided by jboss.. for example hibernate jars.. Make sure you are using <scope>provided</scope> for those kind of dependencies

Upvotes: 3

Related Questions