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
Author

Run jar file

P Igor
Greenhorn

Joined: Nov 20, 2006
Posts: 20
Hi,

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??

Thanks
amit punekar
Ranch Hand

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

?

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

Regds,
Amit


Regards,
Amit
P Igor
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
P Igor
Greenhorn

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