Tuesday, April 21, 2015

Maven: executing JAR created with Maven

In this tutorial we will learn how to create an executable jar with Maven and run it from command line.


Let's add a maven-jar-plugin to your pom, make sure you specify your main class as such:

<mainClass>exec.MyApp</mainClass>





Run Maven:

uki@ JavaFxSceneSwitch $ mvn clean install[INFO] Scanning for projects...[INFO]                                                                         [INFO] ------------------------------------------------------------------------[INFO] Building JavaFxSceneSwitch 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------...[INFO] Installing .. to /Users/uki/.m2/repository/edu/clcillinois/cit137/JavaFxSceneSwitch/1.0-SNAPSHOT/JavaFxSceneSwitch-1.0-SNAPSHOT.jar[INFO] Installing ...[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.822 s[INFO] Finished at: 2015-04-21T14:57:43-05:00[INFO] Final Memory: 15M/91M[INFO] ------------------------------------------------------------------------



Run the app from the ROOT of your project:


uki@ UKI_LUCAS $ java -jar  /Users/uki/.m2/repository/edu/clcillinois/cit137/JavaFxSceneSwitch/1.0-SNAPSHOT/JavaFxSceneSwitch-1.0-SNAPSHOT.jar



The JavaFX app should start, if you start it from other folder, observe how the Image path behaves.