Ant mkdir failed - ant

i'm new to ant. Please highlight which goes wrong in my build.xml. Any help is appreciated. Thanks.
Problem: The folders i wanted to make kept created on the upper level of current directory.
ant version: 1.8.0
platform: LinuxMint 10.10
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.9) (6b20-1.9.9-0ubuntu1~10.10.2)
OpenJDK Server VM (build 19.0-b09, mixed mode)
build.xml:
<property name="prj.root" value="." />
<property name="build.dir" value="${prj.root}/build"/>
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.models" value="${build.dir}/models"/>
<property name="build.projects" value="${build.dir}/projects"/>
<property name="dist.dir" value="${prj.root}/dist"/>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="init" depends="clean" description="initialization target">
<echo message=">> Build JAS ${jas.version} at ${prj.root}"/>
<echo message="build.dir = ${build.dir}" />
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.docs}" />
<mkdir dir="${build.models}" />
<mkdir dir="${build.projects}" />
<mkdir dir="${dist.dir}"/>
</target>
Execution + Output:
yamhon#yamhon-g410 ~/projects/JAS $ ant init
Buildfile: /home/yamhon/projects/JAS/build.xml
clean:
[delete] Deleting directory /home/yamhon/projects/build
[delete] Deleting directory /home/yamhon/projects/dist
init:
[echo] >> Build JAS ${jas.version} at .
[echo] build.dir = ./build
[mkdir] Created dir: /home/yamhon/projects/build
[mkdir] Created dir: /home/yamhon/projects/build/docs
[mkdir] Created dir: /home/yamhon/projects/build/models
[mkdir] Created dir: /home/yamhon/projects/build/projects
[mkdir] Created dir: /home/yamhon/projects/dist
BUILD SUCCESSFUL
Total time: 0 seconds
yamhon#yamhon-g410 ~/projects/JAS $

Two things you can try.
1) Resolve your relative '.' path by assigning it to a property with the location attribute.
<property name="my.path" location="."/>
<echo message="my.path = ${my.path}"/>
2) Use the build in basedir property which points to the directory of the build.xml file itself.
<echo message="basedir = ${basedir}"/>
This should get you going :)

Related

Build failed while executing Ant script

I have an ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTest" basedir="." default="clean">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<target name="clean" description="delete all generated files">
<delete dir="${classes.dir}" failonerror="false"/>
<echo message="Hello" />
<delete dir="${ant.project.name}.jar"/>
</target>
<target name="compile" description="compile the task">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" description="create jars of task" depends="compile">
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}" />
</target>
<target name="use" description="use the created jars" depends="jar">
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar" />
<ntTest/>
</target>
</project>
And output is
Buildfile: D:\Work\D3000\AntTest\Build.xml
clean:
[delete] Deleting directory D:\Work\D3000\AntTest\classes
[echo] Hello
compile:
[mkdir] Created dir: D:\Work\D3000\AntTest\classes
[javac] Compiling 1 source file to D:\Work\D3000\AntTest\classes
compile:
jar:
[jar] Building jar: D:\Work\D3000\AntTest\AntTest.jar
compile:
jar:
use:
BUILD FAILED
D:\Work\D3000\AntTest\Build.xml:24: taskdef class AntTest cannot be found
using the classloader AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
Total time: 758 milliseconds
Can anybody tell me why this error is coming:
BUILD FAILED D:\Work\D3000\AntTest\Build.xml:24: taskdef class AntTest
cannot be found using the classloader
AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
My class file contains class named AntTest
Seems like the classname is wrong, you need the full qualified classname.
instead of :
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar"/>
try :
<taskdef name="ntTest" classname="com.yourdomain.AntTest" classpath="${ant.project.name}.jar"/>

Target Clean does not exist in the project dir

I have installed Ant in my centos 6.3 , installed location are
/opt/ant and also ANT_HOME env are same
I have created build.xml to test by deleting testdir. This directory exist in the /opt/ant/testdir like this.
build.xml
<?xml version="1.0"?>
<project name="testdir" default="all" basedir=".">
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib"/>
<target name="all" depends="clean, compile" description="Builds the whole project">
<echo>Doing all</echo>
</target>
<target name="clean">
<echo message="Deleting bin/java ..." />
<delete dir="testdir/test" />
</target>
</project>
Using Command :-
ant -buildfile build.xml Clean
getting error:-
BUILD FAILED
Target "Clean" does not exist in the project "testdir".
Any suggestion to make it work?
You mis-spelt the target name ? 'Clean' as against 'clean' ??
I have found solution. I missed target="compile" block in build.xml.
<target name="compile">
<echo message="Compiling source code"/>
</target>
Run command :-
ant clean

TestNG test-output folder getting generated on Desktop when expected to be in project folder

I have a setup of Selenium WebDriver + TestNG + Ant framework in my automation project. Running webdriver + TestNG tests from Ant using build.xml was working absolutely fine a few months ago. TestNG was generating the test-output folder in the project directory as expected. Now when I run my testng tests from ANT it's generating the default report folder test-output on my Desktop (home/user/Desktop). I don't know why it is happening.
This is my build.xml file:
<project name="InitialConfigProject" default="start" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property file="./app.properties"/>
<property name="ws.home" value="${basedir}"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="browser" value="/usr/bin/google-chrome"/>
<property name="mail_body_file" value="${basedir}/email_body.txt"/>
<property name="buildID" value="IND3.2.0"/>
<property name="sendmailscript_path" value="${basedir}/sendmail.sh"/>
<property name="mail_subject" value="Automated_test_execution_of_${buildID}"/>
<!-- ====== Set the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.home}/lib" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="timestamp" pattern="dd/MM/yyyy hh:mm aa" />
</tstamp>
<!--
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition> -->
<property name="build.log.dir" location="${basedir}/buildlogs" />
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
<echo message="Loading TestNG.." />
<taskdef name="testng" classpath="${test.classpath}" classname="org.testng.TestNGAntTask" />
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compiling files -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<copy file="${ws.home}/app.properties" todir="${ws.home}/build" />
<copy file="${ws.home}/resources/testdata/testDataSet1.properties" todir="${ws.home}/build" />
<echo message="compiling source files..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.6"
classpath="${test.classpath}"
includeantruntime="true"
>
</javac>
</target>
<!-- run -->
<target name="run" depends="compile">
<testng outputdir="${ws.home}/test-output" classpath="${test.classpath}:${test.dest}" suitename="Praxify Sanity Suite">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
</target>
<!-- ========== Generating reports using XSLT utility ============== -->
<target name="testng-xslt-report">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"
processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="classpath_jars"></classpath>
</xslt>
</target>
<!-- Starting point of the execution, should be dependent on target "run".
Target sequence will be:
start (not_execute) ==> run (not_execute) ==> compile (not_execute) ==> init (execute) ==> clean (execute)
start (execute) <== testng-xslt-report (execute) <== run (execute) <== compile (execute) <==
Suitable for ANT 1.7. Currently using this ====================== -->
<target name="start" depends="run, testng-xslt-report">
<tstamp prefix="getTime">
<format property="TODAY" pattern="MM-dd-yyyyhhmmaa"/>
</tstamp>
<echo message="sending report as mail...."/>
<property name="execution_time" value="${buildID}_${getTime.TODAY}"/>
<property name="dest_file" value="/home/xtremum/Reports/${execution_time}.zip"/>
<zip destfile="/home/xtremum/Reports/${execution_time}.zip" basedir="${basedir}/testng-xslt"/>
<property name="report_attachment_file" value="${dest_file}"/>
<exec executable="${sendmailscript_path}" newenvironment="false">
<arg value="${mail_subject}"/>
<arg value="${mail_recipient}"/>
<arg value="${report_attachment_file}"/>
<arg value="${mail_body_file}"/>
</exec>
</target>
Just for the record:
1. I am using Eclipse Juno.
2. I have installed TestNG plugin on Eclipse so that I can run tests directly from eclipse by right clicking on testng.xml and going for Run.
3. I have installed ANT 1.7 on my Ubuntu machine and have set my ANT_HOME pointing to /usr/share/ant. And I looked up in Windows -> Preferences -> Ant -> Runtime -> Ant Home Entries (Default) and they seem to have references to ant 1.8.3 libraries (JARS) which are inside the Eclipse package (eclipse/plugins/). Is there anything wrong here?
4. I am running the tests via ant from eclipse and not from command line.
I am not getting any build errors. Tests are getting executed but the test-output folder is getting created on Desktop. Any help?
If you are running through the testng plugin option, the output folder would be the one you specify in Project->Properties->TestNG->OutputDirectory

