0

I'm working on windows, with Tomcat 9.0 / Java 8 One of my servlet will create and manage quite a lot of images. So we decided to store those on a network disk.

On my Windows server I mounted the resource on P:/

To access images outside Tomcat, I set the context in the host of server.xml. To be sure that it was working fine, I first tried in local like this :

<Context docBase="C:/IMG/" path="/RepIMG" />

Then if I try to access : http://localhost/RepIMG/test.jpg The image is displayed.

But if I change my context to :

<Context docBase="P:/IMG/" path="/RepIMG" />

Tomcat will not start at all with this error : Caused by: java.lang.IllegalArgumentException: L'ensemble de ressources principal [P:] est invalide

=> The main ressource [P:] is not valid

If I try to access directly P:/IMG/test.jpg with Chrome it works fine. I checked the permissions on the folder and everything seems to be ok.

Since it's working when I access a local disk I assume the issue is the fact that I try to access a mounted disk.

Is there something to specify or some way to troubleshoot this? To know exactly what's wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pandalex
  • 23
  • 7

1 Answers1

1

I'm assuming you're running Tomcat as a service (e.g. not through your IDE or Command Line). This way it will run in a different context, likely as a different user. That context/user account doesn't have your local user's drive mapping - only the local disks are the same for all accounts.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Thanks, This seems to be the issue. I tried to start Tomcat with my session but it didn't solve the issue. I also tried to set the server.xml with the UNC path but to no avail : . . and just in case : – Pandalex Jul 05 '21 at 11:11
  • well, those network paths will likely require authentication... Not sure if the service user that tomcat uses is allowed to access them. (Note: I can't help you on windows networking specifics, just point out the most probably cause) – Olaf Kock Jul 05 '21 at 13:00
  • Ok, I'll continue digging, thanks a lot for your help ! – Pandalex Jul 05 '21 at 13:14
  • Tomcat 9.0 by default runs as `LocalService` (check in Procrun/Tomcat Monitor), which presents guest credentials on the network. You might want to change it to `NetworkService`, which uses the machine's credentials on the network. – Piotr P. Karwasz Jul 05 '21 at 13:27