Maven项目在eclipse中工作,但不是从命令行工作

时间:2014-01-12 19:35:11

标签: java maven selenium rest-assured

我有一个主要有测试的maven项目。我用eclipse创建了它。我能够从eclipse更新maven依赖项并能够运行我的所有测试。但是,当我尝试使用mvn clean installmvn test从命令行运行这些测试时。 它抛出一个错误,说“包com.jayway.restassured不存在”。

我是maven的新手。任何帮助,将不胜感激。以下是有关我的环境的其他信息。感谢。

版本信息:

 Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
 Maven home: /usr/share/maven
 Java version: 1.6.0_65
 ...
 OS name: "mac os x", version: "10.8.3", arch: "x86_64", family: "mac"

的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>
<groupId>*******</groupId>
<artifactId>*********</artifactId>
<version>1.0</version>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.37.1</version>
    </dependency>

    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>1.8.1</version>
        <exclusions>
            <!-- Exclude Groovy because of classpath issue -->
            <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy</artifactId>
            </exclusion>
        </exclusions>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <!-- Needs to be the same version that REST Assured depends on -->
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>json-path</artifactId>
        <version>1.8.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>xml-path</artifactId>
        <version>1.8.1</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
    </dependency>


    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
 </project>

1 个答案:

答案 0 :(得分:0)

您正在使用范围测试的第二个依赖项...更改为编译

<dependency>
    <groupId>com.jayway.restassured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>1.8.1</version>
    <exclusions>
        <!-- Exclude Groovy because of classpath issue -->
        <exclusion>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
        </exclusion>
    </exclusions>
    <scope>compile</scope>
</dependency>