在maven中使用执行时的NoClassDefFoundError

时间:2013-12-02 15:41:43

标签: java maven maven-3 noclassdeffounderror

更新

基于其他人的评论和我自己的测试,这似乎只是Maven 3.1.1的一个问题 - 我logged a bug with codehaus


我创建了最小的maven POM文件,我可以突出显示问题(见下文)

我正在使用电子邮件服务器插件(用于集成测试)。我可以启动插件没问题:

mvn emailserver:run
[INFO] --- emailserver-maven-plugin:1.1.1:run (default-cli) @ project ---
[INFO] Starting Greenmail mail server...
[INFO] Started Greenmail mail server
[INFO] Waiting for command from client

但是,我已将插件配置为在integration-test生命周期之前运行。以这种方式运行时,我得到NoClassDefFoundError

mvn integration-test
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: com/icegreen/greenmail/util/ServerSetup

当我用-X执行maven以查看正在发生的事情时,在两种情况下它都显示了我所能看到的相同的依赖树,所以我有点不知道为什么我是获得通过生命周期阶段启动的异常。希望有人可以提供帮助!

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

    <groupId>com.mytest</groupId>
    <artifactId>project</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>Test Project</name>

    <build>
        <plugins>
            <plugin>
                <groupId>com.btmatthews.maven.plugins</groupId>
                <artifactId>emailserver-maven-plugin</artifactId>
                <configuration>
                    <monitorKey>emailserver</monitorKey>
                    <monitorPort>10025</monitorPort>
                    <serverName>greenmail</serverName>
                    <portOffset>13000</portOffset>
                    <useSSL>false</useSSL>
                </configuration>
                <executions>
                    <execution>
                        <id>run-mail</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <daemon>true</daemon>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-mail</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Maven信息:

> mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 16:22:22+0100)
Maven home: /opt/apache-maven
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /opt/jdk1.7.0_45/jre
Default locale: en_IE, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-13-generic", arch: "amd64", family: "unix"

1 个答案:

答案 0 :(得分:0)

NoClassDefFoundError意味着该类在编译时存在于类路径中,但在运行时的类路径中不存在。

通过eclipse清理项目,.class文件将再次重新生成。在Maven的帮助下再次运行maven项目