Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running jar, setting classpath

I've got a project I've made with Maven. I compile a JAR, with "mvn package", and now I want to run it, preferably without setting some insane classpath, as it depends on Spring and half the internet or something. Is there any way I can run it easily? Something like "mvn run" would be great, or an option to throw in all dependencies into the jar so I can do "java -jar" would also be splendid.

How do you deal with this, and what do you recommend doing? Because exporting a CLASSPATH based on ~/.m2 would probably just be hurtful ;-)

like image 890
niklassaers Avatar asked Nov 30 '22 19:11

niklassaers


1 Answers

Setting CLASSPATH and calling java -jar myjar.jar wouldn't work anyway. Because the java -jar command ignores the CLASSPATH environment variable as well as the -cp flag.

In this case you had to add the classpath entries to the jar's MANIFEST at the Class-Path key, like:

 Class-Path: jar1-name jar2-name directory-name/jar3-name
like image 83
Andreas Dolk Avatar answered Dec 04 '22 11:12

Andreas Dolk