1

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?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Jan 9, 2014 at 6:34

1 Answer 1

2

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>
answered Jan 9, 2014 at 15:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.