aspose file tools
The moose likes Java in General and the fly likes Classpath or How to declare files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Classpath or How to declare files" Watch "Classpath or How to declare files" New topic
Author

Classpath or How to declare files

Raj S Kumar
Ranch Hand

Joined: Aug 06, 2006
Posts: 48
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....


Raj S Kumar
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
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.


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Raj S Kumar
Ranch Hand

Joined: Aug 06, 2006
Posts: 48
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

Joined: Sep 16, 2008
Posts: 241
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

Joined: Aug 06, 2006
Posts: 48
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classpath or How to declare files
 
Similar Threads
Calling a Jar file from PHP and System.out.println
Calling PHP from Servlet
Unable to deploy a war file from the correct location
"Applet not initiated" in Tomcat 3.3
sorry bout this: log4j & tomcat question...