Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run a jar that is located at /Library/Java/jack.jar, this works:

java -jar /Library/Java/jack.jar

However, I want to run it without the path, relying on the class path. The default class path includes /Library/Java, but this fails with "Unable to access jarfile":

java -jar jack.jar

Why? What's more, this also fails (same error):

java -cp /Library/Java -jar jack.jar

What's the problem/what am I doing wrong?

share|improve this question
up vote 2 down vote accepted

The jar file can not be executed this way. You need to provide the full path of the jar file. the class path -cp classpath specifies a list of directories, JAR archives, and ZIP archives to search for class files needed to run your java program. However, the jar file to be executed should be accessed using full path. After the jar file is run, the classpath can be used to locate more classes and libraries.

By the way, this is not the right site to ask such a question.

share|improve this answer
Ahhhh OK. So there's no way Java can be configured to search a default environment defined directory for JARs to execute using the "java -jar ..." command? The jarfile argument always has to be explicit? – Jack Sleight Dec 21 '11 at 15:23
RE the right site: Sorry, I wasn't sure, thought this counted as server configuration. – Jack Sleight Dec 21 '11 at 15:30
@JackSleight: AFAIK, yes the jar file path should be set explicitly. – Khaled Dec 21 '11 at 15:32
OK great, thanks! – Jack Sleight Dec 21 '11 at 15:38
Yes, this problem got me once also, trying to run java from a powershell script:… – djangofan Jan 3 '12 at 19:41


When you use this option, the JAR file is the source 
of all user classes, and other user class path settings
are ignored.
share|improve this answer

Your Answer


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.