IntelliJ + Tomcat + Spring-Loaded
Asked Answered
C

2

12

I would like to try out Spring Source's "Spring Loaded" class reloading agent, with Tomcat run via IntelliJ.

https://github.com/SpringSource/spring-loaded

I've added the JVM arguments to my Tomcat run configuration, and my webapp starts up without errors and seems to behave normally.

I'm not really sure how to trigger the class reloading though. Do I just need to compile the classes that I modify? I've tried that and that didn't seem to work. Do I need to update Tomcat and deploy classes and resources? That doesn't seem to work either...?

Any specific configuration details would be greatly appreciated.

EDIT: More info, I think my problem may have to do with using two modules, one a core code library, and one the webapp. I use Maven for both, one configured as a jar project and the other as a war project. IntelliJ sets up the Artifact for the exploded war to use the jar module's jar file. I've tried switching the Artifact config to incorporate the jar module's compiled output into WEB-INF/classes instead. Now I see the .class files in target/webapp/WEB-INF/class/etc. But I'm not sure how to get IntelliJ to update a specific class file when I edit it.

Clarsach answered 27/2, 2013 at 17:42 Comment(2)
Did you figure out a way to handle the submodules with Spring Loaded?Casque
Not yet. I haven't been back to working on this for a long time.Clarsach
T
5

If you added the following jvm parameters (as described at the springloaded page) to your tomcat

-javaagent:<pathTo>/springloaded-{VERSION}.jar -noverify SomeJavaClass

you should be fine. It may help to disable auto reloading in tomcat for the webapp you are testing. For exmaple in your server.xml:

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    <Context docBase="projekt" path="/projekt" reloadable="false" ...

This ensures that only the springloaded classloader loads changed classes.

Tabard answered 16/9, 2013 at 11:50 Comment(5)
Thanks for your answer. What is it that triggers the springloaded classloader to reload changed classes? Does it just happen periodically? Does it monitor the class files for timestamp changes? Or do I need to perform an action in IntelliJ to trigger it?Clarsach
According to github.com/spring-projects/spring-loaded class files are watched for a changes once a second.Enwomb
Sorry but, how did you change this using IntelliJ? I mean, this is impossible to change using IntelliJ because you don't have visibility of the "server.xml", is it?Plaintive
There's the server location with old jars and old class files. Where's the definition of the location of the new compiled classes?Turk
@I.Cougil In IntelliJ you add it as a VM option in Run/Debug Configurations for the Tomcat Server you have created and are deploying to. The VM option in my case has the following -javaagent:c:/dev/springloaded-1.2.4.RELEASE.jar -noverifyHyponasty
M
0

spring loaded cannot hotswap jars.

Put web fragment output into webapp/WEB-INF/classes

Also spring loaded support only spring 4.1 https://github.com/spring-projects/spring-loaded/issues/139

Moslemism answered 14/6, 2017 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.