working directory in web application
I have my Java project, say in C:\User\Workspace\myApplication
And there’s an xml file in that folder: C:\User\Workspace\myApplication\myXML.xml
And in my java program, I will take that xml file to retrieve information. So, I need to call it from my program. And now I am loading that file like:
File xmlfile = new File(“C:\\User\\Workspace\\myApplication\\myXML.xm l”)
And I know that it’s not a good way to load a file using directly the absolute path. So, I try to call it from my program dynamically. Here, my program is web application. And I use Tomcat.
First, I tried this way:
File directory = new File(“.”);
String loc = directory.getCanonicalPath();
File xmlfile = new File(loc + “myXML.xml”);
And, second I tried using: System.getProperty(“user.dir”);
Both first and second way give me the same result. When I tried to test those methods as Java application, they both gave me the path : C: \User\Workspace\myApplication
But when I tried to put it in my program which accepts input from JSP and run on server, then the result path is: C:\Eclipse. So, there’s an error that the system cannot find the file.
Why it cannot find the actual path?
And how can I do it to load that xml file into my Java program.
Any reply would be greatly appreciated.
Re: working directory in web application
Is the "Eclipse" user on whose process the web server is running?
That could be one reason for your problem
Check if this helps you
|All times are GMT +5.5. The time now is 05:40.|