简体   繁体   English

Maven项目可以在Eclipse中运行,但不能从命令行运行

[英]Maven project works in eclipse but not from command line

I have a maven project which mainly has tests. 我有一个主要测试的Maven项目。 I created it using eclipse. 我使用eclipse创建了它。 I am able to update maven dependencies from eclipse and able to run all my tests. 我能够从Eclipse更新Maven依赖关系,并能够运行所有测试。 But, when I try to run those tests from command line using mvn clean install or mvn test . 但是,当我尝试使用mvn clean installmvn test从命令行运行那些mvn test It throws an error saying "package com.jayway.restassured does not exist". 它引发错误,指出“包com.jayway.restassured不存在”。

I am new to maven. 我是新手。 Any help would be appreciated. 任何帮助,将不胜感激。 The following are additional info about my environment. 以下是有关我的环境的其他信息。 Thanks. 谢谢。

Version info: 版本信息:

 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 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>

You are using the second dependency with scope test... change to compile 您正在将第二个依赖项与范围测试一起使用...进行编译

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven从Eclipse而不是命令行中看到依赖的项目jar - Maven sees dependent project jar from Eclipse but not from the command line Maven项目从eclipse正确运行但不是命令行 - Maven project running correctly from eclipse but not command line Maven 项目中的 JUnit 5 测试适用于 IntelliJ,但不适用于命令行 - JUnit 5 tests in Maven Project works in IntelliJ but Not from Command Line Maven项目在命令行中运行,但不在Eclipse中运行 - Maven project runs in command line but not in Eclipse eclipse / maven / sonatype war build在命令行工作但不在eclipse中工作 - eclipse/maven/sonatype war build works at the command line but not in eclipse eclipse-maven项目-NoClassDefFoundError从eclipse运行,但从命令行运行良好 - eclipse-maven project - NoClassDefFoundError running from eclipse but runs fine from command line 从命令行使用多个Eclipse项目进行Maven - Maven from command line with multiple eclipse projects 无法从Eclipse运行带有Maven的Java应用程序,但它可以在命令行中运行 - Can't run Java Application with Maven from Eclipse but it works in Command line 从命令行(Eclipse外)运行Java应用程序(Maven项目)时出错 - Errors when running Java Application (maven project) from command line (outside eclipse) 项目在Eclipse中运行,但不是从命令行运行:带有Maven和Dom4J的java.lang.NoClassDefFoundError - Project runs in Eclipse, but not from command line : java.lang.NoClassDefFoundError with Maven and Dom4J
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM