How would I allow an application running on Tomcat access to a network directory?

感情迁移 提交于 2019-12-11 03:22:53

问题


I'm running a web application (written in Java) on a Tomcat server running on Windows 7. At some point in the application, I try to access a directory on a remote machine through the basic java.io.File class.

If I start Tomcat from the command line through "tomcat6.exe //TS//MyServiceName", my application can successfully find the network directory. When I start Tomcat as a service, though, it thinks the directory doesn't exist.

Based on some research, I'm assuming it's an authentication issue. I've updated the windows service to "Log on as" my domain user account, and I've updated the tomcat service to add a username and password with 'tomcat6.exe //US//MyServiceName --User="bhardage" --Password="xxx"', but even with both of these changes it still doesn't find the network directory.

I've also tried 'tomcat6.exe //US//MyServiceName --User="mydomain\\bhardage" --Password="xxx"' with no luck.

Would anyone be able to tell me the proper way to get my web application running under a different user?

Any help/suggestions are much appreciated.

Thanks,

B.J.


回答1:


There seemed to be some problems with the "Log on as" feature. Maybe these problems still exist.

You can try to set the user account via the properties of the tomcat service in the windows service manager.

Here is a description how to do that. Look at attempt number 3. It is based on an old version of tomcat (5.5) but it should work the same way.

Edit:

Maybe your network directory is not mapped when the service starts tomcat. This may be because the user logs on in a separate logon act.

Try to execute a "net use" command before accessing the network directory. This can be done with:

Runtime.exec("net use Z: \\\\My\\Share")



回答2:


The "Log on" has to work (I have used it quite a few times), as long as that account has the necessary right to the network share.

When you start it from the command line, and it works, are you logged in as "bhardage" ?

Now, when you start it up as a service, which account do you see tomcat running under in task manager ?



来源:https://stackoverflow.com/questions/9914536/how-would-i-allow-an-application-running-on-tomcat-access-to-a-network-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!