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"


2 Answers 2


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.


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

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

  • I tried export CLASSPATH=$CLASSPATH:<my_new_path>, with the <my_new_path> replaced with the actual path of the folder, sourced and still the same result. Commented Jun 21, 2012 at 11:46
  • Sorry my mistake, it's not the path but the .jar file with full path you put, I'll update the answer
    – Huygens
    Commented Jun 21, 2012 at 12:11
  • Does this mean I will have to add to the CLASSPATH, a new entry for every jar file. There are about 80 of these jar files. Commented Jun 21, 2012 at 12:26
  • @DavyKavanagh Note: do not add the environment variable to .bashrc, add it to .profile. See Alternative to .bashrc Commented Jun 21, 2012 at 22:44
  • @DavyKavanagh sorry for the long delay in the response. But yes, this would mean adding the 80 jar files to the classpath.
    – Huygens
    Commented Feb 28, 2015 at 20:16

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
  • No, sorry, the tools are the jar files themselves Commented Jun 21, 2012 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .