Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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!

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()));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top