javaspringpermissionsembedded-tomcat-7

Permission denied with embeded tomcat


I have a Spring boot application which tries to access files located in "/var/someDirectory"

Platform is: linux ubuntu 16

Server Application is: Embedded tomcat

here is the code:

    File file = new File("/var/testFile1.txt");
    if (file.createNewFile()) {
        System.out.println("File is created!");
    } else {
        System.out.println("File already exists.");
    }

but with exception:

java.io.IOException: Permission denied

Question:

How can I grant permissions to my application on '/var/' ?


Solution

  • sudo mkdir /var/someDirectory
    sudo chown -R your_user /var/someDirectory
    

    It is not about Java, honestly.