Using Ant condition tag - java

I want to do something like this
<target name="init" description="Create build directories.
>
<mkdir dir="bin" />
<mkdir dir="dist" />
<!-- Check for the presence of dependent JARs -->
<condition property="dependent.files.available">
<and>
<available file="../../xx.jar" />
<available file="../../yy.jar" />
</and>
</condition>
</target>
<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources
and create classes">
<if>
<isset property="dependent.files.available"/>
<then>
<javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>
</then>
<else>
<echo message="Either xx.jar or yy.jar not found"/>
</else>
</if>
</target>
When I tried to compile the code it gave me the following error
Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place
It it the correct way of doing it?

You need to have the ant-contrib jar visible at runtime, or configure it correctly as described in the link.
The thing boils down to have Ant load the task definition, so if you put ant-contrib in ant/lib, you just need
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

Just a suggestion. You can do the same thing with ant 1.9.1 onwards using if/unless without ant-contrib (http://ant.apache.org/manual/targets.html)
Your targets would be
<target name="init" description="Create build directories.
>
<mkdir dir="bin" />
<mkdir dir="dist" />
<!-- Check for the presence of dependent JARs -->
<condition property="dependent.files.available">
<and>
<available file="../../xx.jar" />
<available file="../../yy.jar" />
</and>
</condition>
</target>
<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources
and create classes" if="dependent.files.available">
<javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>
</target>

Related

Ant - javac task - classpath is not taking the jars

I have my ant build.xml file like this:
<!-- Properties -->
<property name="src" value="${basedir}" />
<property name="jars" value="${src}/jars" />
<property name="dest" value="${src}/dest" />
<property name="reports" value="${src}/reports" />
<path id="claspath">
<fileset dir="${jars}">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<echo> removing the directories "dest" and "reports" </echo>
<delete dir="${dest}" />
<delete dir="${reports}" />
</target>
<target name="makedir" depends="clean">
<echo> creating directories "dest" and "reports" </echo>
<mkdir dir="dest" />
<mkdir dir="reports" />
</target>
<target name="complie" depends="makedir">
<javac srcdir="${src}" destdir="${dest}" />
<classpath refid="classpath"/>
</target>
When I type ant command in cmd prompt the compiling happens but the jar files are not loading so I am getting compiling errors. The jar folder that i have mentioned in the above code has only one jar file which is "testng-6.8.5.jar". Please let me know what is wrong in the above code.
You're closing the <javac> tag on the same line, it should be:
<javac srcdir="${src}" destdir="${dest}">
<classpath refid="classpath"/>
</javac>

how to replicate "ant run" to execute a Glassfish ACC client with appclient

How do I run the appclient outside of the IDE? While it seems possible to run stand-alone JNDI lookup apps from the CLI with appclient, it doesn't appear to work for ACC clients. However, it should be possible:
Running an Application Client
Using the appclient Script To run an application client,
you can launch the ACC using the appclient script,
whether or not Java Web Start is enabled.
GlassFish Server Open Source Edition
Application Development Guide
Release 4.0
Developing Java Clients 10-15
page 186
Steps:
1.) created an #Remote interface as a Java SE library API
2.) created an Enterprise Application with an ejb module; add the interface API
3.) in the ejb module, implement the #Remote interface
4.) create an ACC app; add the interface API; add to the Enterprise Application
5.) insert the ejb from the IDE
6.) deploy the EAR and then run the ACC client from the IDE
This is adapted from Creating and Running an Application Client on the GlassFish Server.
running with ant, "ant run" from the CLI:
-run:
[java] 2
run:
BUILD SUCCESSFUL
Total time: 28 seconds
thufir#dur:~/NetBeansProjects/SingletonACC$
which is the correct output, in this case. (Each time the client runs, the integer increases by one.)
I've looked through the ant files, but wasn't able to decipher what "ant run" does in this case:
<!--
=================
EXECUTION SECTION
=================
-->
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-pregfv3,-run" description="Run a main class." name="run"/>
<target if="j2ee.appclient.tool.args" name="-run-pregfv3">
<carproject:run-appclient-pregfv3/>
</target>
<target name="-run" unless="j2ee.appclient.tool.args">
<carproject:run-appclient/>
</target>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-single-pregfv3,-run-single" description="Run a single class." name="run-single"/>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" name="-run-single" unless="j2ee.appclient.tool.args">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:run-appclient serverparams="${j2ee.appclient.tool.jvmoptions.class}${run.class}"/>
</target>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" if="j2ee.appclient.tool.args" name="-run-single-pregfv3">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:run-appclient-pregfv3/>
</target>
<target depends="init" name="-init-run-macros">
<macrodef name="run-appclient" uri="http://www.netbeans.org/ns/car-project/1">
<attribute default="${application.args.param}" name="args"/>
<attribute default="${j2ee.appclient.tool.jvmoptions}${client.jar}" name="serverparams"/>
<element name="customize" optional="true"/>
<sequential>
<java dir="${basedir}" fork="true" jar="${client.jar}">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="#{serverparams}"/>
<jvmarg line="${run.jvmargs.param}"/>
<arg line="#{args}"/>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<env key="APPCPATH" path="${javac.classpath}"/>
<sysproperty key="java.system.class.loader" value="org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"/>
<customize/>
</java>
</sequential>
</macrodef>
<macrodef name="run-appclient-pregfv3" uri="http://www.netbeans.org/ns/car-project/1">
<element name="customize" optional="true"/>
<sequential>
<java classname="${j2ee.appclient.tool.mainclass}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="${j2ee.appclient.tool.jvmoptions}"/>
<jvmarg line="${run.jvmargs.param}"/>
<arg line="${j2ee.appclient.tool.args}"/>
<arg line="-client ${client.jar}"/>
<arg line="${application.args.param}"/>
<classpath>
<path path="${j2ee.platform.classpath}:${j2ee.appclient.tool.runtime}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
<target if="j2ee.appclient.mainclass.args" name="-as-retrieve-option-workaround" unless="j2ee.clientName">
<property name="client.jar" value="${dist.dir}/SingletonACCClient.jar"/>
<sleep seconds="3"/>
<copy failonerror="false" file="${wa.copy.client.jar.from}/SingletonACC/SingletonACCClient.jar" todir="${dist.dir}"/>
<copy failonerror="false" flatten="true" todir="${dist.dir}/">
<fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/SingletonACCClient.jar"/>
</copy>
<copy flatten="true" todir="${dist.dir}/SingletonACCClient">
<fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/*.*ar"/>
</copy>
<copy failonerror="false" flatten="false" todir="${dist.dir}/SingletonACCClient">
<fileset dir="${dist.dir}/gfdeploy/SingletonACC" includes="**/*.jar"/>
</copy>
</target>
<target name="pre-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="post-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="-pre-nbmodule-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- This target can be overriden by NetBeans modules. Don't override it directly, use -pre-run-deploy task instead. -->
</target>
<target name="-post-nbmodule-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- This target can be overriden by NetBeans modules. Don't override it directly, use -post-run-deploy task instead. -->
</target>
<target name="-run-deploy-am">
<!-- Task to deploy to the Access Manager runtime. -->
</target>
<target depends="init,compile,dist,pre-run-deploy,-pre-nbmodule-run-deploy,-run-deploy-nb,-init-deploy-ant,-deploy-ant,-run-deploy-am,-post-nbmodule-run-deploy,post-run-deploy,-do-update-breakpoints" name="run-deploy"/>
<target if="netbeans.home" name="-run-deploy-nb">
<nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
</target>
<target name="-init-deploy-ant" unless="netbeans.home">
<property name="deploy.ant.archive" value="${dist.jar}"/>
<property name="deploy.ant.resource.dir" value="${resource.dir}"/>
<property name="deploy.ant.enabled" value="true"/>
</target>
<target depends="init,-run-undeploy-nb,-init-deploy-ant,-undeploy-ant" name="run-undeploy"/>
<target if="netbeans.home" name="-run-undeploy-nb">
<fail message="Undeploy is not supported from within the IDE"/>
</target>
<target depends="run-deploy,-init-display-browser,-display-browser-nb,-display-browser-cl" name="run-display-browser"/>
<target if="do.display.browser" name="-init-display-browser">
<condition property="do.display.browser.nb">
<isset property="netbeans.home"/>
</condition>
<condition property="do.display.browser.cl">
<and>
<isset property="deploy.ant.enabled"/>
<isset property="deploy.ant.client.url"/>
</and>
</condition>
</target>
<target if="do.display.browser.nb" name="-display-browser-nb">
<nbbrowse url="${client.url}"/>
</target>
<target if="do.display.browser.cl" name="-get-browser" unless="browser">
<condition property="browser" value="rundll32">
<os family="windows"/>
</condition>
<condition else="" property="browser.args" value="url.dll,FileProtocolHandler">
<os family="windows"/>
</condition>
<condition property="browser" value="/usr/bin/open">
<os family="mac"/>
</condition>
<property environment="env"/>
<condition property="browser" value="${env.BROWSER}">
<isset property="env.BROWSER"/>
</condition>
<condition property="browser" value="/usr/bin/firefox">
<available file="/usr/bin/firefox"/>
</condition>
<condition property="browser" value="/usr/local/firefox/firefox">
<available file="/usr/local/firefox/firefox"/>
</condition>
<condition property="browser" value="/usr/bin/mozilla">
<available file="/usr/bin/mozilla"/>
</condition>
<condition property="browser" value="/usr/local/mozilla/mozilla">
<available file="/usr/local/mozilla/mozilla"/>
</condition>
<condition property="browser" value="/usr/sfw/lib/firefox/firefox">
<available file="/usr/sfw/lib/firefox/firefox"/>
</condition>
<condition property="browser" value="/opt/csw/bin/firefox">
<available file="/opt/csw/bin/firefox"/>
</condition>
<condition property="browser" value="/usr/sfw/lib/mozilla/mozilla">
<available file="/usr/sfw/lib/mozilla/mozilla"/>
</condition>
<condition property="browser" value="/opt/csw/bin/mozilla">
<available file="/opt/csw/bin/mozilla"/>
</condition>
</target>
<target depends="-get-browser" if="do.display.browser.cl" name="-display-browser-cl">
<fail unless="browser">
Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.
</fail>
<property name="browse.url" value="${deploy.ant.client.url}${client.urlPart}"/>
<echo>Launching ${browse.url}</echo>
<exec executable="${browser}" spawn="true">
<arg line="${browser.args} ${browse.url}"/>
</exec>
</target>
<target depends="dist" name="verify">
<nbverify file="${dist.jar}"/>
</target>
<target depends="init,compile-single" name="run-main">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:java classname="${run.class}"/>
</target>
<target depends="init" if="netbeans.home" name="-do-update-breakpoints">
<carproject:nbjpdaappreloaded/>
</target>
How can I replicate "ant run" outside of the IDE?
note that SingletonAcc is deployed individually, even though it's also part of the SingletonQueue Enterprise Application, which also has an appclient.
thufir#dur:~/NetBeansProjects/SingletonACC$
thufir#dur:~/NetBeansProjects/SingletonACC$ /home/thufir/glassfish-4.1/glassfish/bin/asadmin list-applications
SingletonQueue <ear, appclient, ejb>
SingletonACC <appclient>
Command list-applications executed successfully.
thufir#dur:~/NetBeansProjects/SingletonACC$
You can enable verbose logging in ant so you can see what it is actually executing:
In NetBeans go to Options -> Tools -> Java -> Ant and set the Verbosity Level to Debug.
It looks like ant just deploys the appclient (EntAppClient.jar) on GlassFish and then runs the file EntAppClientClient.jar (notice the double Client) with some parameters similar to this:
/java/jdk1.7.0/jre/bin/java.exe
-Xbootclasspath/p:/NetBeans/enterprise/modules/ext/javaee6-endorsed/javax.annotation.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/jaxb-api-osgi.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/webservices-api-osgi.jar
-Djava.endorsed.dirs=/glassfish410/glassfish/lib/endorsed;/glassfish410/glassfish/modules/endorsed
-javaagent:/glassfish410/glassfish/lib/gf-client.jar=mode=acscript,arg=-configxml,arg=/glassfish410/glassfish/domains/domain1/config/glassfish-acc.xml,client=jar=dist/EntAppClientClient.jar
-Djava.system.class.loader=org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader
-jar /EntAppClient/dist/EntAppClientClient.jar
Hope this helps :)

