Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

locating jar file in $PATH environment variable for java -jar command

Tags:

java

I want to run a simple executable jar like this:

java -jar /path/to/my/jar/myjar.jar

However, i have to put that absolute path every time I want to run it. Is there a way to tell the OS to look for the jar in $PATH environment variable?

like image 486
Sean Nguyen Avatar asked Mar 15 '26 10:03

Sean Nguyen


2 Answers

You can also copy your jar file to /usr/bin folder, then it will work with just $ myjar.jar

Make sure your jar file has the executable bit (chmod +x myjar.jar) and copy it to /usr/bin (sudo cp myjar.jar /usr/bin/myjar.jar)

like image 193
Nejc Saje Avatar answered Mar 16 '26 23:03

Nejc Saje


I think you'd use the classpath; append your directory to it and java -jar myjar.jar should work.

like image 35
Robert Avatar answered Mar 16 '26 22:03

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!