• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Run jar file

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic