如何使用maven在testng中创建可执行jar
有人能帮我如何为testng maven项目制作可执行jar吗。我的目标是使用bat文件运行testng可执行jar来运行单元测试 下面是我的文件夹结构如何使用maven在testng中创建可执行jar,maven,testng,maven-plugin,executable-jar,maven-assembly-plugin,Maven,Testng,Maven Plugin,Executable Jar,Maven Assembly Plugin,有人能帮我如何为testng maven项目制作可执行jar吗。我的目标是使用bat文件运行testng可执行jar来运行单元测试 下面是我的文件夹结构 如果您能帮助我,我将不胜感激。您应该使用maven插件运行testNG with mvn测试 <build> <!-- Source directory configuration --> <sourceDirectory>src</sourceDirectory>
如果您能帮助我,我将不胜感激。您应该使用maven插件运行testNG with mvn测试
<build>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
<suiteXmlFile>suites-test-testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
src
org.apache.maven.plugins
maven surefire插件
2.14.1
testng.xml
suites-test-testng.xml
如果你真的想要一个可执行的jar(我想你不需要),你需要shade插件:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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.greg</groupId>
<artifactId>tester</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>tester</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.greg.Application</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.greg
测试员
1.0-快照
罐子
测试员
UTF-8
....
org.apache.maven.plugins
maven阴影插件
3.0.0
包裹
阴凉处
com.greg.Application
有一种简单的方法,您可以通过右键单击eclipse follow来创建可执行jar-
并创建一个java类,该类将调用testNG xml文件并使用testNG.run()执行
公共类InvokeTestNGJava{
/**
* @param args
*/
public static void main(String[] args) throws Exception {
System.out.println("Started!");
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("src"+File.separator+"main"+File.separator+"resources"+File.separator+"stats-comparison.xml");
testng.setTestSuites(suites);
testng.run();
}
/**
*@param args
*/
公共静态void main(字符串[]args)引发异常{
System.out.println(“开始!”);
TestNG TestNG=新的TestNG();
List suites=Lists.newArrayList();
add(“src”+File.separator+“main”+File.separator+“resources”+File.separator+“stats comparison.xml”);
testng.setTestSuites(套房);
testng.run();
}
}
java类将使用-java-classpath yourjar.jar youpackage.InvokeTestNGJava运行。它可以简单地调用testng xml并运行它。Hi Essex,我按照您的方式处理了错误“错误:无法找到或加载主类”。我们还在main方法中使用testng.xml。当testng.xml出现在应用程序外部时,我们如何提供引用?也让我知道使用什么目标。