Tomcat appBase and docBase
By dmytro - Posted on December 19th, 2009
While deploying JSF/Ajax application faced very strange problem. JSF mapping was working for files only in application root dir and in all other dirs was thrown such exception:
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsf/core cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)web.xml and faces configs were configured properly. And mapping was also OK:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>What was not obvious for me, there was no other errors in the logs, and all ordinary .jsp files were working. And jsf content was delivered ok if you specify http://client/test.jsf, but not http://client/anything/test.jsf
The problem actually was in server.xml. Both appBase and docBase had full path for stored jsp files, i.e. /home/client/public_html/
As said in Tomcat Configuration reference:
docBase
The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.
If a symbolic link is used for docBase then changes to the symbolic link will only be effective after a Tomcat restart or by undeploying and redeploying the context. A context reload is not sufficient.
Do not choose a docBase that starts with your Host's appBase string. The default appBase is "webapps" so do not choose a docBase like "webapps-foo." Doing so will lead to deployment errors: see Bugzilla for details.
The value of this field must not be set when the Context is configured using a META-INF/context.xml file as it will be inferred by the automatic deployment process.and
appBase
The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host. You may specify an absolute pathname for this directory, or a pathname that is relative to the $CATALINA_BASE directory. See Automatic Application Deployment for more information on automatic recognition and deployment of web applications to be deployed automatically.If not specified, the default of webapps will be used.With following configuration there was a problem:
<Host name="client.com" appBase="/home/client/public_html">
<Context path="" reloadable="true" docBase="/home/client/public_html" debug="1"/>and fix was pretty easy
<Host name="client.com" appBase="/home/client">
<Context path="" reloadable="true" docBase="public_html" debug="1"/>
