java.nio.file.FileSystemException: Read-only file system

9,308

This issue is related to Debian sandboxing of tomcat. A solution has been described here:

https://stackoverflow.com/questions/56827735/how-to-allow-tomcat-war-app-to-write-in-folder

Share:
9,308

Related videos on Youtube

aardbol
Author by

aardbol

Updated on September 18, 2022

Comments

  • aardbol
    aardbol almost 2 years

    I have a tomcat webapp that generates a thumbnail from an image and wants to save it to a writable location (chmod 777). But for some reason I always get java.nio.file.FileSystemException errors and writing that image isn't possible.

    It works on my local computer (running the webapp in intellij), but not on my azure ubuntu 18.04 server vm. I can create a file in that directory from the terminal as any user.

    java.nio.file.FileSystemException: /var/www/html/static/avatars/8SZK9w.jpg: Read-only file system
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:215) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/java.nio.file.Files.newOutputStream(Files.java:219) ~[na:na]
    Jun 25 17:07:17 ubu18 tomcat9[103802]:         at java.base/java.nio.file.Files.write(Files.java:3487) ~[na:na]
    ...
    

    I tried many things like changing the ownership of the folder, chmod 777 it, changing the path to /tmp (triggered a FileNotFoundException instead), using a different java code to write a file. I also disabled apparmor.

    Any advice on what's causing this?

    • Michael Hampton
      Michael Hampton about 5 years
      How exactly are you deploying this app?
    • aardbol
      aardbol about 5 years
      @MichaelHampton As a war in the webapps folder. Note that /var/www/html/static/avatars is outside that folder