This is the first time I post a question here. Sorry if don't follow a specific convention.
I have this code that is working fine when I run it as a Java application (stand alone). It listes the files fine.
But when I try to run it in my Web App in Tomcat, the files are never listed because the remote folder does not exist.
Is there a restriction in Tomcat to open remote network addresses? The folder I am trying to open is in a different network. Again, the strange thing is that in a normal command simple program, the code runs fine. My issue is with my web app. Thanks!
Absolutly not. The code I want to run does not include the prints. This is an example of the code I'm running in my Struts web app (a class called by an action). It's a recursive scanning using file.listFiles(). The problem is that when I try to open the remote address, the folder is not found. But if I do it in a normal Java application, the folder is opened fine. Hope it clarifies!
Your directory path is what's technically referred to as a "UNC name", consisting of a servername plus a sharename. It's a construct unique to Windows fileshares. On a Linux/Unix system using Samba, the format would be "//hostname/sharename", which is a safer from accidents that come from miscounting backslash escapes.
It's possible, I suppose, that Tomcat is sandboxing UNC paths. However it's not common to use UNC paths that way in any event. Although there is a general-purpose apache commons library that can handle this kind of stuff, for a server, you'd usually want a more permanent and more traditional mechanism: a filesystem mount.
For Windows: "NET USE X: \\hostname\sharename", where X is any suitable drive ID.
For Linux use smbmount for a cifs node - usually automounted. For Solaris, you have to purchase a third-party package to make SMB/CIFS shares mountable, as the Solaris version of Samba lacks the smbmount feature.
There are 2 benefits to permanently mounting a share. The first one is that you can now access the share and its children just like any other local filesystem node, allowing for the variances in behaviour that come when you have different security systems, etc. involved. The second one is that you don't put the system through the overhead of resolving the network share every time you want to open a file, list a directory, or whatever. It's already resolved and locked down.
An IDE is no substitute for an Intelligent Developer.
Joined: Jul 19, 2010
Actually, I tried that before, mounting a network drive, but it was the same as using the UNC path. The remote server is located in a Windows and requires an user and password authentication which is already stored in the WIN 2003 server where I have the Tomcat. Maybe there is something in the server's configuration that restricts any web page to open a connection to a different network.
Joined: Jul 19, 2010
Solved!! It was indeed a permissions issue. Tomcat needed to start as the user I used to access the remote address. It was a matter of configuring the "Log On" tab in the Tomcat service.