3

I want to use some files outside my war file. It is located in

/opt/jetty/webapps

Let's say I want to put some files into

/opt/jetty/resources

and use them from my project. How can I access them from java code? When I use a full path in the deployed project, it's not working (no logging done and no errors):

Files.readAllBytes(Paths.get("/opt/jetty/resources/config"))
Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
LEQADA
  • 1,913
  • 3
  • 22
  • 41
  • What happens when your WAR gets deployed in a different container? Or over the web? You must provide a pointer to a "root" configuration in your command-line options to the container (probably in `/etc/myApp/...`), and pointers to all external files in the root configuration. – Jim Garrison Dec 14 '15 at 00:11
  • @JimGarrison, I just put war file into webapps directory and restart jetty service. It finds war automatically. – LEQADA Dec 14 '15 at 00:13
  • You still need to provide an external configuration (not part of the WAR) if you wish to refer to external resources. Something has to provide pointers to those external resources, and those locations must be discoverable at runtime. – Jim Garrison Dec 14 '15 at 00:15
  • @JimGarrison, how can I do it? – LEQADA Dec 14 '15 at 00:16

1 Answers1

1

If you need to read a file from the filesystem, you can access it directly. If your servlet doesn't see the file on your server, but does from the IDE, there might be a problem with privileges / access rights.

If your server runs under a different user, make sure that it has rights to read and write requred files. Otherwise you'll have a Permission Denied error.

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67