I use tomcat server, and try to call a java class from servlet, that class has method which will return system current directory path. It’s result is difference with the one when I run form main method in that class.
- from main method: “D:\Projects\Eclipse\Assignment” (which is where i place my project)
- from servlet: “D:\IDE\eclipse helios” ( which is where i place my eclipse)
With this I have trouble to access my xml file in my project folder( file not found exception when I call a class from servlet). I want the same result when call from servlet as when run main method. How can I do that?
I would appreciate any advice you could give me to, or any articles that you could recommend.
Thank you.
Why are you trying to access your resources from the filesystem? The expected method of accessing resources from any JAR, including webapps, is using getResourceAsStream:
http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
i.e. add the folder containing your resource to the build path, and use
YourClassName.class.getResourceAsStream("/foo.xml")to access it.