Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...