Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank, I am quite clear now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic