| Author |
Cannot run .jar file
|
Caglar Cataloglu
Greenhorn
Joined: Feb 06, 2010
Posts: 25
|
|
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?
|
Java Lover
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
C:\Program Files\Java\jdk1.6.0_21\bin> java -jar ../classes/app1.jar
|
[Jess in Action][AskingGoodQuestions]
|
 |
Caglar Cataloglu
Greenhorn
Joined: Feb 06, 2010
Posts: 25
|
|
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
Joined: Oct 13, 2005
Posts: 32833
|
|
|
Why are you putting your own work into the Java™ installation folders? Create your own folder, a bit like thisOpen command lineWrite "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
Joined: Feb 06, 2010
Posts: 25
|
|
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 lineWrite "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
Joined: Oct 25, 2008
Posts: 2700
|
|
|
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.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
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
Joined: Feb 06, 2010
Posts: 25
|
|
|
i put the directory where javac lives into the system path and everything is working well now, thanks a lot :>
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Well done
|
 |
 |
|
|
subject: Cannot run .jar file
|
|
|