Maven exec plugin allows us to execute system and Java programs from the maven command.
There are two goals of the maven exec plugin:
In this tutorial, we will learn how to use exec:java to run a Java program from our maven project.
If you want to use any maven plugin, you need to configure it in the pom.xml build section. Just add the below plugin configuration to your project pom.xml file.
The most important point to note here is the “mainClass” element inside the “configuration”. This is where we specify the Java class that will be executed by the exec:java goal.
Here is the content of the Java class. It’s a simple class where we are printing Java version details and the current time.
Here is the output when we run the maven build with the exec:java goal.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Thank you Pankaj for the Maven tutorial, one of the best tutorial I came across in internet.
- Durga Prasad Patro