I defined a path in a file called unittest.xml in the following way(line 26):
<path id="tasks.path">
<pathelement location="${publish.home}/INSIDE/UnitTest/testinganttasks.jar"/>
</path>
next I tried to use the path in the following way:
<classpath>
<path refid="tasks.path" />
</classpath>
in a taskdef tag.
when I run my ant code, it does everything well until I get the following error:
BUILD FAILED unittest.xml:296: The
following error occurred while
executing this line: unittest.xml:281:
Reference tasks.path not found.
How can I resolve this issue?
You should see this example at http://ant.apache.org/manual/using.html#references
<project ... >
<path id="project.class.path">
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<target ... >
<rmic ...>
<classpath refid="project.class.path"/>
</rmic>
</target>
<target ... >
<javac ...>
<classpath refid="project.class.path"/>
</javac>
</target>
</project>
I think your problem is that in classpath you should not nest path element, but give id of the path for the classpath element itself.
Related
My Ant target looks like this:
<target name="junit" depends="compile">
<junit haltonfailure="true" printsummary="true">
<classpath>
<fileset dir="${idea.dir}/lib" includes="junit.jar" />
<fileset dir="${build.dir}" includes="**" />
</classpath>
<formatter type="plain" usefile="true" />
<batchtest fork="false" todir="${out.dir}">
<fileset dir="${build.dir}" includes="test_*/*Test.class" />
</batchtest>
</junit>
</target>
All compiled classes from the project are in ${build.dir}, as well as all compiled test cases. The latter are within ${build.dir}/test_* sub folders.
There is one test class ${build.dir}/test_ecs/EntityManagerTest.class, which apparently is found in batchtest. However, Ant gives me this output in the junit report:
test_ecs.EntityManagerTest
java.lang.ClassNotFoundException: test_ecs.EntityManagerTest
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)
Now, what I don't understand is: Why is the test case class file found, but then the error says exactly that class is not found?
try modifying the <classpath>.. section like this:
<junit ..>
<classpath>
<pathelement location="${idea.dir}/lib/junit.jar"/>
<pathelement path="${build.dir}"/>
</classpath>
and see if it runs...
I suspect your issue is the classpath declaration:
<classpath>
<fileset dir="${idea.dir}/lib" includes="junit.jar" />
<fileset dir="${build.dir}" includes="**" />
</classpath>
Are your *.class files located in the build directory? Or a subdirectory of the build dir?
By way of example here's my standard junit task:
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="test.path"/>
<pathelement path="${build.dir}/classes"/>
<pathelement path="${build.dir}/test-classes"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${build.dir}/test-reports">
<fileset dir="${test.src.dir}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
Note the classpath declaration. It includes the path to 3rd party dependency jars, the directory where I compiled my classes to and the directory I compiled my test classes to.
Selenium - ANT -TestNG
I have written a build.xml, where it produces a error stating " classname attribute of taskdef element is undefined "
Here is my build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name ="AutomationScripts" default="test" basedir=".">
<echo message ="Testing selenium server... Plz wait"/>
<target name="startServer">
<echo message ="Start selenium server... Plz wait"/>
<java jar="..\lib\selenium-server-standalone-2.19.0.jar" fork="true">
<jvmarg value="-Dhttp.proxyHost=192.168.0.200"/>
<jvmarg value="-Dhttp.proxyPort=3128"/> </java>
<echo message ="Started selenium server"/>
</target>
<target name="test" depends="startServer">
<echo message="Test run. Please wait"/>
<mkdir dir="out" />
<java classname="RosettastoneMain" classpath="..\AutomationScripts\bin"
dir="C:\Program Files\Java\jdk1.6.0_11\bin">
<classpath>
<fileset dir="..\AutomationScripts\lib" includes="*.*"/>
</classpatha></java>
<taskdef name="testng" classpath="org.testng.TestNG"> ---------> It produces
error in this stmt
<classpath>
<pathelement location="../lib/testng-6.2.jar"/>
</classpath>
</taskdef>
<property name="testng.output.dir" value="testngOutput"/>
<path id="classes">
<fileset dir="../lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${bin.dir}"/>
</path>
<mkdir dir="${testng.output.dir}"/>
<testng outputdir="${testng.output.dir}" classpathref="classes">
<xmlfileset dir="." includes="testng.xml"/>
</testng> </target>
<target name="stopServer">
<echo message="stop selenium server. Plz wait"/>
<get taskname="selenium-shutdown"
src="http://localhost:4444/selenium-server-standalone-2.0rc2/driver/?cmd=shutDown"
dest="./out/sever.stop.status.txt" ignoreerrors="true"/>
</target>
</project>
Can any one help me out
thanks in advance
You need to specify the class implementing the data type in the 'classname' attribute.
According to the Ant taskdef documentation (and more specifically typedef), this task has two required attributes - 'name' and 'classname', unless 'file' or 'resource' have been specified. The attribute 'classpath' only defines the locations where the class specified in 'classname' can be found.
I am trying to integrate yuicompressor with Ant to automate the minification of our CSS and JS files. However, I keep getting the following error message when I try to run build.xml:
BUILD FAILED
/Applications/MAMP/htdocs/zanadu-dev/build/build.xml:64: taskdef A class needed by class com.yahoo.platform.yui.compressor.YUICompressTask cannot be found: org/mozilla/javascript/EvaluatorException
using the classloader AntClassLoader[/usr/share/ant/lib/YUIAnt.jar:/usr/share/ant/lib/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar:/usr/share/ant/lib/yuicompressor-2.4.6/lib/rhino-1.6R7.jar]
Here is the code in my build.xml file:
<target name="minify" depends="build" description="Minifiy CSS and JS files">
<available file="${antlib.dir}/YUIAnt.jar" property="YUIANT_AVAILABLE" />
<fail unless="YUIANT_AVAILABLE" message="YUIAnt.jar not found" />
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathelement path="${antlib.dir}/YUIAnt.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6/lib/rhino-1.6R7.jar" />
</classpath>
</taskdef>
<mkdir dir="${jsminify.dir}" />
<yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true"
outputfolder="${jsmin.dir}">
<fileset dir="${js.dir}" >
<include name="**/*.js" />
</fileset>
</yuicompress>
<mkdir dir="${cssminify.dir}" />
<yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true"
outputfolder="${cssmin.dir}">
<fileset dir="${css.dir}" >
<include name="**/*.css" />
</fileset>
</yuicompress>
</target>
I have tried following several online examples on this, but all seem to yield the same error message. Not sure exactly where I can find the EvaluatorException class that seems to be missing.
Any idea what I may be doing wrong?
Cheers!
Your taskdef is missing one lib.
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathelement path="${antlib.dir}/YUIAnt.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6.jar" />
<pathelement path="${antlib.dir}/rhino-1.6R7.jar" />
</classpath>
</taskdef>
EDIT:,
The problem is somehow related to the jar locations and Ant's class-loader, see this post
One workaround is to copy YUIAnt.jar, yuicompressor-2.4.6.jar and rhino-1.6R7.jar to one directory. Then use it like above. I've tried and it works.
if you use http://code.google.com/p/yui-compressor-ant-task/ for me solution was to use classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask" instead of classname="com.yahoo.platform.yui.compressor.YUICompressTask"
I want to be able to have different targets doing nearly the same thing, as so:
ant build <- this would be a normal (default) build
ant safari <- building the safari target.
The targets look like this:
<target name="build" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.target}"/>
</java>
</target>
<target name="safari" depends="javac" description="GWT compile to Safari/JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.safari.target}"/>
</java>
</target>
(Nevermind the first thought that strikes: throw out ant! That's not an option just yet.) I tried using macrodef, but got a strange error message (even though the message didn't imply it, it think it had to do with putting a target in sequential). I don't want write a cmdline as so: ant -Dwhatever=nevermind. Any ideas?
My first try (without being able to test it at the moment):
<target name="build" depends="javac, create.mymacro" description="GWT compile to JavaScript">
<mymacro target="${lhs.target}"/>
</target>
<target name="safari" depends="javac, create.mymacro" description="GWT compile to Safari/JavaScript">
<mymacro target="${lhs.safari.target}"/>
</target
<target name="create.mymacro">
<macrodef name="mymacro">
<attribute name="target" default="${lhs.target}"/>
<sequential>
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="#{target}"/>
</java>
</sequential>
</macrodef>
</target>
I have a main build file with a path declaration
<path id="path.app.src">
<pathelement location="myfolder/src"/>
</path>
Then i call a task in sub file with <ant>
<ant antfile="subbuild.xml" inheritAll="false" inheritRefs="false">
<reference refid="path.app.src"/>
</ant>
in subbuild.xml i have:
<path id="subpath.app.src">
<pathelement location=".. some locations .."/>
<path refid="path.app.src" />
</path>
In my understanding the call to <ant> with a nested should overwrite path.app.src in subbuild.xml.
But i get an error like: subbuild.xml:xx: Reference path.app.src not found.
Am i doing something wrong ? is it a bug in ant ?
I'm using Apache Ant version 1.7.0 compiled on December 13 2006
Thanks,
Lionel
in fact it seems to have the right behavior now, but i can't explain what i did wrong the first time.
here is the code sample:
build.xml
<?xml version="1.0"?>
<project name="test" default="build" basedir=".">
<path id="mainpath">
<pathelement location="my/main/path"/>
</path>
<target name="build">
<ant antfile="subbuild.xml" target="test">
<reference refid="mainpath" torefid="globalpathid"/>
<reference refid="mainpath" torefid="localtotargetpathid"/>
</ant>
</target>
</project>
subbuild.xml
<?xml version="1.0"?>
<project name="subbuild">
<path id="globalpathid">
<pathelement location="my/sub/location"/>
</path>
<target name="test">
<path id="localtotargetpathid">
<pathelement location="my/target/location"/>
</path>
<property name="p.localtotargetpathid" refid="localtotargetpathid" />
<echo>p.localtotargetpathid: ${p.localtotargetpathid}</echo>
<property name="p.globalpathid" refid="globalpathid" />
<echo>p.globalpathid: ${p.globalpathid}</echo>
</target>
</project>
here is the console log:
$ ant
Buildfile: build.xml
build:
[ant] Parent project doesn't contain any reference 'mainpath'
test:
[echo] p.localtotargetpathid: d:\my\target\location
[echo] p.globalpathid: d:\my\main\path
BUILD SUCCESSFUL
Total time: 0 seconds
we can see globalpathid has been override but not localtotargetpathid, which is the behvior mentioned in the spec.
still I can't explain the first message ...
I think you have an incomplete declaration here in the subbuild file of refid path.app.src.
<path id="subpath.app.src">
<pathelement location=".. some locations .."/>
<path refid="path.app.src" /> <=======
</path>
It should not have the 2nd nested path element () since there is no location associated with it. The way you wrote the main build file to overwrite no reference //other than// this refid looks good to me.