Java:Enum:NoClassDefFoundError

Java:Enum:NoClassDefFoundError,java,maven,jboss,enums,noclassdeffounderror,Java,Maven,Jboss,Enums,Noclassdeffounderror,在J2EE应用程序中使用enum时,我遇到了一些问题。我在无状态服务bean中的一个交换机案例中使用enum 在运行时,我在switch语句中看到以下异常: Caused by: java.lang.NoClassDefFoundError: com/comp/service/TestServiceImpl$1 这个问题已经在一个线程上进行了广泛的讨论。但我看不到有人提到任何解决这一问题的办法 在我的例子中,我使用JBOSS EAP6.1服务器。JDK版本是1.7。代码是在EclipseIDE

在J2EE应用程序中使用enum时,我遇到了一些问题。我在无状态服务bean中的一个交换机案例中使用enum

在运行时,我在switch语句中看到以下异常:

Caused by: java.lang.NoClassDefFoundError: com/comp/service/TestServiceImpl$1
这个问题已经在一个线程上进行了广泛的讨论。但我看不到有人提到任何解决这一问题的办法

在我的例子中,我使用JBOSS EAP6.1服务器。JDK版本是1.7。代码是在EclipseIDE中使用Maven构建的。应用程序被部署为EAR归档。如何将这个额外生成的类文件添加到EAR归档中的类路径中?有没有其他办法解决这个问题

2014年6月29日更新: 我试图从命令行构建应用程序。然后生成这个额外的类文件。我能够成功地部署和执行应用程序。这似乎是eclipse的错误。你知道怎么解决吗

EAR项目中的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>demo-maven</artifactId>
        <groupId>com.comp.demo</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>demo-ear</artifactId>
    <packaging>ear</packaging>

    <name>demo - ear</name>

    <url>www.comp.com</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>

    <dependencies>

        <!-- Depend on the ejb module and war so that we can package them -->
        <dependency>
            <groupId>com.comp.demo</groupId>
            <artifactId>demo-web</artifactId>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>com.comp.demo</groupId>
            <artifactId>demo-service</artifactId>
            <type>ejb</type>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.parent.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>${version.ear.plugin}</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></modules>
                    <fileNameMapping>no-version</fileNameMapping>
                </configuration>
            </plugin>
            <!-- The JBoss AS plugin deploys your ear to a local JBoss EAP container -->
            <!-- Due to Maven's lack of intelligence with EARs we need to configure 
                the jboss-as maven plugin to skip deployment for all modules. We then enable 
                it specifically in the ear module. -->
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app will need. -->
            <!-- By default that is to put the resulting archive into the 'deployments' folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-ear-plugin</artifactId>
                        <version>${version.ear.plugin}</version>
                        <configuration>
                            <outputDirectory>deployments</outputDirectory>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

4.0.0
演示专家
com.comp.demo
0.0.1-快照
演示耳
耳朵
演示耳
www.comp.com
Apache许可证,版本2.0
回购
http://www.apache.org/licenses/LICENSE-2.0.html
com.comp.demo
演示网站
战争
com.comp.demo
演示服务
ejb
${project.parent.artifactId}
org.apache.maven.plugins
maven耳朵插件
${version.ear.plugin}
6.
解放党
无版本
org.jboss.as.plugins
jboss作为maven插件
假的
openshift
maven耳朵插件
${version.ear.plugin}
部署
ejb项目中的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>demo-maven</artifactId>
        <groupId>com.comp.demo</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>demo-service</artifactId>
    <packaging>ejb</packaging>

    <name>demo - service</name>

    <url>www.comp.com</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>

    <dependencies>

        <!-- Declare the APIs we depend on and need for compilation. All of them 
            are provided by JBoss EAP 6 -->

        <!-- Import the EJB API, we use provided scope as the API is included in 
            JBoss EAP 6 -->
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the CDI API, we use provided scope as the API is included in 
            JBoss EAP 6 -->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the JPA API, we use provided scope as the API is included in 
            JBoss EAP 6 -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- JSR-303 (Bean Validation) Implementation -->
        <!-- Provides portable constraints such as @Email -->
        <!-- Hibernate Validator is shipped in JBoss EAP 6 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>org.jboss.ejb3</groupId>
            <artifactId>jboss-ejb3-ext-api</artifactId>
            <version>2.0.0-redhat-2</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>

        <!-- Test scope dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.5.Final</version>
    <scope>test</scope>
</dependency>


        <!-- Optional, but highly recommended -->
        <!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA) 
            JPA from JUnit/TestNG -->
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <scope>test</scope>
        </dependency>

<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>${version.ejb.plugin}</version>
                <configuration>
                    <!-- Tell Maven we are using EJB 3.1 -->
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- The default profile skips all tests, though you can tune it to run 
                just unit tests based on a custom pattern -->
            <!-- Seperate profiles are provided for running all tests, including Arquillian 
                tests that execute in the specified container -->
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${version.surefire.plugin}</version>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <!-- An optional Arquillian testing profile that executes tests in your 
                JBoss EAP instance -->
            <!-- This profile will start a new JBoss EAP instance, and execute the 
                test, shutting it down when done -->
            <!-- Run with: mvn clean test -Parq-jbossas-managed -->
            <id>arq-jbossas-managed</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-managed</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

        <profile>
            <!-- An optional Arquillian testing profile that executes tests in a remote 
                JBoss EAP instance -->
            <!-- Run with: mvn clean test -Parq-jbossas-remote -->
            <id>arq-jbossas-remote</id>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.as</groupId>
                    <artifactId>jboss-as-arquillian-container-remote</artifactId>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

    </profiles>

</project>

4.0.0
演示专家
com.comp.demo
0.0.1-快照
演示服务
ejb
演示服务
www.comp.com
Apache许可证,版本2.0
回购
http://www.apache.org/licenses/LICENSE-2.0.html
org.jboss.spec.javax.ejb
jboss-ejb-api_3.1_规范
假如
javax.enterprise
CDIAPI
假如
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
假如
org.hibernate
休眠验证器
假如
org.jboss.ejb3
jboss-ejb3-ext-api
2.0.0-redhat-2
罐子
假如
朱尼特
朱尼特
测试
org.mockito
莫基托所有
1.9.5
测试
org.hibernate
休眠实体管理器
4.3.5.最终版本
测试
org.jboss.arquillian.junit
arquillian junit容器
测试
org.jboss.arquillian.protocol
arquillian协议servlet
测试
爪哇
JavaEEAPI
6
罐子
假如
${project.artifactId}
maven ejb插件
${version.ejb.plugin}
3.1
违约
真的
maven surefire插件
${version.surefire.plugin}
真的
arq jbossas管理
org.jboss.as
jboss作为arquillian容器管理
测试
arq jbossas远程
org.jboss.as
jboss作为arquillian容器远程
测试

我有一个与您的项目配置非常相似的配置:eclipse、Maven、JDK 1.6、JBoss EAP6.2,在交换机案例中使用enum时,我遇到了与java.lang.NoClassDefFoundError相同的问题

我已经找到了一个解决方法:生成一个ear文件(在我的例子中这是一个war),然后从JBoss管理控制台手动安装它。我注意到战争包括了1美元的必要课程,然后你不会得到例外

这只是一个解决办法,但对我来说很有效。此解决方案的一个优点是,后续部署可以通过eclipse完成


我将听取您问题的答案,因为我需要一个真正的解决方案。

我遇到了一个类似的问题,简单的解决方法是将枚举定义为public而不是private

(没有时间验证,但我的直觉是,这会导致类不会被创建为名称$