简体   繁体   中英

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing using Maven

I'm trying to run the junit webdriver example from sauce labs, but I get the following error when I run 'mvn test':

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

Here is the full 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>

The project was created by running:

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>

I've tried adding an exclusion for hamcrest and also tried using junit 4.11, but I keep getting java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

Output from mvn dependency: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] ------------------------------------------------------------------------

Any advice?

How about adding the dependency for hamcrest in your pom?

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

Also see this related SO question.

I've just added:

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

after

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

and it worked in my project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM