我试图从酱汁实验室运行junit webdriver示例,但是当我运行' mvn test'时出现以下错误:
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,但我不断获得java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
mvn依赖的输出:tree:
[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 :(得分:3)
如何在你的pom中添加hamcrest的依赖?
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
另见this related SO问题。
答案 1 :(得分: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>
它在我的项目中有效。