java.lang.NoClassDefFoundError Erro,它对Jboss 7中的EJB项目具有maven依赖性

时间:2014-10-20 20:16:56

标签: maven deployment ejb noclassdeffounderror

我有一个与War和Ejb项目相关联的EAR项目。

我正在尝试通过pom添加Xstream依赖do EJB项目:

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

项目编译良好,Ejbs jar部署到EAR部署目录:

             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

但是在运行时,我在调用Stateless EJB方法时遇到了这个错误: 18:14:49,977 ERROR [stderr](http - 0.0.0.0-8084-2)引起:java.lang.ClassNotFoundException:来自[Module“deployment.PortalScopeWebEAR.ear.PortalScopeWebEJB-2.27的com.thoughtworks.xstream.XStream .46.7.jar:main“来自服务模块加载器”

如果我将xstream依赖项添加到WAR项目中,我可以调用Xstream类而没有错误。

提前Ty。

1 个答案:

答案 0 :(得分:2)

我认为问题在于您不会将ejb jar依赖项放在您耳内的lib文件夹中。如果您使用的是maven ear插件,请尝试以下

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

另外,检查你的poms,你正在复制jboss提供的jar ..例如hibernate jars ..确保你使用<scope>provided</scope>来表示那种依赖