Search code examples
javamavenservletsjettyjetty-9

How to use files outside of war file on jetty server?


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"))

Solution

  • 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.