Hot code for deploying tomcat with Maven

I have a web application built using maven. It is built in the form of various projects that depend on each other - domain, dao, services, etc. I ran eclipse: eclipse in each of them to set up an eclipse environment. So now I have several projects in eclipse. This is my development.

I also created a tomcat package for the Operations guys, so I can just provide them with a zip file that they can extract and run the batch file to start the server. This zip file contains the military file that is mentioned in the <context> configuration for tomcat.

Also, for development purposes, I installed tomcat to run from eclipse. My goal is to deploy hot code every time the source changes. This is not happening at present because the class files are in the "target" folder (due to the maven directory structure). And tomcat looks at the war file (exploded structure, I mean ..)

How can I set up tomcat / eclipse environment to start hot code deployment?

-Thanks!

+4
source share
3 answers

I use tomcat-maven-plugin and its target is tomcat7:run to run tomcat from within eclipse (btw using the m2e plugin for eclipse is a great tool available from the eclipse market). Replacing the hot code does not work for me either. But I use a workaround: when <contextReloadable>true</contextReloadable> tomcat reloads the application whenever it detects a file change.

 <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>/myapp</path> <contextReloadable>true</contextReloadable> </configuration> </plugin> </plugins> </build> 
+10
source

Tomcat does not support "hot" rework on its own if your application infrastructure does not support reloading classes. (The tapestry does, but I do not recommend using the tapestry for other reasons). I'm sure eclipse: eclipse also does not support hot redistribution, so you have two things that work against you.

You have two alternatives that I know of ... first switch to using M2Eclipse instead of eclipse: eclipse. You will need to get rid of your old eclipse: setting up eclipse for this. Using m2eclipse will export classes from the eclipse compiler to Tomcat. this avoids the intermediate step "mvn clean package". Once you launch m2eclipse, you can download JRebel. JRebel will support hot redeployment, even if the infrastructure does not support reloading classes.

Good luck

+1
source

You can use the reload mechanism controlled by "autoDeploy" which you can read about it here . I changed my maven-war-plugin to bring the war to the webapp folder:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <outputDirectory>${my.tomcat.path}</outputDirectory> </configuration> </plugin> 

with

 <properties> <my.tomcat.path>[MY TOMCAT WEBAPP PATH]</my.tomcat.path> </properties> 

After that I only need to do mvn compile war:war or mvn compile package

0
source

Source: https://habr.com/ru/post/1333509/


All Articles