Is there a way to set a relative path to the docBase attribute in the context.xml of a web application, so it is outside of the appBase directory of the tomcat server instance?
I would like to be able to share the context configuration between computers and have the app living in a directory, not a war file. That way i can compile the classes directly into that directory (in my project development directory) and have tomcat use these classes without any copying/packaging needed.
I am using the tomcat 8.0.0-RC5. My directory Layout is:
/home/david/projects/frontend/web-content <-- the static html files
/home/david/projects/frontend/web-content/WEB-INF <-- the WEB-INF with the web.xml
/home/david/projects/tomcat <-- tomcat base directory
/home/david/projects/tomcat/Catalina/localhost <-- holds the frontend.xml context configuration
I have tried
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/frontend" docBase="../../frontend/web-content">
</Context>
but that did not work. The whole path before /web-content seems to be ignored. The log says:
The main resource set specified [/home/david/projects/tomcat/webapps/web-content] is not valid
The Tomcat 8 documentation for the context container says:
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.
Does relative here mean a strict subdirectory of appBase (no .. allowed)?
Setting an absolute path works without problems. The configuration
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/frontend" docBase="/home/david/projects/frontend/web-content">
</Context>
works, but it is specific to my computer. So I cannot share the context configuration without modification anymore.
I could create a symbolic link inside the appBase directory of the tomcat server and let it point to the web-content folder of my application. This would work, but I would have different configurations (symbolic links) on linux and windows machines.
The context path of a web application defines the URL that end users will access the application from. A simple context path like myapp means the web app can be accessed from a URL like http://localhost:8080/myapp.
xml. The second option is to set the context path of the application in the server. xml (which is located at $CATALINA_HOME\conf). Note: defining the context path manually has the side effect that the application is deployed twice by default: at http://localhost:8080/ExampleApp/ as well as at http://localhost:8080/.
Simply put, the context path is a name with which a web application is accessed. It is the root of the application. By default, Spring Boot serves the content on the root context path (“/”). So, any Boot application with default configuration can be accessed as: http://localhost:8080/
tools:context is such an attribute that is defined in any root view and declares which activity or fragment the layout is associated with. This declaration helps in enabling various features in the layout preview which demands the knowledge of the activity such as automatically choosing the necessary theme for preview.
Just taking only the last name of relative path names and ignoring the first parts
is most likly a bug in tomcat. Relative path names should work or must throw errors.
But ignoring parts is bad.
A workaround could be using an absolute path name like this:
<Context docBase="${catalina.home}/../www.war"
I just reading the changelog of Tomcat 8.0.15. The bug should be fixed(!): "Correctly handle relative values for the docBase attribute of a Context."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With