【问题标题】:How can I create independent TestNG Maven executable如何创建独立的 TestNG Maven 可执行文件
【发布时间】:2021-04-17 14:06:33
【问题描述】:

我需要使用 ma​​ventestng 创建一个 .jar 文件。 我的 jar 需要读取一个 testng.xml 文件并执行其中的所有测试。 我尝试了maven-shade-plugin 并创建了一个 jar,但是当我尝试执行它时出现错误:Could not find or load main class org.testng.TestNG。 我试图解决这个问题,找到了很多建议创建类路径的解决方案,但我担心这不是我需要的。我的 jar 文件将上传到服务器中,并且必须从那里执行,我无法在该服务器上创建类路径,我需要一个独立的文件。 如果他们能够执行此任务(war 文件、exe 文件等),我可以使用一些解决方法

我的测试在src/test/java 路径下。 我的 POM:

<repositories>
        <repository>
            <id>jcenter</id>
            <name>bintray</name>
            <url>https://jcenter.bintray.com</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>org.testng.TestNG</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

【问题讨论】:

  • 为什么不在构建过程中执行测试?为什么要通过 maven-shade-plugin 生成 jar 文件?
  • 我被要求只提供 jar 文件
  • 对不起,这没有意义...测试可以在构建期间运行...就是这样...
  • stackoverflow.com/a/64963846/5324105 这可能会有所帮助
  • 这不起作用:(

标签: java maven jar testng war


【解决方案1】:

很久以前我也有类似的要求。您需要创建一个包含所有依赖项的 jar。我已经写下了我遵循here 的过程。 HTH。

【讨论】:

  • [错误] 在可用目标程序集、附件、目录、目录中的插件 org.apache.maven.plugins:maven-assembly-plugin:2.5.3 中找不到目标“test-jar”- inline, directory-single, help, single, unpack -> [Help 1]
猜你喜欢
  • 1970-01-01
  • 2010-09-16
  • 1970-01-01
  • 2017-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
相关资源
最近更新 更多