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
June 22, 2011 at 2:37 pm
This saved me a complete day of code dissection in a creepy office! Thanks.
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
June 12, 2011 at 10:53 am
Hi Krishnaroopa.. I have to do the same thing. ie., deploying to JBoss. I am new to Eclipse and JBoss. Can u please help me? Thanks in advance.
Email me: sudheer.univ@gmail.com
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
November 26, 2009 at 6:06 pm
Hey thanks for this man
December 3, 2009 at 1:35 am
Thank you soo much.I was looking for the same!
December 16, 2009 at 4:24 pm
Great post, worked like a charm
January 7, 2010 at 3:27 pm
I have to agree with everyone else this is a killer ant file. As simple as can be and works PERFECTLY. Thanks
February 26, 2010 at 12:53 pm
Hi, good documentation.
I develop a web application using tomcat 5, spring mvc 2.5, eclipse 3.3.
I have difficulty to deploy jar file from my local machine to remote tomcat server. I set up all info well. But when i deploy in build.xml on my local machine, this error
–
/var/lib/tomcat5/webapps/vm_admin/build.xml:90: java.net.NoRouteToHostException: No route to host
–
could you help me out?
March 3, 2010 at 11:07 am
Awesome. Always love an automated solution, and this worked great for me.
March 22, 2010 at 4:01 am
Cool!! :-) It wrked.
Thanks for sharing
March 29, 2010 at 9:52 pm
I have to agree with everyone else this is a killer ant file
Thank you soo much.I was looking for the same!
March 29, 2010 at 9:56 pm
Great post
Awesome. Always love an automated solution, and this worked great for me.
March 29, 2010 at 9:57 pm
I hate ant, but I love simple solutions
Thanks.
March 29, 2010 at 9:59 pm
How can we deploy a web application(WAR file) in tomcat , using ant with ,eclipse IDE?
March 29, 2010 at 10:00 pm
Thank you dude it really works fine
Thanks
March 31, 2010 at 11:13 am
> How can we deploy a web application(WAR file) in tomcat , using ant with ,eclipse IDE?
1/ Create a build.xml file that contains the stuff of the blog post
2/ in Eclipse, go to Windows/Show View…/
3/ in the Window, Select Ant/Ant
4/ in the Package explorer or Navigator, drag the build.xml file to the Ant view
5/ Be sure “Hide internal targets” is not checked (all the targets from the script are internal since no descriptions are available)
6/ Target “copy” here deploys the WAR in the Tomcat webapps folder; if Tomcat is already running, the WAR will be expanded and available at once, if it is not running, just start it.
April 2, 2010 at 4:12 am
it really helped me
April 2, 2010 at 4:13 am
that’s what i need
April 2, 2010 at 4:14 am
Thanks for this one
April 2, 2010 at 4:20 am
Thank you dude it really works fine
April 21, 2010 at 5:15 am
Thank you bud, It is simple and it works!
here is some minor modification to include reference jars into the war package (root WEB-INF/lib/)
regards..
April 21, 2010 at 5:17 am
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<project name=”Deploy From Eclipse to Tomcat” basedir=”.”>
<property name=”warfile” value=”sanfran”/>
<fileset id=”project.classes” dir=”lib”>
<include name=”javax.servlet-5.1.12.jar” />
<include name=”ojdbc5.jar” />
<include name=”sqljdbc4.jar” />
</fileset>
<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”/>
<lib refid=”project.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>
June 2, 2010 at 10:38 pm
I cant understand this how to create it in my project.please help me.
June 2, 2010 at 10:39 pm
in wat name i should save this xml file
June 2, 2010 at 10:43 pm
i have created one project in eclipse .i have to deploy a war file in to my project to run my jsp pages,the informaton given above its not sufficient can u guide me step by step.
June 2, 2010 at 10:44 pm
where should i add this files
July 15, 2010 at 4:11 am
thx a lot
works immediately
July 27, 2010 at 1:35 pm
Hey, thanks a lot. This solution give more free time to enjoy with many other problems and not with the fkn ant
:)
August 23, 2010 at 5:53 am
Thanks a lot for sharing this! a very helpful working sample.
October 14, 2010 at 10:40 pm
Perfect document, perfect build file. Its actually getting for me to deploy on tomcat externally. This document helped alot.
Thanks
October 27, 2010 at 9:40 am
That’s fantastic tool man. When u execute using ant, go to the root folder and then type >ant create.
Once again thanks a lot.
November 9, 2010 at 10:07 am
Yeah! this is a really awesome tool. Here’s a step-by-step method:
1. Rt. click your project name
2. Select New > File (call it Build.xml)
3. Copy and paste above text (xml posted by sathyaprasad)
4. Edit following lines to reflect your setup:
a.
b. Sometimes, adding full paths to “web.xml”, “todir” etc. helps
5. Right click “build.xml” > Run As > Ant Build
6. You should see something like the following if successful.
Buildfile: C:\workspace\MyWar\build.xml
deploy:
create:
unpack:
[unwar] Expanding: C:\workspace\MyWar\MyWar.war into C:\Tomcat 4.1\webapps\MyWar
BUILD SUCCESSFUL
Total time: 1 second
I removed the step to “copy” because I unpacked directly into the web folder. Hope this helps!
November 9, 2010 at 10:10 am
Not sure why 4(a) got erased…following was the line to edit:
4(a)
November 9, 2010 at 10:11 am
Looks like the webpage is trying to parse the line…here it is again…final try…
December 2, 2010 at 12:08 am
Lot of thanks,its simple and it works fine…..great:)
December 15, 2010 at 9:13 pm
Hi, this article is really very useful.
But, how to make a war file in eclipse using bea weblogic server?
September 28, 2011 at 2:05 am
excellent many thanks