简体   繁体   English

如何从命令提示符下运行Maven项目testng.xml

[英]how to run maven project testng.xml from the command prompt

I am using linux mechine(ubuntu 14). 我正在使用linux机械(ubuntu 14)。 my project is maven project with testng frame work. 我的项目是具有testng框架工作的Maven项目。 here i am trying to run the testng.xml from the command prompt so that i can configure in jenkins. 在这里,我试图从命令提示符下运行testng.xml,以便可以在jenkins中进行配置。

project location : /home/subhash/workspace/myproject
class path is  : /home/subhash/workspace/myproject/bin
testng jar locattion is: /home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar"

suite location is : /home/subhash/workspace/suites/src/test/resources/testng.xml

hence i executed the following command from command prompt from the location.
/home/subhash/workspace/myproject/bin$ 

$ java -cp ".:../lib/*:/home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar" org.testng.TestNG /home/subhash/workspace/suites/src/test/resources/testng.xml

i got the following Exception: 我得到以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException

hence i have added the dependency in pom.xml as follows. 因此,我在pom.xml中添加了依赖项,如下所示。

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>

build it. 建立它。 it was successful. 成功了。 again i have run the above mentioned command to run the testng.xml but still same exception is displayed. 再次,我已经运行上述命令来运行testng.xml,但仍然显示相同的异常。

Please help me in this issue. 请帮我解决这个问题。

Thanks in advance. 提前致谢。 Subhash. 苏巴。

Take a look at this question: Suddenly can't run TestNG tests from ant ([testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException) 看一下这个问题: 突然无法从蚂蚁运行TestNG测试([testng]原因:java.lang.ClassNotFoundException:com.beust.jcommander.ParameterException)

It seems to be the same problem 好像是同样的问题

Hope helps! 希望有帮助!

UPDATE UPDATE

Try to add to the cp java argument the 'beust' jar path in m2. 尝试将m2中的“ beust” jar路径添加到cp java参数。

It would be easier running the tests using mvn test instead of the testng jar. 使用mvn test代替testng jar运行测试会更容易。 Setup the mvn surefire plugin in pom and run using mvn test -DsuiteXmlFile=src/test/resources/yourxml.xml 在pom中设置mvn surefire插件,并使用mvn test -DsuiteXmlFile = src / test / resources / yourxml.xml运行

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM