• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank, I am quite clear now.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic