- This topic has 3 replies, 2 voices, and was last updated 19 years, 7 months ago by Riyad Kalla.
-
AuthorPosts
-
AmosMemberHi there,
New to these forums, so forgive me if I picked the wrong board… 🙂
I’m trying to parse an xml file, which I would like to place in the “resources” subdirectory of my project folder. I’ve got a little utility class in my package, and if I use this class directly (e.g. from a test main method), it finds the file “resources/bla.xml” just fine. However, if I call a method in this class indirectly from a jsp file, I get a file not found exception which says that it’s expecting the file somewhere else.
Before installing MyEclipse, it was expecting the file in my eclipse directory, i.e. “…/eclipse/resources/bla.xml”. Since installing MyEclipse, it’s looking in the tomcat/bin directory. Of course I can put the xml file in /eclipse/resources/ or in tomcat/bin/ for testing and I don’t get the exception, or I can use the absolute reference (i.e. “http://localhost:8080/%5Bproject%5D/resources/bla.xml”), but obviously that can’t be the long-term solution… surely there’s a way to make a relative reference to a resource file within my project directory?
Anyone know how I can get around this? Is there a setting somewhere that fixes this?
Cheers,
Amos
Riyad KallaMemberAmos,
Do yourself a favor and put the properties file in your source tree, for example, com.mycompany.resources, then you can use Class.getResourceAsStream(“/com/mycompany/resources/myproperties.xml”) from anywhere in your project. The problem you are having now has nothing to do with MyEclipse, it is an issue of “working directory”. These are totally different depending on how you run your app. When you are running a web app, the working dir tends to be the app server’s starting dir (tomcat/bin). But when you run standalone, the working dir will be whatever your IDE makes it (sometimes it is your user home dir… there is no way to tell).So by sticking the file in your source tree, you can always get to it in a predictable manner (I’m assuming this is a read only file? If it is not, then I suggest you use the Preferences class from JDK 1.4+)
AmosMemberHi Riyad,
I’m new to webapps, so thanks for answering a beginner’s question – much appreciated, and it did indeed work. I will actually try the Preferences class as well for another part of a project, so thanks for that as well…
Cheers,
Amos
Riyad KallaMemberNo problem Amos, web apps are a forest of fun things to discover like this 😀
-
AuthorPosts