Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

java - How can I create independent TestNG Maven executable

I need to create a .jar file using maven and testng. My jar needs to read a testng.xml file and execute all the tests that are in there. I tried maven-shade-plugin and created a jar, but when i try to execute it i have the error:Could not find or load main class org.testng.TestNG. I tried to solve this problem finding a lot of solutions suggesting to create classpath but i fear this is not what i need. My jar file will be uploaded in a server and it will have to be executed from there, i can't create a classpath on that server, i need an independent file. i can use some workarounds if thery are able to do this task (war file, exe file, etc...)

My tests are under the src/test/java path. My 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had a similar requirement long time back. You would need to create a jar with all dependencies. I had written up the process I followed here. HTH.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...