Recompiling JSP files on volume when Tomcat runs in Docker container

I would like to use Docker to setup a local development environment of a Java webapplication running on Tomcat. I am running Tomcat inside a Docker container, and have mounted a volume containing the Tomcat webapps directory containing the JSP and Java class files of the web application.

The volume is mounted using the -v flag to Docker. So when I make changes to the JSP files in the mounted volume on the host machine (Windows or Mac), then I want Tomcat inside the Docker container to detect that the JSP files are changed and recompile the JSP into a new servlet, so that the web application becomes updated with the latest changes in the JSP files.

However, the problem is that when I make changes to the JSP files, then Tomcat does not detect that the JSP files are changed and will therefore not recompile the JSP files correctly. I think that Tomcat has been configured to detect and refresh JSP files correctly, but the problem might be that the volume mounted with Docker does not “inform” Tomcat correctly that the JSP files are changed. Does anyone have any advice on how to mount the Tomcat webapps directory so that changes to JSP files are updated instantly inside the Docker container?

Hi,
I am not sure about the Tomcat and JSP part in your case, but I have seen similar issue with nginx. This is not a Docker issue, rather its something related to Virtualbox (I assume you are using boot2docker).

There is an open ticket for virtualbox for the same https://www.virtualbox.org/ticket/9069 which is 4 years old.

This was the fix with nginx - http://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile

A similar issue was discussed here : Docker "Mount a volume on the Container" for Mac OS X kinda works

I am sure something similar will be there for tomcat.

Regards

Thanks, I have resolved this issue now.

Hi,

How did you resolve the issue? Was it something related to the issue which i mentioned. If you can share the solution it will be very helpful for others who are facing similar issue.

Regards

Your answer was very helpful.

It turned out that Tomcat was actually able to recompile JSP files from the mounted volume and detect changed files in the Docker volume. So what I had was not a problem with mounted volumes on Docker.

My problem was that when JSP files were compiled manually by ant to WEB-INF\classes, then making changes to the JSP files would not result in Tomcat compiling new servlets from the JSP files. So the solution was to not compile JSP files manually to WEB-INF\classes with ant, since then Tomcat would compile the JSP files correctly.