• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot run .jar file

 
Caglar Cataloglu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
    • 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?

     
    Wouter Oet
    Saloon Keeper
    Posts: 2700
    IntelliJ IDE Opera
    • Likes 1
    • Mark post as helpful
    • send pies
    • 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
    Sheriff
    Posts: 48381
    56
    • Mark post as helpful
    • send pies
    • 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
    • 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
    Sheriff
    Posts: 48381
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic