- https://www.mulesoft.com/tcat/tomcat-configuration
- https://www.mulesoft.com/tcat/understanding-apache-tomcat
https://tomcat.apache.org/tomcat-8.5-doc/host-manager-howto.html https://tomcat.apache.org/tomcat-8.5-doc/config/host.html
https://tomcat.apache.org/tomcat-5.5-doc/config/host.html#Automatic Application Deployment
http://www.onjava.com/pub/a/onjava/2003/06/25/tomcat_tips.html
Removing the unpackWARs feature https://wiki.apache.org/tomcat/RemoveUnpackWARs
// unpackWARs="false" the
SevletContext.getRealPath();// method always returns null
https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
getServletContext().getRealPath("/")
// returns '\' at the end when I run my project in Tomcat 7 whereas it is not
// working as such in Tomcat 8.
// For example,
// In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
// In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
//At present the project is in production so, I am unable to change the code
//in every part(where i use getRealPath("/")). Is there a way/setting in
//tomcat level configuration to make it resolved.
//Additional information, Tomcat version : 8.0.14
tomcat implementation
https://bz.apache.org/bugzilla/show_bug.cgi?id=57556
// the servlet-2_3-fcs-docs for ServletContext.getRealPath():
// "This method returns null if the servlet container cannot translate the virtual path to a real path for any reason
// (such as when the content is being made available from a .war archive)."
config.getServletContext().getRealPath("/" + storageLocation);
getServletContext().getResource("files");
// Read the javadoc for ServletContext.getResource:
//"Returns a URL to the resource that is mapped to a specified path. The
//path must begin with a "/" and is interpreted as relative to the current
//context root."
ServletContext#getRealPath()
// may return null in case that the cms.war is running without being unpacked.
// So, I think it's better to use a default storage directory instead in this
// case under the current working directory (e.g, "./repository_storage").
The java.io.File acts on the local disk file system. relative paths in java.io are dependent on the current working directory. "user.dir"
in the classpath use
ClassLoader#getResource()
orClassLoader#getResourceAsStream()
instead. It is able to locate files relative to the "root" of the classpath, In webapplications (or any other application which uses multiple classloaders) it's recommend to use the ClassLoader as returned byThread.currentThread().getContextClassLoader()
for this.Another alternative in webapps is the
ServletContext#getResource()
and its counterpartServletContext#getResourceAsStream()
. It is able to access files located in the public web folder of the webapp project, including the /WEB-INF folder.// also need classloader
// local eclipse+tomcat:
// file:/home/bzu/eclipse-workspace-fogo-wrong-decision/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/fpc/WEB-INF/classes/
// a safer way is to use class name itself for this solution, for example,
// MyClass.getResourceAsStream(), as often this.getClass() won't work in subclassing or autoproxying scenarios.
CATALINA_BASE=/var/tomcat export CATALINA_BASE