testNG Maven problem
I am trying to run a build file using Ant. I am using Maven for dependencies. I am having a testNG dependency in my project.
This is the pom.xml file
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.anova.abis</groupId>
<artifactId>maven-pom</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>My first Maven POM</name>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</project>
The maven downloads the testNG from mavenrepository, but I am getting an error, it is complaining that it can not find org.testng.Assert and org.testng.annotations.Test. (as below)
Compiling 10 source files to /home/shahin/Files/Development/Ant/ServiceEJBSample3/bin
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test.java:5: package org.testng does not exist
[javac] import org.testng.Assert;
[javac] ^
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test.java:6: package org.testng.annotations does not exist
[javac] import org.testng.annotations.Test;
[javac] ^
[javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/ejbModule/net/company/test/Service1Test2.java:5: package org.testng does not exist
[javac] import org.testng.Assert;
[javac] ^
If I don't use maven and simply use ant and specify the location where the testNG.jar file is, there is no problem at all. I have used the same .jar file that maven downloaded for Ant to make sure I am using the same source. I also have tried different versions of testNG from maevnrepo. Any insights ?
Do I need to include all dependencies (all different packages? like org.t开发者_运维技巧estng.Assert and org.testng.annotationsTest and as such) in the POM file? or just the one is enough? If I need to have all of them listed in POM file, what is the best and fastet way of doing it?
Works for me. Did you do a mvn clean first? Maybe the dependency isn't getting downloaded.
Your pom.xml looks correct, maybe your repository got corrupt somehow, I suggest rm -rf ~/.m2
or if you don't want to download the entire Internet, start by just removing the TestNG dependencies only.
I have cleaned the maven and revised the build.xml file once again, it works now. Probably it was something wrong in the repository. Thanks all for your input.
精彩评论