Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?
Thanks.

share|improve this question

2 Answers 2

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: thegreenoak.blogspot.com/2009/07/… –  djangofan Jan 3 '12 at 19:41

From http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html:

-jar
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

 
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.