How to exclude base directory from phing/ant FileSet

I have a phing build target that I want to run on each directory directly under my project base. I'm using a foreach task with a fileset to run the target on each directory. The problem I'm having is that the base directory is included, with a filename of "".
Here's an example of the directory structure:
One
Two
build.xml
Here's a simple build file to test:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="test">
<target name="test">
<foreach param="filename" absparam="absfilename" target="echo-file">
<fileset dir="${project.basedir}">
<include name="*" />
<exclude name="*.*" />
</fileset>
</foreach>
</target>
<target name="echo-file">
<echo message="filename: ${filename}" />
<echo message="absfilename: ${absfilename}" />
</target>
</project>
And here's the results of the build (note the first entry with empty filename):
Buildfile: /Users/dmertl/test/build.xml
Test > test:
[foreach] Calling Buildfile '/Users/dmertl/test/build.xml' with target 'echo-file'
Test > echo-file:
[echo] filename:
[echo] absfilename: /Users/dmertl/test/
[foreach] Calling Buildfile '/Users/dmertl/test/build.xml' with target 'echo-file'
Test > echo-file:
[echo] filename: One
[echo] absfilename: /Users/dmertl/test/One
[foreach] Calling Buildfile '/Users/dmertl/test/build.xml' with target 'echo-file'
Test > echo-file:
[echo] filename: Two
[echo] absfilename: /Users/dmertl/test/Two
Not sure how I didn't figure this out the first time around, but here's the solution:
<foreach param="filename" absparam="absfilename" target="echo-file">
<fileset dir="${project.basedir}">
<include name="*" />
<exclude name="/" />
<exclude name="*.*" />
</fileset>
</foreach>
Excluding "/" in the fileset removes the root directory.

Ant fails to find junit for project generated with wsdl2java

I created a axis2 soap client project with unit tests using the following command:
wsdl2java -t -uri http://myDomain.tld/myService.svc?wsdl
I then ran ant and got build errors because it could not find junit methods such as fail(),assertNotNull(), etc. I realize I need the compiler to reference a junit jar. Looking in the build.xml I see the following:
<property name="classes" value="${build}/classes"/>
<property name="lib" value="${build}/lib"/>
So I place junit-4.8.2.jar in the build.lib subfolder. I still get the same errors. What else do I need to do to get ant to build my project?
Update:
I made the following changes to the build.xml:
Added the lib folder as a path with the id local.class.path
<path id="local.class.path">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
Then I modified my init task to look for junit:
<available classpathref="local.class.path" property="junit.available" classname="junit.framework.TestCase"/>
<condition property="jars.ok">
<and>
<isset property="stax.available"/>
<isset property="axis2.available"/>
<isset property="junit.available"/>
</and>
</condition>
<!--Print out the availabilities-->
<echo message="Stax Availability= ${stax.available}"/>
<echo message="Axis2 Availability= ${axis2.available}"/>
<echo message="JUnit Availability= ${junit.available}"/>
And strangely the output is:
H:\Code\Java\test.axis2> ant pre.compile.test
Buildfile: H:\Code\Java\RiskTools.axis2\build.xml
init:
[mkdir] Created dir: H:\Code\Java\test.axis2\build
[mkdir] Created dir: H:\Code\Java\test.axis2\build\classes
[mkdir] Created dir: H:\Code\Java\test.axis2\build\lib
pre.compile.test:
[echo] Stax Availability= true
[echo] Axis2 Availability= true
[echo] JUnit Availability= ${junit.available}
BUILD SUCCESSFUL
Total time: 0 seconds
So it seems I am doing something wrong due to the line [echo] JUnit Availability= ${junit.available}
Apparently build/lib is the transient folder that gets blown away by ant clean. I made a folder called lib at the project root and then did the following to the build.xml.
In the root I added <property name="dep_libs" value="${project.base.dir}/lib"/>
I then change my path statement above to:
<path id="local.class.path">
<fileset dir="${dep_libs}">
<include name="*.jar"/>
</fileset>
</path>
Then everything worked.

Resources