Book Image

Apache Maven Cookbook

By : Raghuram Bharathan
Book Image

Apache Maven Cookbook

By: Raghuram Bharathan

Overview of this book

If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to learn how Apache Maven can be used for build automation. It is also meant for those familiar with Apache Maven, but want to understand the finer nuances of Maven and solve specific problems.
Table of Contents (13 chapters)
12
Index

Running a custom executable

There are many situations when you want Maven to run a specific executable on your computer. A simple use case would be to run the JAR that you created. Another case would be to have Maven run commands that are not provided as plugins (for instance, create a native Windows installer).

Maven provides support to run any executable system in a separate process along with Java programs in the same virtual machine on which Maven runs. The Maven Exec plugin provides this support using the exec goal (to run in a separate process) and the java goal (to run Java programs in the same process).

How to do it...

  1. Open a simple Maven project (simple-project).
  2. Run the command:
    mvn clean package exec:java –Dexec.mainClass="com.packt.cookbook.App"
    
  3. Observe the results:
    How to do it...

How it works...

We wanted to run the JAR file that we had created in the project. To do this, we called the java goal of the Maven Exec plugin. We provided the plugin with the required parameter (mainClass...