File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes why can't I execute .jar file this way. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "why can Watch "why can New topic

why can't I execute .jar file this way.

Yuan Ye
Ranch Hand

Joined: Mar 05, 2003
Posts: 172
I have made an executable .jar file, stored in a directory of classpath.
I think I can execute this .jar file anywhere by just calling java -jar a.jar, since it is in the classpath of my system. However this is not true, I get ZipException: system can't find the file. If I first go to the directory, then run java -jar a.jar, everything is fine. Does that mean I can't depend on the system classpath to load an .jar file? Please help. Thanks in advance. (I am using Java2 1.4).
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
If you read the note in the Tools Documentation for the -jar switch, it states "When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored." The jar must be in the same directory you issue the command. Plus some other requirements, I suggest you read up on it. You could also check out the tutorialRunning JAR-Packaged Software
[ August 28, 2003: Message edited by: Carl Trusiak ]

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Note that the jar file doesn't have to be in the current directory; you can specify a path to it. But Carl's point that the CLASSPATH is irrelevant is correct.

[Jess in Action][AskingGoodQuestions]
Yuan Ye
Ranch Hand

Joined: Mar 05, 2003
Posts: 172
Thank, I am quite clear now.
I agree. Here's the link:
subject: why can't I execute .jar file this way.
jQuery in Action, 3rd edition