We can set the default main class in the META-INF/MANIFEST.MF. This could be configured in the maven-jar-plugin in pom.xml. Let’s use the previous example.
1. Edit the pom.xml as follow.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>info.ykyuen.eureka</groupId> <artifactId>testng-example</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>testng-example</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>info.ykyuen.eureka.Addition</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>
2. So instead of specify the main class after the build…
- java -cp .\target\testng-example-1.0.jar info.ykyuen.eureka.Addition 12 32
3. We can now just simply run the jar file.
- java -jar .\target\testng-example-1.0.jar 12 32
Done =)
Reference: How do I specify a main class in the manifest of my generated jar file?