Home > Back-end >  Serving static content in Tomcat 10
Serving static content in Tomcat 10

Time:11-17

I deployed a webapp on Tomcat 10 and at certain point it forms KML files to be displayed on map (Google Maps API) and Google requires files to be publicaly available via URL. So in my app I decided to store formed files in specific temporary directory to serve them, then upload them to map and erase. How can I make a directory on my machine be available via URL in Tomcat 10?

I can access them if I packed them in war but that is not what I need. I tried adding

<Context docBase="/opt/tomcat/static" path="/kml/" />

element to server.xml but when I try to reach my file with example.com\app-name\kml\file.txt it throws me to 404. Other articles seem to be somewhat outdated. What would be the appropiate approach for Tomcat 10? Thank you!

CodePudding user response:

It appears to be I wasn't far off.

<Context docBase="${catalina.base}/static" path="AppName/kml/"/>

In server.xml under <Host> tag hosts static content from folder <CATALINA_BASE>/static on URL /AppName/kml.

  • Related