• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath or How to declare files  RSS feed

 
Raj S Kumar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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....
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!