Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Can't find executable Jar file

 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am trying to create a batch script that puts an executable jar file in the classpath so that I can execute the jar from any directory. If I start the application from the directory the jar file is in, like this: java -jar Program.jar, it starts fine, but if I am in a different directory, I get "java.util.zip.ZipException The system cannot find the file specified." I also tried putting it in the system classpath, but that also does not work. I have never had this problem before with other jar files that were NOT self executing (in other words, the main class not defined in MANIFEST.MF) So, I was wondering if it had something to do with the fact that this one I am trying to run is self executing. Has anyone else ever experienced this? Thanks for your help!

Barry
 
Sheriff
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry, I believe your problem may be that in a command line like:
java -jar whatever.jar
the value to the -jar option is not searched for in the classpath.
If your main() routine resides in a class with a unique package signature (it should), you might have better luck with:
java your.package.name.Main
in which the named class will be searched for in the classpath. Of course, you lose all the benefits of using a manifest file in the jar with this approach.
I don't know of any means to specify a search path for values on the -jar option. Too bad, that'd be very convenient. Perhaps that's why so many java programs are started via shell scripts.
hth,
bear
 
Create symphonies in seed and soil. For this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic