I use Apache Tomcat 7 on an Arch linux distribution, and my webapps directory is located at
/usr/share/tomcat7/webapps. In this directory one should create a directory, and put META-INF and WEB-INF directories in it with xml configuration files. Then this directory will be the main path of the webapp. Thus for example:
<!DOCTYPE html> <html> <body> Hello world! </body> </html>
http://localhost:8080/foo will show:
However, the goal is to have an external dynamic project (distributed by Netbeans in this case) as a webapp. So in that case I would like to locate my webapp here:
/home/user/NetbeansProjects/foo/build/web/ (which contains
I've come up with three possible approaches but none are working and I think I'm missing something.
Approach 1 (symlink)
I was thinking, let's put a symlink (symbolic link) in the webapps directory using this command:
$ ln -s /home/user/NetbeansProjects/foo/build/web /usr/share/tomcat7/webapps/foo
This seems like the most elegant approach, but Tomcat is not able to read the directory. Why not?
Approach 2 (mount --bind)
I read that you could also redirect one directory to another using
mount --bind. So I tried to do this:
sudo mount --bind /usr/share/tomcat7/webapps/foo /home/user/NetbeansProjects/foo/build/web
Actually, this is the only solution that does work. Unfortunately, if I build the project again the mount will disappear. I have already tried to remount the directory after distributing the project using
<exec/> in Ant, but this makes Linux crash for some weird reason. So this is not an option either. Also remounting after every clean-build seems not a clean approach. Mounting is also not really used for this kind of stuff, so I imagine the solution will not involve mounting.
Approach 3 (server.xml)
The last thing I want to do is to go againsts the recommendations of the Apache folks (see here). Which says:
It is NOT recommended to place elements directly in the server.xml file.
So what do I do, I take the default server.xml and add this Context-tag to the Host-tag:
<Context docBase="/home/user/NetbeansProjects/foo/build/web/" path="/foo"></Context>
However, if I restart the Tomcat service it fails to start. In the logfiles I read:
SEVERE: Error starting static Resources java.lang.IllegalArgumentException: Document base /home/user/NetbeansProjects/foo/build/web does not exist or is not a readable directory
So, obviously this must be some kind of permission problem. Since I double checked for spelling errors the path must be correct. But I am not able to solve this, what I have done to grant tomcat7 (group: tomcat7) permission is:
chown -R tomcat7:tomcat7 /home/user/NetbeansProjects/foo/build/web chmod -R 755 /home/user/NetbeansProjects/foo/build/web
But after restarting Tomcat, the same error occurs and Tomcat fails to start.
Which approach above is the most sensible, and what am I doing wrong that's preventing it from working?