I have used Jboss and deployment happens by dropping war to deploy folder. But when I set my war project to Tomcat server eclipse claims that it is deploying war, but I cannot see my war in webapps folder. And what url is to my war? In jboss I can add app url to jboss-web.xml, so when I set app path to jboss-web.xml I can find my app from http://localhost:8080/my_app_path_in_jboss_web.xml/.
I deploy WARs to the webapps dir all the time without issue, probably ~25 times a day. You shouldn't have any problems with that. If you want more control by all means deploy the directory yourself, but this will most likely require a restart.
Using ant simplifies the task. Here is an an ant build.xml file I use to deploy to tomcat 6. (note, I wasn't the origial author of this, but I forget where I got it from)
<project name="provisioning" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="provisioning"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}"/>
</target>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
If I understand correctly, you have configured eclipse to use Tomcat by adding a new Server. In that case eclipse deploys the war file in folder inside your workspace, NOT at $TOMCAT_HOME/webapps. I can't remember the path in eclipse's workspace folder from the top of my head - it should be something that contains tmp, server, ...
You have added Tomcat server in eclipse, eclipse runs the WAR file within your workspace. Eclipse does not use your %TOMCAT_HOME%. To be able to see your WAR in the webapps folder simply drop it in there. You will then be albe to run the war from localhost.
Related
i built an ear using ant and the its compiling fine. however when i deploy i get the noclassdeffound error in the weblogic server logs. so i added the libraries(jars) in server startup script i.e the server java classpath it works fine.
Please help me how to resolve this runtime classpath issue using ant build. i assume adding classpath in manifest.mf file will help. so far my build.xml is:
Please advice
<?xml version="1.0"?>
<project name="xxx APP Check" default="all" basedir=".">
<target name="init">
<property name="software.version" value="1.0"/>
<property name="user.name" value="usrnme"/>
<property name="dirs.base" value="${basedir}"/>
<property name="classdir" value="${dirs.base}/build/src"/>
<property name="src" value="${dirs.base}/src"/>
<property name="mf" value="${dirs.base}/src/META-INF"/>
<property name="jar" value="${dirs.base}/build/jar"/>
<property name="web" value="${dirs.base}/web"/>
<property name="deploymentdescription" value="${dirs.base}/build/deploymentdescriptors"/>
<property name="warFile" value="xxxappchk.war"/>
<property name="earFile" value="xxxxappchk.ear"/>
<property name="earDir" value="${dirs.base}/build/ear"/>
<property name="warDir" value="${dirs.base}/build/war"/>
<property name="srcDir" value="${dirs.base}/build/src"/>
<!-- Create Web-inf and classes directories -->
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/lib"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
<!-- Create Meta-inf and classes directories -->
<mkdir dir="${warDir}/META-INF"/>
<mkdir dir="${earDir}/META-INF"/>
</target>
<!-- Main target -->
<target name="all" depends="init,build,buildWar,buildEar,clean"/>
<!-- Compile Java Files and store in /build/src directory -->
<target name="build" >
<path id="3rdparty.jar.path">
<fileset dir="${jar}">
<include name="*.jar" />
</fileset>
</path>
<javac srcdir="${src}" includeantruntime="false" destdir="${classdir}" debug="true" includes="**/*.java" >
<classpath>
<path refid="3rdparty.jar.path"/>
</classpath>
</javac>
</target>
<!-- Create the War File -->
<target name="buildWar" depends="init">
<copy todir="${warDir}/WEB-INF/classes">
<fileset dir="${classdir}" includes="**/*.class" />
</copy>
<jar destfile="${warDir}/WEB-INF/lib/xxxx-appcheck.jar"
basedir="${warDir}/WEB-INF/classes"
/>
<echo message="Hyperion appcheck jar created."/>
<copy todir="${warDir}/WEB-INF/classes/com/ca/xxxx_appcheck">
<fileset dir="${src}" includes="**/*.java" />
</copy>
<copy todir="${warDir}/WEB-INF">
<fileset dir="${deploymentdescription}" includes="web.xml" />
</copy>
<copy todir="${warDir}/WEB-INF/lib">
<fileset dir="${jar}" includes="*.jar" />
</copy>
<copy todir="${warDir}">
<fileset dir="${web}" includes="**/*.*" />
</copy>
<!-- Create war file and place in ear directory -->
<jar jarfile="${earDir}/${warFile}" basedir="${warDir}" />
</target>
<!-- Create the War File -->
<target name="buildEar" depends="init">
<copy todir="${earDir}/META-INF">
<fileset dir="${deploymentdescription}" includes="application.xml" />
</copy>
<!-- Create ear file and place in ear directory -->
<jar jarfile="${dirs.base}/${earFile}" basedir="${earDir}" />
</target>
<target name="clean" description="Delete all generated files">
<delete dir="${srcDir}" failonerror="false"/>
<delete dir="${earDir}" failonerror="false"/>
<delete dir="${warDir}" failonerror="false"/>
<echo message="Deleted the temp directories src, war, ear"/>
<mkdir dir="${earDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${srcDir}"/>
<echo message="created the temp directories src, war, ear"/>
</target>
</project>
Usually you don't need to add anything to MANIFEST.MF to make your jars added to application classpath.
Your web application (WAR) files should be directly under EAR.
Overall dependencies (JAR) should be under EAR's APP-INF/lib directory.
Web application own dependencies under WAR files WEB-INF/lib directory. Looking at your build.xml, they should be there.
Before changing you Ant build script, please check these prerequisites and please provide the stacktrace from Weblogic error log.
I have a war file and a Tomcat server. I'd like to put the war file into the Tomcat server using AntInstaller and I want the server subsequently restarted.
Is it possible? Can anybody help me to do this?
You need to create user in tomcat-users.xml
<?xml version="1.0"?>
<tomcat-users>
<role rolename="dbadmin"/>
<role rolename="manager"/>
<user username="BruceP" password="bwperry" roles="dbadmin,manager"/>
<user username="JillH" password="jhayward" roles="manager"/>
</tomcat-users>
Create the build.properties file
appserver.home=c:\\apache-tomcat-7.0.19
appserver.lib=${appserver.home}/lib
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://www.localhost.com:8080/manager
tomcat.manager.username=username
tomcat.manager.password=secret
Create the build.xml file
<?xml version="1.0"?>
<project name="fax" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="javadoc.dir" value="doc"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="fax"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="javadoc">
<javadoc packagenames="faxapp.*" sourcepath="${src.dir}"
destdir="doc" version="true" windowtitle="Fax Application">
<doctitle><![CDATA[<h1>= Fax Application
=</h1>]]></doctitle>
<bottom><![CDATA[Copyright © 2011. All
Rights Reserved.]]></bottom>
<group title="util packages" packages="faxapp.util.*"/>
<group title="web packages" packages="faxapp.web.*"/>
<group title="data packages"
packages="faxapp.entity.*:faxapp.dao.*"/>
</javadoc>
</target>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="deploy --> Deploy application
as directory"/>
<echo message="deploywar --> Deploy application
as a WAR file"/>
<echo message=""/>
</target>
<target name="build" description="Compile main
source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5"
target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build"
description="Deploy application">
<copy todir="${deploy.path}/${name}"
preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build"
description="Deploy application as a WAR file">
<war destfile="${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<!-- ============================================================ -->
<!-- Tomcat tasks -->
<!-- ============================================================ -->
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
</fileset>
</path>
<taskdef name="install"
classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload"
classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list"
classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start"
classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop"
classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
Ant tasks
InstallTask --Installs a web application. Class Name: org.apache.catalina.ant.InstallTask
ReloadTask -- Reload a web application. Class Name: org.apache.catalina.ant.ReloadTask
ListTask -- Lists all web applications. Class Name: org.apache.catalina.ant.ListTask
StartTask -- Starts a web application. Class Name: org.apache.catalina.ant.StartTask
StopTask -- Stops a web application. Class Name: org.apache.catalina.ant.StopTask
I am trying to use ant + ivy together.
This is what I have done so far. I have just the ant file build.xml, which I edited, to download ivy jar file.
<?xml version="1.0"?>
<project name="spring" basedir="." default="usage" xmlns:ivy="antlib:org.apache.ivy.ant" >
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="ivy"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true" includeantruntime="false">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="${name}.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->
<path id="catalina-ant-classpath">
<!-- We need the Catalina jars for Tomcat -->
<!-- * for other app servers - check the docs -->
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}"/>
</target>
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
<!-- End Tomcat tasks -->
<!-- Ivy settings start-->
<target name="-download-ivy" unless="skip.download">
<!-- download Ivy from web site so that it can be used even without any special installation -->
<echo message="installing ivy..."/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<!-- Ivy settings end-->
</project>
This is my build.properties:
# Ant properties for building the springapp
appserver.home=C:/apache-tomcat-7.0.20
# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib
appserver.lib=C:/apache-tomcat-7.0.20/lib
deploy.path=C:/apache-tomcat-7.0.20/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=tomcat
tomcat.manager.password=s3cret
ivy.install.version=2.2.0
ivy.jar.file=${lib.build.dir}/ivy-${ivy.install.version}.jar
When I try to deploy my war file and -download-ivy with ant, I get following error in eclipse:
Buildfile: C:\Users\Jansu\workspace\HelloWorld\build.xml
build:
deploywar:
-download-ivy:
[echo] installing ivy...
[get] Getting: http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
[get] To: C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar
[get] Error getting http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar to C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar
BUILD FAILED
C:\Users\Jansu\workspace\HelloWorld\build.xml:153: java.io.FileNotFoundException: C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar (The system cannot find the path specified)
Total time: 1 second
What could be the problem? The address http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar exists, I could download from there manually.
According to the log, the problem is that lib.build.dir definition is missing in your build.properties file. So in order to fix this problem, you should :
add the definition of lib.build.dir in your build.properties,
create this dir at the beginning of the -download-ivy target (<mkdir dir="${lib.build.dir}" />).
Buildfile: /.../build.xml
build:
buildtests:
tests:
BUILD FAILED
/.../build.xml:43: Problem: failed to create task or type junit
Cause: Could not load a dependent class org/apache/tools/ant/Task
It is not enough to have Ant's optional JARs
you need the JAR files that the optional tasks depend upon.
Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
-/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib
-/Users/cjwalsh/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
Total time: 512 milliseconds
... and I've checked all the recommended directories, and yet I still keep getting this build failure. The specific JAR 'ant.jar', which I've looked into, has the class 'Task', and it is in the '/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib' directory. Do I need to manually add this classpath to my build.xml as well? Here is my build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="springapp" basedir="." default="build">
<property file="build.properties"></property>
<property name="src.dir" value="src"></property>
<property name="web.dir" value="war"></property>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"></property>
<property name="name" value="springapp"></property>
<property name="test.dir" value="test"></property>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"></include>
</fileset>
<pathelement path="${build.dir}"></pathelement>
</path>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false"
failonerror="true">
<src path="${src.dir}" />
<classpath refid="master-classpath" />
</javac>
</target>
<target name="buildtests" description="Compile test tree java files">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${test.dir}"></src>
<classpath refid="master-classpath"></classpath>
</javac>
</target>
<target name="tests" depends="build, buildtests" description="Run tests">
<junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath"></classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${build.dir}">
<include name="**/*Tests.*" />
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
tests.failed=${tests.failed}
***********************************************************************
***********************************************************************
**** One or more tests failed! Check the output ... ***************
***********************************************************************
***********************************************************************
</fail>
</target>
<target name="deploy" depends="build" description="Deploy the application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*" />
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as WAR file">
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"></include>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"></include>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"></include>
</fileset>
</path>
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath" />
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="catalina-ant-classpath"></classpath>
</taskdef>
<target name="install" description="Install application in Tomcat">
<install url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"
war="${name}" />
</target>
<target name="reload" description="Reload applicatio in Tomcat">
<reload url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="start" description="Start tomcat application">
<start url="${tomcat.manager.url}" username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}" />
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}" />
</target>
</project>
Are you starting ant from within Eclipse?
Please check in the menu {Run | External Tools Configuration...} that the Classpath tab contains "Ant Home". After expanding, does it point to valid files?
Hey guys I've been trying all day to get an ant file to automatically build my project. The file (appended below) was on a web page I found and is pretty thorough.
My problem is that it works as long as I don't run the "clean" target. Once the I run the "clean" target the "test" target ceases to work. I get NoClassFound errors on all test classes. Even though it worked earlier.
I'm working on a Macbook (10.5.8) using the latest version of eclipse. This error occurs running the file from eclipse and from a terminal using Ant version 1.7.1
I modified the file slightly to adapt it to my file structure which is as follows:
src/
packageA.packageB/
ClassA.java
...
ClassN.java
unittests/
packageA.packageB/
AllClassTests.java
ClassATest.java
...
ClassNTest.java
lib/
junit-4.7.jar
The ant file is:
<project name="SampleJUnitTests" default="dist" basedir=".">
<description>
DataTypes Build File
</description>
<!-- set global properties for this build -->
<property name="project_name" value="DataTypes"/>
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>
<property name="lib" location="lib"/>
<property name="reports" location="reports"/>
<property name="tests" location="unittests"/>
<property name="tmp" location="tmp_file"/>
<!-- the names of various distributable files -->
<property name="jar_name" value="${project_name}.jar"/>
<property name="war_name" value="${project_name}.war"/>
<!-- top level targets -->
<target name="compile" depends="init" description="compile the source code " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distributable files " >
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jar_name}" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
<delete dir="${tmp}"/>
</target>
<target name="run-tests" depends="compile" description="run your test suite" >
<junit printsummary="yes" haltonfailure="no" showoutput="yes" tempdir="${tmp}">
<classpath>
<pathelement path="${build}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="${tests}">
<include name="**/*.java"/>
<exclude name="**/All*Tests.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name ="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>
<target name ="run" depends="" description="if this project can be run, run it" >
</target>
<!-- supporting targets -->
<target name="init" description="initialize the build environment" >
<!-- Create the time stamp -->
<tstamp/>
<!-- Create directory structures -->
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
<mkdir dir="${tmp}"/>
</target>
<target name="all" depends="clean, test">
</target>
I give up and hope that someone can shine a light on my problem.
Thanks a lot!
You haven't got any Ant target which builds the test classes. You could do this as part of the compile target if you wanted:
<target name="compile" depends="init" description="compile the source code " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
<javac srcdir="${tests}" destdir="${build}">
<classpath>
<pathelement path="${build}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>