Maven编译错误[软件包org.testng.annotations不存在] [英] Maven Compilation error [package org.testng.annotations does not exist]
本文介绍了Maven编译错误[软件包org.testng.annotations不存在]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Maven还是很陌生,我想使用maven运行测试类.我已经生成了testng.xml,并且还创建了POM.xml文件.但是,当您运行mvn install
时,它将生成此错误:
I'm pretty new to maven and I want to run my test classes using maven. I have generated the testng.xml and I have created the POM.xml file also. But when you run the mvn install
, it generates this error :
[软件包org.testng.annotations不存在]
[package org.testng.annotations does not exist]
请对此提供建议.
pom.xml
<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>com.TestNG</groupId>
<artifactId>TestNG</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="1" preserve-order="true">
<test name="Test">
<packages>
<package name="com.testngTest2" />
<package name="com.testngTest" />
</packages>
</test> <!-- Test -->
</suite> <!-- Suite -->
推荐答案
我遇到了类似的问题.原因是需要编译"时将"testng"依赖项的范围"选项设置为测试".
I've got similar problem. The reason for that was "Scope" option of "testng" dependency set to "test" when "compile" was needed.
我如何修复它(注意,我使用了Eclipse):
How I fixed it (note, I used Eclipse):
- 打开 pom.xml 文件.
- 转到"依赖项"标签.
- 选择"测试"程序包,然后单击"属性... "
- 在打开的屏幕上,将"范围"选项更改为"编译",然后单击确定"进行保存.
- 尝试通过编译测试"目标再次构建您的项目.
- Open pom.xml file.
- Go to "Dependencies" tab.
- Select "testng" package and click on "Properties..."
- On opened screen change "Scope" option to "compile" and click "OK" to save it.
- Try to build your project again with "compile test" goals.
这篇关于Maven编译错误[软件包org.testng.annotations不存在]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文