I am coding a Java program on my development machine. Maven packages this a myjar.jar
, and I can run it from the command line using java -cp myjar.jar my.FantasticClass
. It uses library somelib.jar
. I use Maven, and the project is hosted on github.
When I want to run my project on the target machine, what is the best way to go?
I could package my code as a jar, grab the somelib.jar
and move it to the target machine manually, but I suppose I could also check out the Maven project from github on the target machine, run it, and have Maven both generate the jar and get the somelib.jar
file.
Or am I simply overlooking something?
1 Answer 1
I found this solution on StackOverflow - use maven-assembly-plugin, and invoke
mvn clean compile assembly:single
Then I can just run the jar like this:
java -jar MyJar.jar
Here are the required additions to the POM file. My main class is demo.GraphTest
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>demo.GraphTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>