I'm trying to compile project using:
ant compile
I've receive following error in terminal:
taskdef class org.testng.TESTNGNGAntTask cannot be found
using the classloader AntClassLoader[]
Here is my teskdef from build.xml file
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TESTNGNGAntTask" />
Could you include the ant file (by default is named build.xml) ?
Ensure you had installed Apache Ant in your computer: open a command line and execute ant -v. If appears a version message It's works.
If you find the ant file, include a compile target (or if you have one, modify it) like this:
<property name="src" location="src" />
<property name="build" location="build" />
<target name="compile">
<mkdir dir="${build}" />
<javac srcdir="${src}" destdir="${build}" />
</target>
The propierties are just constants.
Good luck!
The name of the class is TestNGAntTask (with one NG and with only the T of Test capitalized), not TESTNGNGAntTask (with two NG's and an entirely capitalized TEST).
Try the following instead:
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
Related
Say I have a library and a binary target, let's call them MyLib and MyBin,
MyBin depends on MyLib.
I'm trying to create an Ant buildfile for MyBin that first builds MyLib and then includes it in the classpath when building MyBin.
I've tried using Ant tasks as in Building other, dependent projects with Ant .
However, it's not working, and from ant -v I think the MyBin build-deps target is not even building MyLib. Seems like it's confusing MyBin and MyLib properties? I'm not sure how to prevent this though.
I'm dumping only MyBin/build.xml below, but the MyLib is almost identical, except it does not have the build-deps target.
<project name="MyBin" default="main" basedir=".">
<property name="projectName" value="MyBin" />
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="dist.dir" location="dist" />
<property name="dist.lib.dir" location="dist/lib" />
<property name="lib.dir" value="lib" />
<target name="build-deps" depends="init">
<!-- MyLib main target does clean -> build -> jar to dist folder -->
<!-- Its build.xml uses many of the same property values as above -->
<ant antfile="../MyLib/build.xml" target="main"/>
</target>
<path id="classpath">
<fileset dir="${basedir}/">
<include name="../MyLib/dist/**/*.jar" />
</fileset>
</path>
<!-- Need classpath to run this -->
<target name="compile" depends="build-deps" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}"
destdir="${build.dir}" classpathref="classpath" />
</target>
<!-- Group all dependencies into a big dependency-all.jar -->
<target name="copy-dependencies">
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.lib.dir}/dependencies-all.jar">
<zipgroupfileset dir="${lib.dir}">
<include name="**/*.jar" />
</zipgroupfileset>
</jar>
</target>
<!-- jar it, extract above dependency-all.jar and zip it with project files -->
<target name="jar" depends="compile, copy-dependencies"
description="package, output to JAR">
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
</manifest>
<zipfileset src="${dist.lib.dir}/dependencies-all.jar"
excludes="META-INF/*.SF" />
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Default, run this -->
<target name="main" depends="clean, compile, jar" />
</project>
What I see with ant -v in MyBin is something along the lines of:
build-deps:
Project base dir set to: /MyBin
[ant] calling target(s) [main] in build file /MyLib/build.xml
parsing buildfile /MyLib/build.xml with URI = file:/MyLib/build.xml
Project base dir set to: /MyBin
Override ignored for property "projectName"
Override ignored for property "build.dir"
Override ignored for property "dist.dir"
Override ignored for property "dist.lib.dir"
Override ignored for property "lib.dir"
[pathconvert] Set property classpath.name =
[ant] Entering /MyLib/build.xml...
Build sequence for target(s) `main' is [clean, init, copy-dependencies, jar, main]
Complete build sequence is [clean, init, copy-dependencies, jar, main, ]
clean:
[delete] Deleting directory /MyBin/bin
[delete] Deleting directory /MyBin/bin
init:
[mkdir] Created dir: /MyBin/bin
copy-dependencies:
[ant] Exiting /MyLib/build.xml.
On your specific question:
seems like it's confusing MyBin and MyLib properties? I'm not sure how
to prevent this though.
You are using this to invoke the MyLib build:
<ant antfile="../MyLib/build.xml" target="main" />
A build invoked via the <ant> task this way by default inherits all properties from the caller, including basedir, hence the build is run in the wrong place.
Instead you could use, for example:
<ant dir="../MyLib" />
That will run build.xml in the specified directory, set the basedir property, and call the default target, which should be main if you are using a very similar buildfile for the library as you say. If you don't want to inherit properties from MyBin when executing the MyLib task, specify inheritAll=false in the task.
From the <ant> task docs for the dir attribute:
the directory to use as a basedir for the new Ant project (unless
useNativeBasedir is set to true). Defaults to the current project's
basedir, unless inheritall has been set to false, in which case it
doesn't have a default value. This will override the basedir setting
of the called project. Also serves as the directory to resolve the
antfile and output attribute's values (if any).
I am creating a java agent that will be used to to do some bytecode modification to some classes org.eclipse.jdt.core.JDTCompilerAdapter is one of them. I am using javassit to modify some the execute() method of org.eclipse.jdt.core.JDTCompilerAdapter. So I have included ecj as in my agent project (using gradle)
compile group: 'org.eclipse.jdt.core.compiler' ,name: 'ecj', version :'4.3.1'
As I need to use some classes from ecj.
The goal of the agent is to intercept the calls to execute method, modify the execute method to add some calls to some of my classes in the aim of triggering some processing.
I am testing the agent against a Simple java project with 2 classes. the project is builded with ant and uses JDTCompilerAdapter as a compiler.
Here is the build.xml file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="TestProject">
<property file="build.properties" />
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="PClasspath">
<pathelement location="bin"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="init" name="build">
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="PClasspath"/>
</javac>
</target>
<!--
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_JDT_CORE}" includes="*.jar"/>
</copy>
</target>-->
<target name="build-e" >
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
The agent is to be used when building a project.
So for testing the agent I use this command:
java -jar agent-wrapper.jar --outdir ./out --exec ./build_wrapper.sh
build_wrapper.sh contains this (I have added ecj dependency so I could compile the project with JDTCompilerAdapter as I have in bulid.xml <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> :
../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar build-e
The idea is that the agent-wrapper will parse the argument (outdir is used to generate some stuff and exec is a script used to launch a the build of my test project) get the command to be executed from build_wrapper.sh (in this case ../ant/bin/ant -lib ../eclipse/plugins/ecj-4.3.1.jar build-e) and add it self as java agent to the command.
The problem occurs during the execution of the agent. Here is the output:
java -jar custom-agent.jar --outdir ./out --exec ./build_wrapper.sh [10:18:53]
Picked up JAVA_TOOL_OPTIONS: -javaagent:/Users/dev/TestAgent/project/custom-agent.jar=OUTDIR=/Users/dev/TestAgent/project/./out
objc[30474]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Buildfile: /Users/dev/TestAgent/project/build.xml
build-e:
init:
[mkdir] Created dir: /Users/dev/TestAgent/project/bin
build:
BUILD FAILED
/Users/dev/TestAgent/project/build.xml:47: The following error occurred while executing this line:
/Users/dev/TestAgent/project/build.xml:32: Class org.eclipse.jdt.core.JDTCompilerAdapter could not be loaded because of an invalid dependency.
Total time: 2 seconds
abnormal termination, exit code: 1
When I don't use ecj-4.3.1.jar inside my agent project, the build runs well I intercept the call to execute() method but I can't use the other classes from ecj jar.
The show stopper error is "Class org.eclipse.jdt.core.JDTCompilerAdapter could not be loaded because of an invalid dependency."
First hint at the fault might be found from reading this link
http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-ant_javac_adapter.htm
The second hint might be that one of the jars required for running the JDTCompilerAdapter is missing.
To get the JDTCompilerAdapter to work I copied both the JDTCompilerAdapter.jar and org.eclipse.jdt.core.jar into the ant/lib folder.
There are differences based on version of eclipse and the version of java which are documented in the link mentioned above.
Setup:
Project A - Pure Java project with no dependencies.
Project B - Pure Java project depends on project A.
Process:
I have a build project script in each of the project root directory and a master script to run them both, in the correct order, first Project A and then Project B. The script output is relative to each project's path.
The script works just fine for Project A, but when it comes to Project B it misses the classes output of Project A.
Using ANT, is there a way to add "dynamically" to the compile classpath the output of a previously compile project?
Or, is there any action I can take except explicitly provide Project B with the classes output path of Project A?
OK, so this took a bunch of hacking.
First use add ant-contrib to your ant you can download it from here.
Then I declared a var instead of a property in my main ant script.
In the compile macro I've passed it to the javac as the classpath.
After the compile is done, I've appended the new classes output folder to the classpath var and called the next compile.
Good luck.
The compile script:
<?xml version="1.0"?>
<project name="PDF Test Client" default="main" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<macrodef name="Compile">
<attribute name="ProjectName" default=" -- set aname to a 'ProjectName' property --" />
<attribute name="ProjectRootDir" default="." />
<attribute name="SourceDir" default="#{ProjectRootDir}/src" />
<attribute name="OutputDir" default="#{ProjectRootDir}/output" />
<attribute name="BuildDir" default="#{OutputDir}/bin" />
<attribute name="ClassesDir" default="#{BuildDir}/classes" />
<sequential>
<echo message="Compiling... #{ProjectName}" />
<mkdir dir="#{ClassesDir}" />
<javac srcdir="#{SourceDir}" destdir="#{ClassesDir}" classpath="${ClassPathFolders}" includeantruntime="true" />
<var name="ClassPathFolders" value="${ClassPathFolders}; #{ClassesDir}" />
<echo message="-" />
</sequential>
</macrodef>
<target name="main">
</target>
</project>
I'm currently playing with Ant to do some auto branding work. I modified default build.xml and setup my own target. What I hope to ask is that is there a way in Ant Script that could automatic renaming the apk file just build with the certain name?
I currently has this Ant target setup in my build.xml:
<target name="release-brandA"
depends="default, -set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode for brandA.">
<delete dir="${res}" />
<copydir dest="${res}" src="${branding}/brandA" forceoverwrite="ture" />
<replaceregexp flags="g" byline="false">
<regexp pattern="import com.arthur.android(.*).R;"/>
<substitution expression="import com.arthur.android.brandA.R;"/>
<fileset dir="src" includes="**/*.java" />
</replaceregexp>
<replaceregexp flags="g" byline="false">
<regexp pattern="package="com.arthur.android(.*)"" />
<substitution expression="package="com.arthur.android.brandA"" />
<fileset dir="" includes="AndroidManifest.xml" />
</replaceregexp>
</target>
Is there a way that I could add some more task, to let the output file just be like brandA.apk?
Thank you!
The final apk filename is actually defined by the property 'out.final.file'
So you could create a new Task that sets this property:
<target name="-set-out-final-file">
<property name="out.final.file" location="${out.absolute.dir}/brandA.apk" />
</target>
Finally, you just need to invoke the -set-out-final-file target before calling the debug or release targets.
Using your release-brandA task, it would become this:
<target name="release-brandA"
depends="default, -set-out-final-file, -set-release-mode, -release-obfuscation-check...
Here I found more better explanation and more suitable way to override release target.
Please refer to section:
<target
name="release"
depends="custom-set-release-mode, android_rules.release" />
Its very simple.Refer this link [1]: https://ant.apache.org/manual/running.html
So in the above case,we need to run it like this,
ant debug -Dout.final.file=brandA.apk
Thats it.
I'm fairly new to both Apache Ant and GCJ, and I'm having a hard time trying to build with GCJ via Ant.
My app is in Scala, so I need to use GCJ to take .class files as source. No problem compiling .scala to .class with Ant.
First I figured out how to manually compile a .class file to .o (object), this way:
gcj --classpath=(...) -c (somepath)MouseClickListener.class -o (somepath)MouseClickListener.o
I see here that Ant supports GCJ compilation through the javac tag. So I figured this should work:
<target name="gcjCompile" depends="compile">
<mkdir dir="${object.dir}" />
<javac srcdir="${build.dir}"
destdir="${object.dir}"
compiler="gcj"
executable="C:/gcc/gcc-4.3/bin/gcj.exe"
classpathref="gcjProject.classpath">
<include name="**/*.class"/>
</javac>
</target>
But this javac task does nothing and I get no errors. Any clues?
Thanks
It sounds like you want to link your app into a native executable. That means that you've already compiled the source into JVM bytecode (as you've figured out to do by compiling .scala into .class files). You'll need to run the gcj command manually using the <exec> task to compile the bytecode into gcc object code files.
I'd recommend something like this:
<property name="main.class" value="Main" />
<property name="class.dir" value="${basedir}/classes" />
<target name="compile">
<mkdir dir="${class.dir}" />
<javac srcdir="${build.dir}"
destdir="${class.dir}"
compiler="gcj"
executable="C:/gcc/gcc-4.3/bin/gcj.exe"
classpathref="gcjProject.classpath">
<include name="**/*.java"/>
</javac>
</target>
<target name="link" depends="compile">
<mkdir dir="${object.dir"} />
<exec cmd="C:/gcc/gcc-4.3/bin/gcj.exe">
<arg value="-classpath=${object.dir}" />
<arg value="-c" />
<arg value="*.class" />
</exec>
</target>
Keep in mind that you need to define the build.dir and object.dir properties, and you may need to add a depends task before the javac in the compile target (or just recompile from scratch each time). I may have missed a lot of things, you should check the manual pages (for gcj, gcc, and ant) if it doesn't work at first.