views:

1356

answers:

4

Hello.

I'm facing this strange problem.

I'm trying to read a file that is located in another machine as a shared resource:

\\remote-machine\dir\MyFileHere.txt

When I run a standalone application ( a 16 lines java file ) everything is just fine. But when I attempt to read the same file with using the same class and the same method from a server "engine" ( this is an application engine, pretty much like a Java EE Application Server where you can run java programs ) the "FileNotFoundException" is thrown.

I though I would be some sort of permissions, so I map the resource as a drive: K:\

Re-run my java file, reads, fine.

Re-run my java file inside the "engine" -> FileNotFoundException.

When I copy the file into the local machine ( C:\MyFileHere.txt ) no exception is thrown.

Question

What may be causing this FileNotFoundExcecption?

I'm using Java 1.5

As far as I know the engine pretty much uses java transparently.

Anyone has faced something similar?

Additional question? What would be a good approach for workaround this? I'm starting to think about a tomcat installation serving those files and read them through http, but I think that's too much, that's why the SMB protocol is for in first place isn't it? And probably I won't be able to open sockets anyway.

Does security manager may be the cause ( I have never used that before, but I know it exists )

Wound't a SecurityException be thrown instead if that would be the case?

Thanks a lot.

EDIT

Solved. Thank you Steve W.

It turns out that this engine is launched with "LaunchAnywhere" from ZeroG. So, a .exe is created that in turn will run a JVM with the specified app.

This application it self is Launcher. When it start the engine, somehow ( I cannot figure out why or how ) the user that owns the JVM process is SYSTEM. AS Steve pointed out, this user doesn't have NETWORK access, and thus cannot read from a shared resource or a mapped drive.

The workaround ( while I report this to the manufacturer ) is to create a .cmd file to lauch manually the engine. Since it would be manually launched the user does have access to the network.

I've used "Process Explorer" from SysInternals to know exactly the command line used to run the engine app.

WHAT A MESS!

Thanks to those who posted answers.

+4  A: 

Is the shared resource protected by a username and password? And if so, is your application engine running as that user? If your application engine is running as a Windows Service, the Windows service cannot be running as the "Local System Account". This account cannot access the network. You must configure your service to run as a user that has the rights to access the shared drive.

Steve Wranovsky
1stq: It does. 2ndq: Is not. 3rd Is not a service, but looking carefully, the launcher is running as local user, but this launcher ( well ) launches the engine app whose user is SYSTEM ( hence not allowed to use network ) :-/ Am I to see how this launcher can start the app not as SYSTEM?
OscarRyz
I am looking at the "engine" is was started using LaunchAnywhere ( from zerog ) I don't know how does it start the new VM using SYSTEM :-/
OscarRyz
This answer gave the the hint to solve the problem. Thanks a lot.
OscarRyz
A: 

Double check that the file is REALLY Called "MyFileHere.txt" and not "MyFileHere.txt.txt" If you are hiding the extention of the file this is an easy mistake to miss

Harry
But then again, i didn't really read your entire question. I just remember the above mentioned issue happened and I was scratching my head debugging the issue for someone
Harry
Double and hyper triple checked. Also white spaces etc. I even hard code the path in the java file and it runs ok with java TestRead. But when the class TestRead is loaded into the engine it throws FNFE.
OscarRyz
A: 

Have you checked the event logs on the server to see if it is being rejected? it could be that the program is running under a different user account than you think.

I'm not familiar with Java, but i know with some programs i've written i've had to allow Network Service to access the resources.

Actually i see that you have now ticked an answer as the correct one. oh and it was the same as my answer :) Cool!

Harry
jejej Yeap.. thanks a lot. Actually your deductions were pretty close. I am not very aware of Windows services my self, and this took my by surprise. But I finally got a good hint there with Steve suggestion. ufff. Thanks anyway.
OscarRyz
A: 

I had a similar problem once. I think it has to do with the way java resolves remote files URI's. Try the following and see if it works:

File:////remote-machine/dir/MyFileHere.txt

I used the folowing example to verify the existence of a file in shared folders in my box and worked:

public static void main(String[] args) throws URISyntaxException{
 URI uri = new URI(args[0]); //args[0] = File:////remote-machine/dir/MyFileHere.txt
 File f = new File(uri);
 System.out.print(String.format("File %1$s Exists? %2$s", args[0],f.exists()));
}
Igor Zelaya
Thank you Igor. That's not the case, for the same "path" was used inside and outside the engine. The problem was the VM was created using as user SYSTEM whose doesn't have network resources access. Thanks for the response though.
OscarRyz