You can use Ant to configure, compile, WAR , and deploy your solution.
<target name="default" depends="setup,compile,buildwar,deploy"></target>
You can then do one click in Eclipse to launch this Ant target. The following are examples of each step:
Background
Suppose your code is organized like this:
${basedir}/src : Java files, properties, XML configuration files${basedir}/web : your JSP files${basedir}/web/lib : any JAR files needed at runtime${basedir}/web/META-INF : your manifest${basedir}/web/WEB-INF : your web.xml files
Customization
Define a setup task that creates a distribution directory and copies any artifacts that should be WARNING directly:
<target name="setup"> <mkdir dir="dist" /> <echo>Copying web into dist</echo> <copydir dest="dist/web" src="web" /> <copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" /> </target>
Compile
Create your Java files in classes and copy any artifacts other than Java that are in src but should be available at runtime (e.g. properties, XML files, etc.):
<target name="compile"> <delete dir="${dist.dir}/web/WEB-INF/classes" /> <mkdir dir="${dist.dir}/web/WEB-INF/classes" /> <javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src"> <classpath> <fileset dir="${basedir}/../web/WEB-INF/lib"> <include name="*" /> </fileset> </classpath> </javac> <copy todir="${dist.dir}/web/WEB-INF/classes"> <fileset dir="src"> <include name="**/*.properties" /> <include name="**/*.xml" /> </fileset> </copy> </target>
Build WAR
Create your own WAR:
<target name="buildwar"> <war basedir="${basedir}/dist/web" destfile="My.war" webxml="${basedir}/dist/web/WEB-INF/web.xml"> <exclude name="WEB-INF/**" /> <webinf dir="${basedir}/dist/web/WEB-INF/"> <include name="**/*.jar" /> </webinf> </war> </target>
Deploy
Finally, you can configure the task to deploy the WAR directly at the Tomcat deployment location:
<target name="deploy"> <copy file="My.war" todir="${tomcat.deploydir}" /> </target>
Click and go!
Once all this is set up, just starting the default target from Eclipse will compile, WAR and deploy your solution.
The advantage of this approach is that it will work outside of Eclipse, as well as in Eclipse and can be used to easily share a deployment strategy (for example, using source control) with other developers who are also working on your project.