• 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

Cannot run .jar file

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dear Java lovers,

I have followed steps on Head First Java book to create jar file, everything worked well.
Now i need to read/open that jar file to run the classes.

I have a classes file on top of bin folder.

When i run this code, it cant find jar file.
C:\Program Files\Java\jdk1.6.0_21\bin> java -jar -classpath ../classes app1.jar
Unable to access jarfile app1.jar

So how can i read app1.jar from another folder?
 
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
C:\Program Files\Java\jdk1.6.0_21\bin> java -jar ../classes/app1.jar
 
Caglar Cataloglu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:C:\Program Files\Java\jdk1.6.0_21\bin> java -jar ../classes/app1.jar



that works, thanks, you saved my day

i thinks there is no way like using -classpath
 
Marshal
Posts: 79969
396
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you putting your own work into the Java™ installation folders? Create your own folder, a bit like this
  • Open command line
  • Write "mkdir java" (or similar)
  • Write "cd java"
  • . . . and you can gain access to your Java™ work simply by using the "cd" instruction next time.
     
    Caglar Cataloglu
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:Why are you putting your own work into the Java™ installation folders? Create your own folder, a bit like this

  • Open command line
  • Write "mkdir java" (or similar)
  • Write "cd java"
  • . . . and you can gain access to your Java™ work simply by using the "cd" instruction next time.


    Hi Campbell;
    actually i have tried to create a new folder under C:/ directory, but i am not able to compile .java when i use this command:
    C:\>javac MyApp.java
    'javac' is not recognized as an internal or external command, operable or batch file.


    so my temporary solution is to go to javac directory and then use javac ...

    is there any other way of using javac?

     
    Bartender
    Posts: 2700
    IntelliJ IDE Opera
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In that case you have to add the path to java bin (e.g. C:\Program Files\Java\jdk_xxx\bin) to your PATH environment variable. Remember to restart cmd after that.
     
    Campbell Ritchie
    Marshal
    Posts: 79969
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Look at the Java™ Tutorials section about getting started and the "common problems" link. The first error it describes is exactly what you are suffering. You need to set a system PATH, and the Windows® installation link (§4) tells you how to do that. Forget about "optional"; just set a PATH
    Don't set a system CLASSPATH at this stage.
     
    Caglar Cataloglu
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    i put the directory where javac lives into the system path and everything is working well now, thanks a lot :>
     
    Campbell Ritchie
    Marshal
    Posts: 79969
    396
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well done
     
    Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
    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