2014-07-01 61 views
3

我试图运行Junit从酱实验室webdriver的例子,但我得到以下错误,当我运行“命令mvn测试”:java.lang.NoClassDefFoundError:组织/ hamcrest /自描述使用Maven

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

这里是全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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<artifactId>sauce-project</artifactId> 
<groupId>com.sparkcentral</groupId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<name>sauce_quickstart</name> 
<description>A sample Maven project that demonstrates how to integrate Sauce OnDemand with WebDriver tests 
    that run using JUnit 
</description> 

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.saucelabs</groupId> 
     <artifactId>sauce_junit</artifactId> 
     <version>[1.0.0,)</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>LATEST</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <redirectTestOutputToFile>true</redirectTestOutputToFile> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<repositories> 
    <repository> 
     <id>saucelabs-repository</id> 
     <url>https://repository-saucelabs.forge.cloudbees.com/release</url> 
     <releases> 
      <enabled>true</enabled> 
     </releases> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </repository> 
</repositories> 

</project> 

该项目是由运行时创建:

mvn archetype:generate -DarchetypeRepository=http://repository-saucelabs.forge.cloudbees.com/release -DarchetypeGroupId=com.saucelabs -DarchetypeArtifactId=quickstart-webdriver-junit -DarchetypeVersion=1.0.7 -DsauceUserName=<USERNAME> -DsauceAccessKey=<KEY>

我试图增加对hamcrest排除和使用JUnit 4.11也尝试过,但我一直从MVN依赖性越来越java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

输出:树:

[INFO] Scanning for projects... 
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.sparkcentral:sauce-project:jar:1.0-SNAPSHOT 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 37, column 21 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 44, column 21 
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
[WARNING] 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building sauce_quickstart 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ sauce-project --- 
[INFO] com.sparkcentral:sauce-project:jar:1.0-SNAPSHOT 
[INFO] +- junit:junit:jar:4.10:test 
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.1:test 
[INFO] +- com.saucelabs:sauce_junit:jar:2.1.3:test 
[INFO] | +- com.saucelabs:sauce_java_common:jar:2.1.3:test 
[INFO] | \- com.saucelabs:saucerest:jar:1.0.9:test 
[INFO] |  +- com.googlecode.json-simple:json-simple:jar:1.1:test 
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.3.1:test 
[INFO] |  | +- org.apache.httpcomponents:httpcore:jar:4.3:test 
[INFO] |  | +- commons-logging:commons-logging:jar:1.1.3:test 
[INFO] |  | \- commons-codec:commons-codec:jar:1.6:test 
[INFO] |  \- org.json:json:jar:20090211:test 
[INFO] \- org.seleniumhq.selenium:selenium-java:jar:2.42.2:test 
[INFO] +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.42.2:test 
[INFO] | \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.42.2:test 
[INFO] |  +- cglib:cglib-nodep:jar:2.1_3:test 
[INFO] |  \- com.google.guava:guava:jar:15.0:test 
[INFO] +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.42.2:test 
[INFO] | \- net.sourceforge.htmlunit:htmlunit:jar:2.14:test 
[INFO] |  +- xalan:xalan:jar:2.7.1:test 
[INFO] |  | \- xalan:serializer:jar:2.7.1:test 
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:test 
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.2.1:test 
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.3.2:test 
[INFO] |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.14:test 
[INFO] |  +- xerces:xercesImpl:jar:2.11.0:test 
[INFO] |  | \- xml-apis:xml-apis:jar:1.4.01:test 
[INFO] |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.20:test 
[INFO] |  +- net.sourceforge.cssparser:cssparser:jar:0.9.13:test 
[INFO] |  | \- org.w3c.css:sac:jar:1.3:test 
[INFO] |  \- org.eclipse.jetty:jetty-websocket:jar:8.1.14.v20131031:test 
[INFO] |  +- org.eclipse.jetty:jetty-util:jar:8.1.14.v20131031:test 
[INFO] |  +- org.eclipse.jetty:jetty-io:jar:8.1.14.v20131031:test 
[INFO] |  \- org.eclipse.jetty:jetty-http:jar:8.1.14.v20131031:test 
[INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.42.2:test 
[INFO] | +- commons-io:commons-io:jar:2.4:test 
[INFO] | \- org.apache.commons:commons-exec:jar:1.1:test 
[INFO] +- org.seleniumhq.selenium:selenium-ie-driver:jar:2.42.2:test 
[INFO] | +- net.java.dev.jna:jna:jar:3.4.0:test 
[INFO] | \- net.java.dev.jna:platform:jar:3.4.0:test 
[INFO] +- org.seleniumhq.selenium:selenium-safari-driver:jar:2.42.2:test 
[INFO] +- org.seleniumhq.selenium:selenium-support:jar:2.42.2:test 
[INFO] | \- org.seleniumhq.selenium:selenium-api:jar:2.42.2:test 
[INFO] \- org.webbitserver:webbit:jar:0.4.14:test 
[INFO]  \- io.netty:netty:jar:3.5.2.Final:test 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.328 s 
[INFO] Finished at: 2014-07-01T10:46:54-07:00 
[INFO] Final Memory: 9M/81M 
[INFO] ------------------------------------------------------------------------ 

有什么建议?

+0

由于错误是抱怨缺少hamcrest类,您是否试过简单地将hamcrest导入您的项目? – blgt

+0

您能否提供一个我们可以用来重现此问题的最小示例测试课程? –

+0

其他的一定是错的。我尝试了与你完全相同的东西,并且我得到了Hamcrest作为JUnit的依赖...正如预期的那样! – SiKing

回答

3

如何在你的pom中添加对hamcrest的依赖?

<dependency> 
    <groupId>org.hamcrest</groupId> 
    <artifactId>hamcrest-all</artifactId> 
    <version>1.3</version> 
</dependency> 

另请参阅this related SO问题。

+0

添加依赖不适合我。 – user3047479

0

我刚说:

<dependency> 
    <groupId>org.hamcrest</groupId> 
    <artifactId>hamcrest-library</artifactId> 
</dependency> 

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.10</version> 
    <scope>test</scope> 
</dependency> 

,它在我的项目工作。

相关问题