• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Classpath or How to declare files

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My application has a command line interface and it is packaged into a .jar file. In my application, I use Log4J for logging. I have placed the log4j.xml at the same directory where the .jar file is kept and it works fine.
D:\Development\Filehandler\dist\...


But, when I call the .jar file from some other directory, for ex: C:\, it throws error as FileNotFound for the log4j.xml file. The reason for calling from some other location is, this jar file will be used by PHP. The PHP script will call the .jar file from some other location.

Please guide me in solving this issue....
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to specify classpath when you start your jar. For example:


If you call it form PHP you'll have to ensure that classpath is passed as a parameter when invoking.
 
Raj S Kumar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,
Thanks for the Reply.

My problem is not with accessing the jar files. But, the related xml files. I have placed the required library files in the \lib directory where the Application.jar file is.

In my application, I am referring to the xml file in this way. Should I change it in some way that, it would look for it in some specific location?

 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use it like that Java will try to access the file located in the same directory, that the .class or .jar file is. You should somehow input full path or make sure the xml file is where the jar file is. You could pass full path as an argument passed to your main class or use -Dproperty=value option and retrieve it with System.getProperty("property"). If those two are even an option.
 
Raj S Kumar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you use it like that Java will try to access the file located in the same directory, that the .class or .jar file is.



The log4j.xml is in the same directory as the .jar file. Yet, I am getting the exception when I call the .jar file from PHP.

If I place the log4j.xml in the same directory as the PHP page, Its working fine.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic