Question

I'm not sure if the fact that i'm using Ubuntu Server matters in this case. When I am trying to create folder using the File.mkdirs() method, it doesn't throw an exception, just never works.

A larger explanation of my problem with specific code references can be found here: Cannot Create Directory On Server. Permission Issue?

The reason i'm writing a new question is because i'm wondering if i'm having issues creating directories on the server because of permissions.

String path = /home/username/foldertocreate;
File file = new File(path);
file.mkdirs();

So i'm trying to create a folder in the /home/username directory. This works just fine when i'm running in dev mode on my dev box and on a tomcat instance inside of Eclipse, but fails when the code is run on the server. Could this be because on the dev box the user is logged in and therefore permission is open to write the /home/username folder? On the server a user isn't actually logged in while the program is running...

Is there a specific folder I am able to write to?

I checked the permissions of the folder which are currently set to 700. Could that be the problem? Is it safe to set this folder to 666 or 777? Is this folder writable even if the user is not logged in?

Update: Tried changing the folder permissions to 755 with no luck.

Was it helpful?

Solution

If you're using ubuntu's packaged version of tomcat, this is running under a different user account - most likely named 'tomcat'. Double check with ps aux | grep catalina - this will display the username that tomcat is running as in the first column. Exactly this user account needs to be able to create the directories/files.

For this reason, you probably don't want to open arbitrary home directories to be world-writeable, but rather configure specific directories somewhere to be accessible by the tomcat user. Setting a 755 permission gives the owner read/write/execute permissions, while everybody else gets read/execute permission. If 'tomcat' is not the owner, it will not be able to create anything in these directories. But don't fall for the trap to chmod 777 - unless it's for a quick test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top