I am working on an ant build file (stand alone from eclipse) to build my android application.
I need to generate the R.java file. I have done so successfully, however, when it tries to build my project from the src directory it complains that it cannot find the imported R.java file. I see it in the gen directory... but it still will not build.
It fails in the build-project target. Fails saying that it "cannot find symbol" and it is reffering to the R.java file. And the line of code it is pointing at is the import line.
Here is my xml file, please assist, thank you! Let me know if you need more information.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="ATB">
<target name="init">
<mkdir dir="../bin/classes"/>
<copy includeemptydirs="false" todir="../bin/classes">
<fileset dir="../src">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="../bin/classes">
<fileset dir="../gen">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="clean" name="cleanall"/>
<target depends="resource-src,build-subprojects,build-project,jar" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true"
debuglevel="${debuglevel}"
destdir="../bin/classes"
source="${source}"
target="${target}"
executable="${env.JAVAHOME}/javac"
fork="true"
>
<src path="../src"/>
<classpath refid="ATB.classpath"/>
</javac>
<javac
debug="true"
debuglevel="${debuglevel}"
destdir="../bin/classes"
source="${source}"
target="${target}"
executable="${env.JAVAHOME}/javac"
fork="true"
>
<src path="../gen"/>
<classpath refid="ATB.classpath"/>
</javac>
</target>
<target depends="init" name="jar">
<jar destfile="../bin/${ant.project.name}">
<fileset dir="../src/">
</fileset>
</jar>
</target>
<target name="resource-src" description="Generate the R.java file for this project's resources.">
<exec executable="${aapt}" failonerror="true">
<arg value="package"/>
<arg value="-f"/>
<arg value="-v"/>
<arg value="-M"/>
<arg path="../AndroidManifest.xml"/>
<arg value="-A"/>
<arg path="../assets"/>
<arg value="-I"/>
<arg path="${android_jar}"/>
<arg value="-m"/>
<arg value="-J"/>
<arg path="../gen"/> <!-- Create R.java in the gen directory -->
<arg value="-S"/>
<arg path="../res"/>
</exec>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects">
<ant antfile="build.xml" dir="${Comms.location}" inheritAll="false" target="clean"/>
<ant antfile="build.xml" dir="${Comms.location}" inheritAll="false" target="build"/>
</target>
</project>
Your script doesn't include {gen} path as compile source. Just add into <javac>:
<src path="../src"/>
<src path="../gen"/>
Related
The ant compile target below compiles all .java files in any of the src folders specified using a <src path="..."/> tag. You can see that a number of items are added to the classpath using <classpath refid=...> tags.
<target name="compile">
<echo message="${ant.project.name}: ${ant.file}"/>
<deps-load-path conf="core" pathid="core.ivy.classpath" />
<deps-load-path conf="test" pathid="test.ivy.classpath" />
<javac debug="true" includeantruntime="false" debuglevel="source,lines,vars" destdir="${bin.path}" source="1.8" target="1.8">
<src path="${xtext.project.path}/src"/>
<src path="${xtext.project.path}/src-gen"/>
<src path="${project.path}/src"/>
<src path="${project.path}/src-gen-umpletl"/>
<src path="${project.path}/src-gen-umple"/>
<src path="${project.path}/test"/>
<src path="${vendors.path}/jopt-simple/src"/>
<exclude name="**/.git"/>
<exclude name="**/*.ump" />
<exclude name="**/data" />
<classpath refid="project.classpath"/>
<classpath refid="validator.project.classpath"/>
<classpath refid="core.ivy.classpath" />
<classpath refid="test.ivy.classpath" />
<!-- Add compiler arguments here, see https://ant.apache.org/manual/using.html#arg for details, example below
<compilerarg value="-Xlint:deprecation" />
-->
</javac>
<copy todir="${bin.path}" overwrite="true">
<fileset dir="${project.path}/src"><include name="**/*.grammar"/></fileset>
<fileset dir="${project.path}/src"><include name="**/*.error"/></fileset>
</copy>
<delete file="cruise.umple/src/rules.grammar"/>
<delete file="cruise.umple/bin/rules.grammar"/>
</target>
One of these items is project.classpath, which is defined elsewhere in the file as the same location as ${bin.path}, which is where the compiled files are written to (see the <copy todir...> tag). How can ${bin.path} be both a classpath dependency and the location where .class files are written to? I know for a fact that ${bin.path} gets deleted before each build, so there isn't anything in the folder prior to the compile target being run. Are the .class files that are produced as the compile target executes added to the classpath dynamically?
Below is my build.xml
<target name="tdd" description="Run unittest" depends="jar">
<mkdir dir="${build.test.dir}"/>
<javac srcdir="${test.src.dir}" destdir="${build.test.dir}"
includeAntRuntime="false">
<classpath refid="lib.junit"/>
<classpath refid="lib.dataquery"/>
</javac>
<jar destfile="${build.jar.dir}/dataqueryTDD.jar">
<fileset dir="${build.test.dir}">
<include name="**/*.class"/>
</fileset>
</jar>
<mkdir dir="${build.test.report.dir}"/>
<junit printsummary="yes">
<classpath refid="lib.junit"/>
<classpath refid="lib.dataquery"/>
<classpath refid="lib.dataquery.tdd"/>
<formatter type="xml"/>
<batchtest todir="${build.test.report.dir}">
<fileset dir="${test.src.dir}" includes="**/*Test.java"/>
</batchtest>
</junit>
<junitreport todir="${build.test.report.dir}" tofile="TEST-Summary.xml">
<fileset dir="${build.test.report.dir}" includes="*.xml"/>
</junitreport>
</target>
I can run them and print reports without errors.
However, ant will only tell me if there is a failed test. I need to manually checkout the test report by command cat. I am wondering how to force ant dumping the failed test report(s) on stdout with colour.
Thanks
Try the following:
<!-- new testwithcat target -->
<target name="testwithcat" depends="tdd, catreport"/>
<target name="tdd" description="Run unittest" depends="jar">
<mkdir dir="${build.test.dir}"/>
<javac srcdir="${test.src.dir}" destdir="${build.test.dir}"
includeAntRuntime="false">
<classpath refid="lib.junit"/>
<classpath refid="lib.dataquery"/>
</javac>
<jar destfile="${build.jar.dir}/dataqueryTDD.jar">
<fileset dir="${build.test.dir}">
<include name="**/*.class"/>
</fileset>
</jar>
<mkdir dir="${build.test.report.dir}"/>
<!-- add errorProperty, failureProperty to junit task -->
<junit printsummary="yes" errorProperty="test.failed" failureProperty="test.failed">
<classpath refid="lib.junit"/>
<classpath refid="lib.dataquery"/>
<classpath refid="lib.dataquery.tdd"/>
<formatter type="xml"/>
<batchtest todir="${build.test.report.dir}">
<fileset dir="${test.src.dir}" includes="**/*Test.java"/>
</batchtest>
</junit>
<junitreport todir="${build.test.report.dir}" tofile="TEST-Summary.xml">
<fileset dir="${build.test.report.dir}" includes="*.xml"/>
</junitreport>
</target>
<!-- add cat report target that runs if test.failed has been set in junit task -->
<target name="catreport" depends="test" if="test.failed">
<echo message="Test failed - cat the test report"/>
<!-- customise the following to cat your report in colour -->
<exec executable="cat">
<arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>
</target>
Run using:
ant testwithcat
Output:
Test failed - cat the test report
[content of ${build.test.report.dir}/TEST-Summary.xml]
You will need to customise
<exec executable="cat">
<arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>
with your own command to "cat your report in colour".
To get plain text output take a look at Ant JUnit Nice Output Formatter.
You can use
<report format="frames" todir="${build.test.report.dir}"/>
or
<report format="noframes" todir="${build.test.report.dir}"/>
in the junitreport task to generate html output.
You can replace
<exec executable="cat">
<arg value="${build.test.report.dir}/TEST-Summary.xml"/>
</exec>
with a call to display the html in a browser. See Exec for example code to do this.
I am trying to configure the ANT for TEstNG but with problems
<project basedir="." default="build" name="Ant Play">
<property name="classes.dir" value="bin" />
<property name="report.dir" value="test-output" />
<path id="classpath">
<fileset dir=".">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${basedir}\${classes.dir}"/>
</path>
<target name="init">
<mkdir dir="${classes.dir}"/>
<copy includeemptydirs="false" todir="${classes.dir}">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${classes.dir}"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-project" name="build"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" includeantruntime="false" destdir="${classes.dir}">
<src path="src"/>
<classpath refid="classpath"/>
</javac>
</target>
<target depends="build" name="runTests" description="Running tests" >
<echo>Running Tests...</echo>
<taskdef resource="testngtasks" classpathref="classpath"/>
<testng outputDir="${report.dir}"
haltonfailure="true"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter"
classpathref="classpath">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
<!--<classfileset dir="${classes.dir}" includes="**/*.class" />-->
</testng>
</target>
</project>
But it refuse to get classpath
I get ................../.../.../lib does not exist.
I do not have lib in my project at all
How to change the classpath? And which folder it should be?
Thanks!
I found the solution
Created manually lib folder>>>Copied to lib all needed Jars>>> added these jars to path
and it worked
I'm a beginner with ant and am wondering what this error means. "failed to create task or type classpath" It gives me that error on the line that is unzipping the file.
<project name="Project2" default="run">
<target name="compile" depends="clean">
<javac srcdir="." includeantruntime="false"/>
</target>
<target name="clean">
<delete>
<fileset dir="." includes="**/*.class"/>
</delete>
<delete>
<fileset dir="." includes="META-INF"/>
</delete>
<delete>
<fileset dir="." includes="*.*~"/>
</delete>
</target>
<target name="getInput">
<get src="file.zip" dest="."/>
<unzip src="folder.zip" dest="folder"/>
</target>
<target name="run" depends= "compile, who, getInput" >
<java classname="Driver" fork="yes"/>
<classpath path = "."/>
</target>
<target name="who">
<echo message="Name"/>
</target>
<target name="jar">
<jar destfile="project2.jar" basedir="."/>
</target>
Any help would be appreciated!
this is what you should do:
put the src values to have the same value
check if the source file exists under the project root
I'm trying to build an application using ant. Everything appears to be fine when I build but I continually get the above error for what I've tried so far.
java -jar dist/pmml_export.jar
java -cp ".:log4j-1.2.16.jar" -jar dist/pmml_export.jar
java -cp log4j-1.2.16.jar -jar dist/pmml_export.jar
I doubled checked to see if Layout was in the jar I'm referencing and it is there. I'm fairly new to both ant and log4j so I could be making an obvious mistake but I'm just not seeing it. Here is my build.xml.
<?xml version="1.0"?>
<project name="pmml_export" default="archive">
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="dist" />
</target>
<path id="compile.classpath">
<fileset dir="build/classes" includes="*.class" />
</path>
<property name="ant.dir" value="apache-log4j-1.2.16"/>
<path id="classpath">
<fileset dir="${ant.dir}" includes="**/*.jar"/>
</path>
<target name="exceptions" depends="init">
<javac srcdir="src/exceptions" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Exceptions compiled! </echo>
</target>
<target name="symbol-table" depends="exceptions" >
<javac srcdir="src/translator/symbol_table" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Symbol table compiled! </echo>
</target>
<target name="parser" depends="symbol-table" >
<javac srcdir="src/translator/parser" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Parser compiled! </echo>
</target>
<target name="lexer" depends="parser" >
<javac srcdir="src/translator/lexer" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Lexer compiled! </echo>
</target>
<target name="translator" depends="lexer" >
<javac srcdir="src/translator" destdir="build/classes" classpathref="compile.classpath"/>
<echo> Translator compiled! </echo>
</target>
<target name="exporter" depends="translator" >
<javac srcdir="src/pmml_export" destdir="build/classes" classpathref="compile.classpath" />
<echo> Exporter compiled! </echo>
</target>
<target name="archive" depends="exporter" >
<property name="manifest.mf" location="dist/manifest.txt" />
<manifest file="${manifest.mf}" >
<attribute name="Main-Class" value="pmml_export.PMML_Export"/>
</manifest>
<jar destfile="dist/pmml_export.jar" manifest="${manifest.mf}"
basedir="build/classes" />
</target>
<target name="run" depends="archive">
<java jar="dist/pmml_exporter.jar" fork="true">
<classpath>
<path refid="classpath"/>
<path location="dist/pmml_exporter.jar"/>
</classpath>
</java>
</target>
</project>
When you use the -jar option, the -cp and -classpath options are ignored. The proper way to embed the classpath with the -jar option is to set a Class-Path directive in the jar's MANIFEST.MF file.