You can configure pom.xml to run some method while executing the package phase, like this, -
<build> <plugins> <plugin> <groupId>some.group.id</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>some.package.where.your.main.Class</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build>
After setting up pom.xml, you can run the following command -
mvn package
Now the package phase of the maven life cycle will execute the main() method from the class mentioned in <mainClass> </mainClass> .
See other ways: 3 ways to start Java main from Maven
Razib source share