Maven测试,构建失败,java.lang.NoClassDefFoundError

时间:2014-02-18 22:34:41

标签: java eclipse maven

我正在Eclipse上的Maven项目中运行mvn测试。 JUnit测试通过,但我得到一个堆栈跟踪错误,如下所示。它与我认为的javax.peristence.Persistence类有关。我做了一些研究,我想我需要将javax库添加到类路径中(获得一些关于如何做到这一点的建议会很棒。我已将此依赖项放在pom.xml中,但仍然得到错误。我认为在pom.xml中明确列出它可以解决我的问题。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>ejb3-persistence</artifactId>
        <version>1.0.2.GA</version>
        <type>pom</type>
    </dependency>

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.399 sec <<< FAILURE! -   

 in tableTests.TestBaseDataConfig

 testCreateDeleteRow(tableTests.TestBaseDataConfig)  Time elapsed: 0.087 sec  <<< ERROR!

 java.lang.NoClassDefFoundError: javax/persistence/Persistence
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at persistence.PersistenceUtil.<clinit>(PersistenceUtil.java:12)
at config.AbstractTableConfig.createRow(AbstractTableConfig.java:11)
at tableTests.TestBaseDataConfig.testCreateDeleteRow(TestBaseDataConfig.java:51)

1 个答案:

答案 0 :(得分:1)

您只是声明对ejb3-hibernate pom 的依赖,而不是实际的jar工件。尝试删除<type>pom</type>