how to hot deploy jsp file using tomcat7-maven-plugin?
Asked Answered
W

3

6

I use tomcat7 with the tomcat-maven plugin. I am able to make it hotswap my jsp but it only work if I modify it directly in the target. How can I make tomcat also look for changes in my sources directory?

pom.xml

 <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <serverXml>${project.build.directory}/config/tomcat-config/${usingDb}/server.xml</serverXml>
                <tomcatUsers>${project.build.directory}/config/tomcat-config/tomcat-users.xml</tomcatUsers>
                <configurationDir>${project.build.directory}/config/tomcat-config</configurationDir>
                <additionalClassesDirs>
                    <classesDir>${project.basedir}/src/main/webapp</classesDir>
                </additionalClassesDirs>
                <contextReloadable>true</contextReloadable>
                <port>${tomcat.http.local.port}</port>
                <path>/${url.contextPath}</path>
            </configuration>
        </plugin>
Wauters answered 19/6, 2017 at 18:14 Comment(3)
Usually you use an IDE to launch tomcat fully integrated, it is much better. If you don't have specific rule in your pom, it means that the plugin copy the file before launching the application, so bad luck for you. Anyway. Use an IDE !Sweeting
it doesn't hotswap when you change it or when you clean and build your war project?Breadnut
hey @marc-chery, not sure if this qualifies as a "true answer", so just a random thought: I initialised a Node project alongside the Maven project, installed nodemon locally, created config to watch .jsp and .java files, and set a NPM run script with nodemon --exec "mvn tomcat7:run".. perhaps a little "hacky", but it does get the job done. (:Snashall
K
2

This depends on how you use/start the maven plugin. Starting it with

mvn tomcat7:run

should do the trick (in comparison to run-war or any other goal). See details at http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/plugin-info.html

This will actually reload the context in your tomcat. I'm not sure actual "Hot replacement" without reloading the context is possible without third party libraries/plugins like jrebel or similar.

Kilocycle answered 10/8, 2017 at 21:27 Comment(2)
..as a total Java noob, may I ask: would the concept of "hot replacement without reloading the context" also include changes made to the Java source package files? in other words, changes to the .jsp files will be visible in the browser (after a hard-reload, I've found), but changes to the .java files require the context to be reloaded?Snashall
@AndreGreeff, exactly. If you are debugging the process though, you can hot-replace code in java-classes too, unless signatures change, then you need to reload again.Kilocycle
H
2

You should be able to run the war:exploded maven goal to get your changes copied from your sources directory to the target directory.

Hire answered 10/8, 2017 at 21:38 Comment(0)
O
0

Change your workspace in Eclipse to \tomcat\webapps Since it is just for your work, this should work fine. Whatever changes you make in Eclipse is in the same directory tomcat looks for applications to deploy

Outfox answered 11/8, 2017 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.