Recently I was posed with a challenge of coming up with a solution to a seemingly simple problem “I want to use Eclipse to create by web mapping project and then deploy the solution directly into my Tomcat instance”
Sounds simple right, I started exploring ways to coming up with a solution. Eclipse allows us to run the application and then export the application to a standard WAR file. But then someone has to manually do the following steps :
- Export the project to a WAR file using Eclipse Interface
- Copy the WAR file from the location created to the Tomcat webapps folder
Here is a better alternative and a solution to the question :
Create an ANT script that will look at the Eclipse Project structure and build the WAR file and copy over the WAR file to the destination (Tomcat WebApps folder)
Here is the ANT script:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Deploy From Eclipse to Tomcat" basedir=".">
<property name="warfile" value="sanfran"/>
<target name="unpack">
<unwar src="${warfile}.war" dest="${warfile}" />
</target>
<target name="create">
<war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
<classes dir="build\classes"/>
<fileset dir="WebContent">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="copy">
<copy todir="c:\tomcat5517\webapps" overwrite="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="deploy">
<antcall target="create"/>
<antcall target="copy"/>
</target>
</project>
Save the above code into a file and name it “build.xml”. Place the build.xml into the root folder of your eclipse project. For example, if “c:\projects” is my eclipse workspace and “SanFrancisco” is the name of my project then all the files related to the project will be under “c:\projects\SanFrancisco”.
You can run the ant command inside the projects root folder either using any ANT tool installed or if you have ArcGIS Java ADF installed then there is a customized ANT tool executable available for use.
Here is the usage:
1. Create the WAR file and deploy it to tomcat
"c:\program files\arcgis\java\tools\ant\build\arcgisant" deploy
2. Just create the WAR file
"c:\program files\arcgis\java\tools\ant\build\arcgisant" create
3. Just copy over the WAR file to deploy location
"c:\program files\arcgis\java\tools\ant\build\arcgisant" copy
4. Unpack the WAR file to see the contents
"c:\program files\arcgis\java\tools\ant\build\arcgisant" unpack



April 25, 2008 at 12:59 am
Uh, nice, just what I need… Thanks
May 6, 2009 at 10:46 pm
Thank you dude it really works fine
sravan
September 19, 2008 at 1:46 am
Perfect! Thanks for this.
December 10, 2008 at 10:14 pm
Thanks. I used it to deploy to JBOSS
December 17, 2008 at 11:03 pm
Thanks…that’s what i need
January 15, 2009 at 8:23 am
Thank you very much for sharing!
January 21, 2009 at 9:50 pm
Thanks it was really useful for me
January 30, 2009 at 6:15 am
Nice! It was very helpful. Thank You!
February 8, 2009 at 12:16 pm
thanks so much friend ^^
March 19, 2009 at 4:35 am
I was stuck with a war deploy, and this solve my problem…thank you!
April 10, 2009 at 4:24 am
[...] Sathya’s blog post here: http://arkblog.wordpress.com/2008/01/08/creating-a-deployable-war-file-from-eclipse-project/ [...]
June 23, 2009 at 6:03 am
[...] [...]
July 7, 2009 at 12:24 am
Thank you
August 31, 2009 at 11:48 pm
man! luv dis script…ws luking for dis for so long. Its workin grt :)
Thanks,
Mukesh
September 1, 2009 at 11:42 pm
Thank you dude, it really helped me at the right moment!
September 14, 2009 at 11:16 am
I hate ant, but I love simple solutions. Many thanks!
October 5, 2009 at 4:34 am
Can you please tell me how to deploy a web application(WAR) in tomcat using ant with eclipse ide?
October 5, 2009 at 4:36 am
How can we deploy a web application(WAR file) in tomcat , using ant with ,eclipse IDE?
November 11, 2009 at 9:06 pm
Thank you dude, it really helped me at the right moment! for deploying my application
SMS
Thanks a lot