mvn测试导致NoClassDefFoundError虽然它在类路径中

时间:2014-06-17 09:12:42

标签: java maven jar jena xerces

首先对该项目进行一些解释。我正在构建https://github.com/paulhoule/infovore/tree/v1.1.1并遇到maven问题。然而,这只发生在Debian 3.2.57机器上,而它适用于Ubuntu 13.04机器。这就是为什么我没有提出相关项目的问题,而是想知道如何调试它。

由于mvn test相同,ClassDefNotFoundError上的多项测试失败。来自万无一失的报道摘录:

 <error message="org/apache/xerces/xs/XSTypeDefinition" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: org/apache/xerces/xs/XSTypeDefinition
    at com.ontology2.millipede.triples.PartitionOnSubjectTTest.testBin(PartitionOnSubjectTTest.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

java.lang.NoClassDefFoundError: org/apache/xerces/xs/XSTypeDefinition
    at com.hp.hpl.jena.n3.turtle.ParserBase.<init>(ParserBase.java:25)
    at com.ontology2.rdf.parser.NodeParser.<init>(NodeParser.java:337)

但是相应的jar在类路径中,mvn test -X显示:

[DEBUG] test classpath classpath:
[DEBUG]   /home/semmul2/tools/infovore-1.1/millipede/target/test-classes
[DEBUG]   /home/semmul2/tools/infovore-1.1/millipede/target/classes
[DEBUG]   /home/semmul2/.m2/repository/junit/junit/4.11/junit-4.11.jar
[DEBUG]   /home/semmul2/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[DEBUG]   /home/semmul2/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar
[DEBUG]   /home/semmul2/.m2/repository/org/springframework/spring-context/3.2.1.RELEASE/spring-context-3.2.1.RELEASE.jar
[DEBUG]   /home/semmul2/.m2/repository/org/springframework/spring-beans/3.2.1.RELEASE/spring-beans-3.2.1.RELEASE.jar
[DEBUG]   /home/semmul2/.m2/repository/org/springframework/spring-aop/3.2.1.RELEASE/spring-aop-3.2.1.RELEASE.jar
[DEBUG]   /home/semmul2/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[DEBUG]   /home/semmul2/.m2/repository/org/springframework/spring-expression/3.2.1.RELEASE/spring-expression-3.2.1.RELEASE.jar
[DEBUG]   /home/semmul2/.m2/repository/org/springframework/spring-core/3.2.1.RELEASE/spring-core-3.2.1.RELEASE.jar
[DEBUG]   /home/semmul2/.m2/repository/org/apache/jena/jena-arq/2.9.3/jena-arq-2.9.3.jar
[DEBUG]   /home/semmul2/.m2/repository/org/apache/jena/jena-core/2.7.3/jena-core-2.7.3.jar
[DEBUG]   /home/semmul2/.m2/repository/org/apache/jena/jena-iri/0.9.3/jena-iri-0.9.3.jar
--> [DEBUG]   /home/semmul2/.m2/repository/xerces/xercesImpl/2.10.0/xercesImpl-2.10.0.jar**
[DEBUG]   /home/semmul2/.m2/repository/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar
[DEBUG]   /home/semmul2/.m2/repository/commons-codec/commons-codec/1.5/commons-codec-1.5.jar
[DEBUG]   /home/semmul2/.m2/repository/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2.jar
[DEBUG]   /home/semmul2/.m2/repository/org/apache/httpcomponents/httpcore/4.1.3/httpcore-4.1.3.jar
[DEBUG]   /home/semmul2/.m2/repository/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4.jar
[DEBUG]   /home/semmul2/.m2/repository/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar
[DEBUG]   /home/semmul2/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
[DEBUG]   /home/semmul2/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar

在相应的jar中看一下这个类确实在那里:

jar tf  /home/semmul2/.m2/repository/xerces/xercesImpl/2.10.0/xercesImpl-2.10.0.jar | grep XSTypeDefinition
>> org/apache/xerces/xs/XSTypeDefinition.

相应的pom.xml如下所示:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>infovore</artifactId>
    <groupId>com.ontology2</groupId>
    <version>1.1-SNAPSHOT</version>
  </parent>

  <groupId>com.ontology2</groupId>
  <artifactId>millipede</artifactId>
  <version>1.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>millipede</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>14.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jena</groupId>
      <artifactId>jena-arq</artifactId>
      <version>2.9.3</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
  </dependencies>
</project>

在Rob Hall提出建议之后,我也尝试将其中一个失败的测试放入jar并执行测试代码作为主要功能。这是结果:

java -cp millipede-1.1-SNAPSHOT.jar com.ontology2.rdf.parser.NodeParserTest
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/xs/XSTypeDefinition
        at com.hp.hpl.jena.n3.turtle.ParserBase.<init>(ParserBase.java:25)
        at com.ontology2.rdf.parser.NodeParser.<init>(NodeParser.java:337)
        at com.ontology2.rdf.parser.NodeParserTest.main(NodeParserTest.java:18)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.xs.XSTypeDefinition
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 3 more

我已经尝试过了:

  • 删除完整的本地存储库以避免与其他项目发生冲突

  • 明确添加xerces依赖

  • 将maven和java版本以及环境变量与工作机器进行比较

非常感谢任何其他想法! :)

0 个答案:

没有答案