Why does not ant delete task work?

I have this ant script:
<sequential>
<echo message="Deleting needed folder" />
<property name="bigPathToFolder" value="${basePath}/pathToFolder" />
<delete dir="bigPathToFolder" quiet="false"/>
<echo message="Delete success" />
</sequential>
In console I see Deleting needed folder and after Delete success, but the content of the folder and folder don't change.
What did I do wrong?
replace
<delete dir="bigPathToFolder" quiet="false"/>
to
<delete dir="${bigPathToFolder}" quiet="false"/>
You can use if task available from ant-contrib to do file existance check at path you are looking & run a delete like below:
<if>
<available file="${bigPathToFolder}"/>
<then>
<delete dir="${bigPathToFolder}" quiet="false"/>
<echo message="Delete success" />
</then>
<else>
<echo message="File Not found at path : ${bigPathToFolder}" />
</else>
</if>

problem running JUnit tests with Ant in Eclipse. Beginner question

I'm learning these days how to use ant to run automated test folowing this tutorial.
I have JUnit in the classpath of my project. All seem to work fine and I can include it in my classes:
import junit.framework.TestCase; //line20
public class SimpleLattice1DTest extends TestCase{
...
}
My build.xml is:
<?xml version="1.0"?>
<project name="Ant-Test" default="compile" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="." />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<property name="test.dir" location="jlife/tests" />
<property name="test.report.dir" location="test/report" />
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${test.report.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}">
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\CoreTest.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Test" value="test.CoreTest" />
</manifest>
</jar>
</target>
<!-- Run the JUnit Tests -->
<!-- Output is XML, could also be plain-->
<target name="junit" depends="compile">
<junit printsummary="on" fork="true" haltonfailure="yes">
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${src.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
</project>
When i run it into eclipse I get the following error:
[javac] C:\Documents and
Settings\noname\Documenti\JLife_git\JLife_git\JLife\src\jlife\tests\SimpleLattice1DTest.java:20:
package junit.framework does not exist
[javac] import junit.framework.TestCase;
I suppose there's something wrong with it, but I have no idea. Could someone put me in the right direction?
Your javac target doesn't specify anything apart from the source and target directory - it doesn't add any classpath entries; you'll need to add an entry for the appropriate JUnit jar file. See the javac task documentation for more details. You may want to specify the path to JUnit as a classpath attribute, a nested element, or a reference to a path declared elsewhere.
The eclipse classpath is separate from your ant environment. In your build file, when you call javac you need to supply a classpath attribute.
You can define the classpath at the top of the file with the rest of your properties, like this:
<path id="classpath">
<fileset dir="[path to libraries]" includes="**/*.jar" />
</path>
and then use it in each call to javac by setting the classpathref attribute, like this:
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
You need to specify the directory that contains your .class files and your external jars (like junit).
e.g.
<!-- Populates a class path containing our classes and jars -->
<path id="dist.classpath">
<fileset dir="${lib}"/>
<pathelement path="${build}"/>
</path>
<!-- Compile the java code place into ${build} -->
<target name="compile" depends="-dirty" description="Compile the source.">
<javac srcdir="${source}" destdir="${build}" includeantruntime="false">
<classpath refid="dist.classpath"/>
<exclude name="${test.relative}/**/*"/>
</javac>
</target>
Here's the complete file I took that excerpt from in case you need ideas for how to setup other common things (emma, javadoc, etc)
<project name="imp" default="dist" basedir="..">
<description>Buildscript for IMP</description>
<property name="source" location="src"/>
<property name="lib" location="lib"/>
<property name="history" location="test_history"/>
<property name="web-tests" location="/var/www/tests"/>
<property name="web-files" location="/var/www/files"/>
<property name="web-javadoc" location="/var/www/javadoc"/>
<property name="web-emma" location="/var/www/emma"/>
<property name="emma.dir" value="${lib}"/>
<property name="test" location="${source}/imp/unittest"/>
<property name="test.relative" value="imp/unittest"/>
<property name="javadoc-theme" value="tools/javadoc-theme"/>
<!-- directories for generated files -->
<property name="build" location="build"/>
<property name="build-debug" location="debug"/>
<property name="build-coverage" location="coverage"/>
<property name="dist" location="dist"/>
<property name="reports" location="reports"/>
<property name="coverage-emma" location="${reports}/coverage/emma"/>
<!-- Populates a class path containing our classes and jars -->
<path id="dist.classpath">
<fileset dir="${lib}"/>
<pathelement path="${build}"/>
</path>
<path id="debug.classpath">
<fileset dir="${lib}"/>
<pathelement path="${build-debug}"/>
</path>
<!-- import emma. This classpath limits the coverage to just our classes -->
<path id="debug.imp.classpath">
<pathelement path="${build-debug}"/>
</path>
<taskdef resource="emma_ant.properties" classpathref="debug.classpath"/>
<!--
Shouldn't ever need to use this from the command line. IRC saith that the "private"
internal use only sort of targets are prefixed with '-'.
dirty because it's the opposite of the 'clean' target.
-->
<target name="-dirty">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${build-debug}"/>
<mkdir dir="${build-coverage}"/>
<mkdir dir="${dist}"/>
<mkdir dir="${reports}"/>
<mkdir dir="${coverage-emma}"/>
</target>
<!-- clean up all the generated files and direcories -->
<target name="clean" description="Deletes all files and directories created by this script.">
<delete dir="${build}"/>
<delete dir="${build-debug}"/>
<delete dir="${build-coverage}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
<delete dir="${coverage-emma}"/>
</target>
<!-- Compile the java code place into ${build} -->
<target name="compile" depends="-dirty" description="Compile the source.">
<javac srcdir="${source}" destdir="${build}" includeantruntime="false">
<classpath refid="dist.classpath"/>
<exclude name="${test.relative}/**/*"/>
</javac>
</target>
<!-- Compile the java code with debug info place into ${build} -->
<target name="compile-debug" depends="-dirty" description="Compile the source with debug information.">
<javac
srcdir="${source}"
destdir="${build-debug}"
includeantruntime="false"
debug="true"
debuglevel="lines,vars,source"
>
<classpath refid="debug.classpath"/>
</javac>
</target>
<!-- roll up everyting into a single jar file -->
<target name="dist" depends="clean, compile" description="Generate the distribution file for IMP.">
<!-- Copy the library .jars to the directory where the IMP distribution will be located -->
<copy todir="${dist}">
<fileset dir="${lib}"/>
</copy>
<!-- TODO: Generate the MANIFEST.MF file on the fly -->
<jar jarfile="${dist}/imp.jar" basedir="${build}" manifest="tools/MANIFEST.MF"/>
<!-- dump to web server -->
<copy todir="${web-files}">
<fileset dir="${dist}"/>
</copy>
</target>
<!-- build and run the tests then report the results in HTML -->
<target name="test" depends="compile-debug" description="Run all the JUnit tests and outputs the results as HTML.">
<!-- run the tests -->
<junit printsummary="true" haltonerror="false" haltonfailure="false">
<classpath refid="debug.classpath"/>
<formatter type="xml"/>
<batchtest fork="true" todir="${reports}">
<fileset dir="${source}">
<include name="${test.relative}/**/*Test*.java"/>
<exclude name="${test.relative}/**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
<!-- report the results -->
<junitreport todir="${reports}">
<fileset dir="${reports}" includes="TEST-*.xml"/>
<report todir="${reports}"/>
</junitreport>
<!-- update the latest results file to be commited -->
<copy file="${reports}/TESTS-TestSuites.xml" tofile="${history}/test-results-latest.xml"/>
<!-- dump to webserver -->
<copy todir="${web-tests}">
<fileset dir="${reports}"/>
</copy>
</target>
<!-- run emma code coverage tool and publish results in HTML -->
<target name="emma" depends="compile-debug" description="Checks code coverage with Emma.">
<!-- put the magic emma juice into the classes -->
<emma>
<instr
instrpathref="debug.imp.classpath"
destdir="${coverage-emma}/instr"
metadatafile="${coverage-emma}/metadata.emma"
merge="true"
/>
</emma>
<!-- run the tests -->
<junit fork="true" printsummary="true" haltonerror="false" haltonfailure="false">
<classpath>
<pathelement location="${coverage-emma}/instr"/>
<path refid="debug.classpath"/>
</classpath>
<batchtest fork="true" todir="${reports}">
<fileset dir="${source}">
<include name="${test.relative}/**/*Test*.java"/>
<exclude name="${test.relative}/**/AllTests.java"/>
</fileset>
</batchtest>
<jvmarg value="-Demma.coverage.out.file=${coverage-emma}/coverage.emma"/>
<jvmarg value="-Demma.coverage.out.merge=true"/>
</junit>
<!-- publish the coverage report -->
<emma>
<report sourcepath="${source}" verbosity="verbose">
<fileset dir="${coverage-emma}">
<include name="*.emma"/>
</fileset>
<html outfile="${web-emma}/index.html"/>
</report>
</emma>
</target>
<!-- publish javadoc -->
<target name="javadoc" description="Creates javadoc for IMP.">
<delete dir="${web-javadoc}"/>
<javadoc
sourcepath="${source}"
defaultexcludes="no"
destdir="${web-javadoc}"
author="true"
version="true"
use="true"
windowtitle="IMP: Integrated Mechanisms Program"
overview="${source}/overview.html"
classpathref="debug.classpath"
stylesheetfile="${javadoc-theme}/stylesheet.css"
/>
<copy file="${javadoc-theme}/javadoc.jpg" tofile="${web-javadoc}/javadoc.jpg"/>
</target>
<target name="all" description="Runs test, emma, javadoc, and dist targets.">
<antcall target="test"/>
<antcall target="emma"/>
<antcall target="javadoc"/>
<antcall target="dist"/>
</target>
</project>
If you observe the error stack, you will find the following line, just above the error line you mentioned...
[javac] [search path for class files: C:\Program Files\Java\jre6\lib\resource...
This line shows all the jars available in the class path for this ant target execution.
You will definitely not find the desired jar over here i.e. junit-x.x.x.jar (junit-4.8.2.jar)
Now go to eclipse -> Window -> preferences -> Ant -> Runtime -> Global Entries -> Add Jars add junit-4.8.2jar (which you will find in your project lib directory)
If you play around the Ant -> Runtime -> classpath and the classpath related error line in the error stack, you will understand the issue.
Hope this solves your problem.

Echo target description in Ant

<target name="compile" description="Compile the File">
<echo>Compile the File </echo>
<mkdir dir="${compilation-dir}" />
<javac srcdir="." classpath="another2" destdir="${compilation-dir}" />
</target>
I want to echo the description of the target. Is there a better way of doing this other than duplicating it?
I guess this is not a perfect solution, but at least you avoid duplicate descriptions.
<property name="testing.desc" value="this is the desc" />
<target name="testing" description="${testing.desc}">
<echo message="${testing.desc}" />
</target>

Categories