wood burning stoves*
The moose likes Beginning Java and the fly likes Run jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run jar file" Watch "Run jar file" New topic

Run jar file

P Igor

Joined: Nov 20, 2006
Posts: 20

I am trying to run a jar file using the command prompt but get 'Unable to access jarfile' error.

I want to run the jar file from c:\, where as my jar file is in c:\apps\jar folder. I have classpath pointing to c:\apps\jar\myapp.jar but still get this error.

set classpath=c:\apps\jar\myapp.jar;%classpath%
java -jar myapp.jar

It works if I run the command file from the same location where the jar file resides but not from other folder. The reason I do not want to test in same folder is because I will be scheduling this command file to run the java program using a scheduler.

Any thoughts??

amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Did you try


Setting classpath will not do because classpath is meant to search the classes which are required to run the application.


P Igor

Joined: Nov 20, 2006
Posts: 20
Absolute path work but are you saying that there is no way to give relative path (or any other path setting) & run the jar file? That's bad
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

Sure you can: java -jar apps\jar\myapp.jar works just as well.

You just cannot use PATH or CLASSPATH when running JAR files.

How To Ask Questions How To Answer Questions
P Igor

Joined: Nov 20, 2006
Posts: 20
It works. Thank You.

Another problem is the path of any folder used inside the java program. I have log folder under c:\apps\jar & again I use relative path to access it in the java program. If I run the cmd file from c:\apps\jar folder, the java code works fine but if I run it from c:\, it doesnt work because I think it looks for log folder under c:\ rather than under c:\apps\jar.

It is sorta covered in the JavaRanch Style Guide.
subject: Run jar file
Similar Threads
ERROR while Running via OTA
Problem signing executable jar's
can run on eclispe but not command line
Problem deploying sample HelloWorld Bean in JBoss 4.2.1 GA
Under Java Security Manager, accessing a file inside a jar