Skip to main content
gamedev.net
🔒 Locked

Regular Java vs Tomcat Project

Started by Clueless Jan 3, 2007 at 1:10 PM 3 replies 1.3k views
Original Post
Clueless
Clueless
Hi everybody, I tried getting code that works as a regular Java project to work as a Tomcat project with servlets. Now a lot of things change when you do that, right? First thing I had to struggle with was the root path. Why does it change at all? Can I change it back somehow? For example this used to work:
... new File("./properties.xml") ...
And I had to change it to:
... new File("\\D:/EclipseWS/Italienisch/properties.xml") ...
The next problem that I have not fixed yet is that dynamically loading classes doesn't work any more. There is no error when I import it in the java file directly ... but when I use the exact code in Class.forName(...) a ClassNotFoundException is thrown. It did work in the regular Java project. And I did not forget to add the external library (obviously). Any ideas? Maybe some ideas where I can start researching? Didn't really find anything in google.
Writing errors since 10/25/2003 2:25:56 AM
Clueless
Clueless
Funny ... like so often. I think I researched about 2 hours before I posted ... and I think I just fixed it :-)

Just not sure how to set the root folder yet ...
Writing errors since 10/25/2003 2:25:56 AM
Clueless
Clueless
Don't think I'll figure it out.
For some reason the root path was set from the project root directory to somewhere in the eclipse directory.
No idea why. Maybe it usually doesn't happen and I just messed up somewhere.
I can't find anything suspicious in the project settings.

The other problem was just that I didn't put the library into the lib directory in the WEB_INF folder.
Guess it has to be put there.
Writing errors since 10/25/2003 2:25:56 AM
Barius
Barius
For property files, using the "getResourceAsStream" method of the class "Class" is probably better, since you can use paths relative to the CLASSPATH.
For example, if the CLASSPATH contains C:/foo, and the file is on the path "C:/foo/bar/baz/properties.xml", you'd access it as follows:

InputStream stream = getClass().getResourceAsStream("/bar/baz/properties.xml");

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.