gpt4 book ai didi

java - Maven 项目在 eclipse 中工作,但不能在命令行中工作

转载 作者:行者123 更新时间:2023-12-05 06:45:49 25 4
gpt4 key购买 nike

我有一个主要有测试的maven项目。我使用 Eclipse 创建它。我能够从 eclipse 更新 Maven 依赖项并能够运行我的所有测试。但是,当我尝试使用 mvn clean installmvn test 从命令行运行这些测试时。 它会抛出一条错误消息“package com.jayway.restassured does not exist”。

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

最佳答案

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

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

关于java - Maven 项目在 eclipse 中工作,但不能在命令行中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21079307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com