Calling java main method during maven package

I have a main class that scans the classpath and generates some files. I want maven to call this main method during the maven package and put the generated files in the target directory. How to do it?

+4
source share
1 answer

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

+4
source

All Articles