You'll probably have to know a little bit about Java, Ant, and build files for this sample build.xml file to be any use to you, but if you're looking for a sample Ant build script that can be used to create a war file, or one that simple uses a war task, this example might work for you. I'm not going to provide any. ANT Tutorial 05 - war, deploy, and start/stop tomcat from ANT Script. 03:40 What is the root tag of an ant build file? 05:00 How to point to the directory where the build file is in an ant.
<?xml version='1.0' encoding='UTF-8'?> |
<projectbasedir='.'default='package'name='PROJECT_NAME'> |
<!-- |
This script assumes: |
1) CATALINA_HOME environment variable points to tomcat's directory |
2) Following Folder Structure |
./ (project root) |
- src/ (project.src.dir - source folder) |
- build/ |
- classes/ (project.classes.dir) |
- WebContent/ (project.web.dir) |
- lib/ (project.lib.dir) |
- PROJECT_NAME.war (project.war) |
3) JAVA_HOME is set and point to JDK 1.6 and above |
--> |
<propertyenvironment='env' /> |
<propertyname='TOMCAT_HOME'value='${env.CATALINA_HOME}' /> |
<propertyname='debuglevel'value='source,lines,vars' /> |
<propertyname='target'value='1.6' /> |
<propertyname='source'value='1.6' /> |
<propertyname='project.name'value='${ant.project.name}' /> |
<propertyname='project.web.dir'value='WebContent' /> |
<propertyname='project.src.dir'value='src' /> |
<propertyname='project.classes.dir'value='build/classes' /> |
<propertyname='project.lib.dir'value='${project.web.dir}/WEB-INF/lib' /> |
<propertyname='project.war'value='${project.name}.war' /> |
<propertyname='project.runtime.lib'value='${TOMCAT_HOME}/lib' /> |
<propertyname='project.deploy.location'value='${TOMCAT_HOME}/webapps' /> |
<pathid='classpath.runtime'> |
<filesetdir='${project.runtime.lib}'includes='*.jar' /> |
</path> |
<pathid='classpath.lib'> |
<filesetdir='${project.lib.dir}'includes='*.jar' /> |
</path> |
<pathid='project.classpath'> |
<pathelementlocation='${project.classes.dir}' /> |
<pathrefid='classpath.runtime' /> |
<pathrefid='classoath.lib' /> |
</path> |
<targetname='init'> |
<mkdirdir='${project.classes.dir}' /> |
<copyincludeemptydirs='false'todir='${project.classes.dir}'> |
<filesetdir='src'> |
<excludename='**/*.java' /> |
</fileset> |
</copy> |
</target> |
<targetname='clean'> |
<deletedir='${project.classes.dir}' /> |
<deletedir='${project.war}' /> |
</target> |
<targetdepends='init'name='build'description='Compiling all java files in ${project.src.dir}'> |
<echomessage='${project.name}: ${ant.file}' /> |
<javacdebug='true'debuglevel='${debuglevel}'destdir='${project.classes.dir}'includeantruntime='false'source='${source}'target='${target}'> |
<srcpath='src' /> |
<classpathrefid='project.classpath' /> |
</javac> |
</target> |
<targetdepends='build'name='package'description='Packagign all files into ${project.war}'> |
<wardestfile='${project.war}'index='true'needxmlfile='fasle'> |
<classesdir='${project.classes.dir}' /> |
<libdir='${project.lib.dir}' /> |
<filesetdir='${project.web.dir}'> |
<includename='**/*.*' /> |
</fileset> |
</war> |
</target> |
<targetdepends='package'name='deploy'description='Copying ${project.war} to ${project.deploy.location}'> |
<copyfile='${project.war}'todir='${project.deploy.location}' /> |
</target> |
</project> |
There is a typo in line 44 |
I have created sample/default test Web project in eclipse.
Then I am using Ant to build and deploy. I export default build.xml. but this ant doesn't have task to create war file. So, I have to write task for creating war.
I used below code.
When I copy and paste the generated war in webapps. After starting Tomcat server, I found that this war is corrupt. War file is just 1KB file that contains web.xml and manifest.mf.
I would like to know:
I read SO answer answer1 and answer2 , but couldn't help in my project.
Your WAR file doesn't look right to me.