Pages

Wednesday, August 7, 2013

WAR file hot deployment issue with Maven[Solved]

Hi guys,

In this blog, I am going to show you how to deploy your war file automatically when you are working with J2EE project using maven build tool.
To make J2EE project with Maven build tool, you should use

Group Id: org.codehaus.mojo.archetypes
Artifact Id: webapp-j2ee14

To build your project, you definitely run this two targets:
Maven Clean
Maven Install

After running "Maven Install", maven tool will compile your project and generate a WAR file under the target folder in your package structure. To deploy this WAR file, you need to manually copy-paste this WAR in tomcat/ webapps folder.

But It seems very tedious task to build WAR file, do copy-paste....

So here are some settings that you need to do in your pom.xml file to make it automated.

1. Do right click on your pom.xml in Eclipse, and select option for "add plugin".(DO NOT SELECT "Add Dependency" )
2. add plugin with artifact id: tomcat7-maven-plugin
3. add plugin with artiface id: maven-war-plugin
4. now, add following configuration for artifact id: maven-war-plugin

<warName>MyApplication</warName>
<outputDirectory>../../apache-tomcat-7.0.32/webapps</outputDirectory>


5. in step4, the <outputDirectory> is the path to your webapps folder of your tomcat. Path is with respect to your pom.xml file.
6. Run Maven Clean.
7. Run Maven Install.

Your war will be hot deployed on the running tomcat.
To test hot deployment, do some changes in your JSP files and run Maven Clean and Install again. The war will be reloaded.

Here is the entry of my pom.xml file:

        <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration></configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>MyApplication</warName>
<outputDirectory>../../apache-tomcat-7.0.32/webapps</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

That's it..!!!
Enjoy...!!!
Happy Coding...!!!