views:

65

answers:

3

Hello World!

I have developed a java servlet that monitors a folder on a network drive for new files then does some actions on them depending on what kind of file it is. It worked in Eclipse when Eclipse and Tomcat were running with each other, but now that I have deployed it onto a server(different machine), the servlet keeps logging that it cannot find the folder to be mapped. The exact same network drive is mapped, and the folder definitely exists. This problem only occurs when the servlet is run on the server, not on the development machine.

Thanks!

PS: It is a Windows Server 2003 Enterprise Server with Tomcat v6 installed.

+1  A: 

Are you using relative paths in your code to find the file? The paths to reach a file in your filesystem when the code runs in your IDE or local Tomcat is more than likely not the same path to reach the file as when it runs on other machines/environments.

Best bet is to remove the paths from your code completely and load them from a configuration file instead.

matt b
I did, and reconfigured the configuration file for the server, however, because it is a network drive, the file is located on the E drive for both machines.
Austin
A: 

Can you try output of this API to check if the file path is what you are expecting

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

prasrob
please forgive me if this is a dumb question, but i keep getting a NullPointerException for the line this.getServletContext();Why would this be null?
Austin
may be you want to check this link too http://www.coderanch.com/t/360208/Servlets/java/getServletConfig-does-not-work
prasrob
I got it working, and the file path is indeed not what I am expecting. Thanks, now to find out what to do to fix it!
Austin
I am stumped again. What do I do now that I figured out that the file path is NOT what I expected? Can I change the servlet context?
Austin
Adding the file path in some configuration file, might be a good idea
prasrob
A: 

I finally figured it out.

It turns out that when Tomcat runs it (obviously) is running as a service. The service does not see things the same way as a user does. It turns out that Windows ONLY mounts network drives at the USER level. Therefore, according to the SYSTEM, the drive does NOT exist. The workaround was to use UNC pathnames.

I tried that originally, but it did not work, and the reason for that was because the service did not have correct permissions.

Thanks to everyone who helped me.

http://wiki.apache.org/tomcat/FAQ/Windows#Q7

Austin