Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here is my /etc/paths:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

I added a file yuicompressor.jar to /usr/local/bin. Then I ran:

sudo java -jar yuicompressor.jar

but it says

Unable to access jarfile yuicompressor.jar

What am I doing wrong?

share|improve this question
1  
Java does not search the PATH for jars you specify. sh script.sh wouldn't work either if script.sh is on the PATH. –  Daniel Beck Sep 9 '13 at 17:36
    
Oh wow, now I feel dumb. –  Brandon Sep 9 '13 at 17:48

1 Answer 1

up vote 2 down vote accepted

PATH is used for executables only. It's what the shell (bash usually on MacOSX) uses for lookups for executables when you don't give an explicit path (such as /usr/bin/java or ./java).

Once you run java, now java is loaded, and it needs to figure out where things are. The shell is done. So, does java itself have any environment vars to check that might help? In general, you may try CLASSPATH. This gives a list of jars, to search for classes that may not be in the normal places java looks for.

But in this case, I don't think it could help, based on your syntax. You're telling it a specific path to a Jarfile. I'd just explicity path the jar out. Probably use a script to do this for you instead of typing this all out. I see something like:

#!/bin/bash

sudo java -jar /path/to/yuicompressor.jar

in your future.

share|improve this answer

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.