I have a simple JSP page that creates a directory on centOS server root
<% File f= new File("/test/testdir");
if(f.mkdir()){
%>
generated a .WAR file and deployed on server. when i run this code. the created directory testdir have following attributes. it should have tomcat as a owner. tomcat is a user on my server and tomcat is the member of tgroup group.
i need that the directory should have owner as tomcat and group as a tgroup
Your Tomcat process is running as root (which is not a good thing). Since you already have a separate tomcat
user setup, complete the process of always running Tomcat as that user:
Assuming:
sudo /etc/init.d/tomcat stop
sudo chown -R tomcat:tgroup /opt/tomcat
sudo -u tomcat /etc/init.d/tomcat start
You may choose to hard code the user to run as in your startup script, which would be beneficial if you are setting Tomcat up to run on boot.