Maven 2, MyEclipse & Tomcat Hot Deploy
Recently we have been attempting to move away from manually managing libs for each project and move to a central repository for manging our jars and dependecies. Maven 2 seemed like the ideal tool for this and since it seems to have such a large body of support we thought that it would be reasonably easy to integrate into our current development processes. We even thought we might get quite a bit of leverage out of the other plugins available for Maven 2 which would allow things like automatic site generation for the project and documentation of dependencies.
Unfortunately getting Maven 2 integrated into our current development processes was anything but easy. We usually build Web applications and we use the MyEclipse plugin for eclipse to automate and speed up many of the repetitive tasks. Auto-deploying wars and hot-swapping code is one feature we consider absolutely critical to our rapid development process. The following is a description of how we eventually got this working, and now can in fact get setup quicker than we could our old way.
- First make sure that Maven 2 is installed and that it is in the path (see the Maven install instructions if you can find them).
- .Configure the M2_REPO variable in Eclipse to point to your maven repository (usually
/.m2/repository). This can be configured in Eclipse under windows->preferences->Java->build path->Classpath - Next, I have found that is easier to just follow the Maven folder conventions than to try and get maven to follow yours. This means that the normal src folder becomes src/main/java, all resources and configuration files go in src/main/resources, and the web root becomes src/main/webapp the test tree follows the same structure and becomes src/test/java and src/test/resources. In order for MyEclipse to live with this and do a hot deploy you need to tell the web deployer that your web context root folder is /src/main/webapp, this can be done when you give a project web capabilities but if your project already has web capabilities then you will need to modify the .mymetadata file in order to change it and restart eclipse.
- obviously your project needs to have a valid pom.xml in the project root. Under the
<plugin>part of your pom put the following:
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-eclipse-plugin</artifactid>
<configuration>
<buildoutputdirectory>src/main/webapp/WEB-INF/classes</buildoutputdirectory>
<downloadsources>true</downloadsources>
</configuration>
</plugin> - this tells eclipse to build to the classes folder under your web root WEB-INF folder (where they need to be for a hot deploy)
- Navigate to your project root on the command line and run mvn eclipse:eclipse this should build your .classpath file according to your pom.xml and even attach source code where available.
Most people should be able to hot-deploy as normal now using the MyEclipse server tools, however i have noticed some people have problems with servlet-api.jar and jsp-api.jar conflicts, if that is the case then the following steps should fix that:
- Right click on your project and go to the properties>java build path>libraries You will need to look through this list for servlet-api.jar and jsp-api.jar, remove them and add the J2EE library (You will need to do this each time you run the eclipse target or else your servlet-api.jar and jsp-api.jar will get deployed to your web server and may interfere with the one it already has in it’s classpath
- Next, still under the project properties item go to MyEclpse->Web->Deployment uncheck the ‘workbench default settings’ and ‘Jars in web Projects user Libraries’
you should now be able to do a normal MyEclipse hot-deploy…
August 18th, 2009 at 1:29 am
Hi,
I want to build using maven and deploy to tomcat in eclipse with hot deployment feature . Like when I Update some thing it should build the source ( Build automatic ) and deploy to tomcat . Can u tell me is that possible with eclipse .