Issue
I have a multi-module Maven project for a webapp. Example:
project-root
|- core
|- webapp-demo
where webapp-demo
references core
.
Most jsp and tag files are placed in webapp-demo
. However, some are placed in core
.
For development, I build and deploy this project using Maven as exploded webapp (i.e. the content of the WAR file but uncompressed). This also works fine from IntelliJ. Further, when I do "Build > Rebuild Project" in IntelliJ, then
- JSP and tag files are packaged.
- Changes to the files in
webapp-demo
are immediatedly recompiled by Tomcat. I can see the new version when I reload the page.
However, changes to the jsp and tag files in core
are not immediately recompiled by Tomcat. I have to stop and start Tomcat to see the changes.
I noticed that the changed files are packaged correctly by IntelliJ. The new tag file is available in the JAR of the webapp's "lib"-folder (/WEB-INF/lib). Sadly, Tomcat does not seem to notice this.
Is there a Tomcat configuration to make this work? I want Tomcat to recompile changed jsp and tag files even though they are inside a JAR in /WEB-INF/lib.
Maybe there is an option to also "explode" these JAR files (or at least their jsp and tag files)?
I prepared an example project on GitHub to reproduce my issue.
- I found this thread where it is said not to work for stuff inside /WEB-INF/lib.
- I found this other thread where it is said to work when one adds a
<WatchedResource>
config. I tried this and it did not work. - I tried "start" and "stop" of the webapp in the Tomcat Manager but the changed tag file is still not recompiled. It still shows the old version. Only when I stop and start the run config in IntelliJ (which stops and starts whole Tomcat), then I see the changed tag file of
core
.
Solution
I noticed that Tomcat DOES recompile jsp and tag files inside JAR files.
However, "Package File" action of IntelliJ, which updates the file in the JAR, is not enough for this.
To recompile jsp and tag files in a JAR from a dependency, I have to
- compile the dependency project
- In the example, go to
core
project and runmvn install
- In the example, go to
- package the webapp project
- In the example, go to
webapp-demo
project and runmvn package
- In the example, go to
Tomcat then notices the changed JAR and recompiles the jsp and tag files.
Note that it does not work, when running mvn package
in core
project. It seems like Tomcat is missing something, when the dependency project is packaged but not build.
Note further that Tomcat seems to recompile all jsp and tag files in the JAR in this case. Maybe even further files from later projects that depend on these. Thus, in my case recompilation of the jsp and tag files of the changed JAR takes nearly as long as deploying the webapp from scratch.
Tested with Tomcat 9.0.50 and Maven 3.6.0
Answered By - mihca
Answer Checked By - Senaida (JavaFixing Volunteer)