Serve static resources from external folder outside webapps tomcat
Tomcat will serve any static content from a WAR file using the DefaultServlet. This works great for serving files that are bundled with your Java code inside of a WAR file – it’s fast enough for most purposes and it just works, but with one major drawback: you have to re-deploy the WAR file if you want to add or amend a static file.
Tomcat can be configured to read files from anywhere on the disk and serve on a specific URL. This configuration is completely separate to our application configuration.
You just need to change a single file server.xml that resides under $CATALINA_HOME/config/server.xml.
Just open the server.xml file and make the changes like below.
Remember: You need to take bounce of server after the making the changes to take effect of the changes.
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="C:AnkurtestFiles" path="/companyLogo" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
A <context> element is added inside the <HOST>
Thanks 🙂
Is there a way where we can supress the error which comes if the path of docBase is not present
Hello,
I use your idea sucessfully with tomcat 7. I migrate the application from tomcat 7 to 9. But now, I can't access to http://localhost:8081/companyLogo/test.png.
Have you pointers ? Ideas ? New security mechanism with tomcat 9 ?
Thanks
PHL
I am also facing the same issue
Awesome! Helped me a lot. Thanks.
Btw tomcat 9
Thankyou for sharingerp software
I wand to read from s3 bucket instead of c:\somefolder\test.png. Any idea? pointer? for tomcat 8.5