问题原文
原帖链接 · Yeti · CC BY-SA 3.0
Setup
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:
If /usr/share/tomcat7/webapps/foo/bar.html contains:
<!DOCTYPE html>
<html>
<body>
Hello world!
</body>
</html>
Then http://localhost:8080/foo will show:
Hello world!
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 bar.html).
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?
社区高分解答
原帖链接 · GlenPeterson · CC BY-SA 3.0
What @Schrute said in a comment (not an answer): Use option #1 (ln -s) and just allow linking in the Tomcat context.xml file. For Tomcat 7:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true">
...
Tomcat 8:
<Context>
<Resources allowLinking="true"></Resources>
...
DO NOT DO THIS ON WINDOWS (or any other case-insensitive filesystem), as it will disable case sensitivity checks, allowing JSP source code disclosure, among other security problems. http://tomcat.apache.org/tomcat-8.0-doc/config/resources.html
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
