Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Unix newbie here. 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"

Any help is appreciated.

Cheers.

share|improve this question
    
Have you checked if it's not a permissions issue? –  matcheek Jun 21 '12 at 11:11
    
You'll have to excuse my ignorance, but how could I check this? –  Davy Kavanagh Jun 21 '12 at 11:20
    
You may want to check this answer:stackoverflow.com/questions/5569591/… –  matcheek Jun 21 '12 at 11:46

2 Answers 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
share|improve this answer
    
No, sorry, the tools are the jar files themselves –  Davy Kavanagh Jun 21 '12 at 11:45

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.

share|improve this answer
    
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. –  Davy Kavanagh Jun 21 '12 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 Jun 21 '12 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. –  Davy Kavanagh Jun 21 '12 at 12:26
    
@DavyKavanagh Note: do not add the environment variable to .bashrc, add it to .profile. See Alternative to .bashrc –  Gilles Jun 21 '12 at 22:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.