10

I have java tools that I need to use. The tools are in a folder full of jar files. I wanted to add this folder to my path, for the obvious reasons, but after I edit my .bash_profile to include the new folder in the $PATH variable, and source it, it doesn't work. I also tried logging out, and logging back in, and that didn't work either. I just keep getting the error message "Unable to access jarfile .jar"

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

5

For JAR files, you have to set the CLASSPATH and not the PATH environment variable.

If you're using BASH, it is: export CLASSPATH="$CLASSPATH:<full_path_to_each_jar_files>"

You better add it in the file .bashrc unless you know what you are doing.

Example:

export CLASSPATH="$CLASSPATH:$HOME/java/lib/foebar.jar:$HOME/extra/lib/another.jar"

But of course, if you are still invoking the jar file with the Main class you have to use the full path for it:

java -jar $HOME/java/lib/main-prog.jar

However, you can set its execution right and run it:

chmod u+x $HOME/java/lib/main-prog.jar
export PATH=$PATH:$HOME/java/lib
main-prog.jar

But you have to take care that your classpath is correct and list all required jar.

Huygens
  • 9,345
2

If your tools are scripts, which contain commands like

 java -jar somejafile.jar

then you should edit them to contain the correct path

 java -jar /full/path/to/somefile.jar