• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run jar file

 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can: java -jar apps\jar\myapp.jar works just as well.

You just cannot use PATH or CLASSPATH when running JAR files.
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic