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
Related
According to the training task, I need to create .jar-file with ant. There are no problems with the Assembly of ordinary classes that are in src .
But I have in project present logger, libraries to him and .properties file.
because of this, errors fly out:
[javac] error: package org.apache.logging.log4j does not exist
and
error: cannot find symbol
[javac] error: private static final Logger logger = LogManager.getLogger(Hello.class);
I have build.xml
<?xml version="1.0"?>
<project name="Runner" default="run">
<!-- define names of directories -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="classes" location="${build}/classes"/>
<!-- define all targets -->
<target name="compile">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" includeAntRuntime="false"/>
</target>
<target name="run" depends="compile">
<java classname="${ant.project.name}" classpath="${classes}"/>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
<target name="package" depends="compile">
<jar destfile="${build}/${ant.project.name}.jar" basedir="${classes}">
<manifest>
<attribute name="Main–Class" value="${ant.project.name}"/>
</manifest>
</jar>
</target>
</project>
and this stracture
How and where to gather library and property in Java file to jar-file was executable?
I figured it out.
<path id="classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="init" depends="clean" description="starts">
<tstamp/>
</target>
<target name="clean" depends="package-to-jar" description="clean up">
<delete dir="${classes}"/>
<delete file="${external-lib}"/>
</target>
<target name="package-to-jar" depends="package-external-lib" description="packing all project into a jar-file">
<jar destfile="${jar}/${ant.project.name}.jar" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<zipfileset src="${external-lib}"/>
</jar>
<delete dir="${classes}"/>
<delete file="${external-lib}"/>
</target>
<target name="package-external-lib" depends="compile" description="packing external libraries into a jar-file">
<jar destfile="${external-lib}">
<zipgroupfileset dir="${lib}">
<include name="**/*.jar"/>
</zipgroupfileset>
</jar>
</target>
<target name="compile" description="compile the source">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" classpathref="classpath"/>
<copy todir="${classes}">
<fileset dir="${src}" excludes="**/*.java"/>
</copy>
</target>
Firstly you need include required library folders to class path
<path id="class.path">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
and add reference to javac task in compile target
<target name="compile">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" includeAntRuntime="false">
<classpath refid="class.path" />
</javac>
</target>
aftewards include all properties file to jar
<target name="package" depends="compile">
<jar destfile="${build}/${ant.project.name}.jar" basedir="${classes}">
<include name="*.properties"/>
<manifest>
<attribute name="Main–Class" value="${ant.project.name}"/>
</manifest>
</jar>
</target>
I would like to obfuscate my pure Java library but I am not sure how to use dexguard in my and build.xml file. Can somebody show me an example? My current code is following:
<property file="build.properties"/>
<taskdef resource="build.properties"
classpath="dexguard.jar" />
<target name="build">
<antcall target="clean"/>
</target>
<target name="clean">
<delete dir="build"/>
<antcall target="compile"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
<antcall target="jar"/>
</target>
<target name="jar" >
<mkdir dir="build/jar"/>
<jar destfile="build/jar/testlib.jar" basedir="build/classes">
</jar>
<antcall target="obfuscate"/>
</target>
<target name="obfuscate"
description="Obfuscate compiled classes">
<dexguard>
-libraryjars "dexguard.jar"
-injars build/jar/testlib.jar
-outjars build/jar/testlib_obf.jar
</dexguard>
<target name="run">
<java jar="build/jar/testlib.jar" fork="true"/>
</target>
Use Gradle.
task obfDexguard(type: com.guardsquare.dexguard.gradle.DexGuardTask) {
configuration 'dexguard.txt'
injars "build/jar/testlib.jar"
outjars "build/jar/testlib_obf.jar"
}
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 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"/>
I am using ant to build my war to deploy it. But ant builds the war as a file "webapp.war". I need to build it as a folder "webapp.war" how can I do it using ant?
<target name="war" depends="compile">
<war destfile="dist/AntExample.war"
webxml="WebContent/WEB-INF/web.xml" keepcompression="false">
<fileset dir="WebContent"/>
<lib dir="WebContent/WEB-INF/lib"/>
<classes dir="build/classes"/>
</war>
</target>
try this...works for me
<target name="war" depends="compile">
<war destfile="dist/deployme_temp.war" webxml="web/WEB-INF/web.xml">
<fileset dir="web"/>
<lib dir="web/WEB-INF/lib"/>
<classes dir="build/classes"/>
</war>
</target>
<target name="unzip" depends="war">
<unzip src="dist/deployme_temp.war" dest="dist/deployme.war" />
</target>
<target name="copy-war" depends="unzip">
<copy todir="${deploy.destination}/deployme.war" overwrite="true">
<fileset dir="dist/deployme.war"/>
</copy>
</target>
try copy task (assume you are using Eclipse Dynamic Web Project layout):
<property name="dist" location="webapp.war"/>
<target name="war folder" depends="compile" description="generate the distribution" >
<mkdir dir="${dist}/WEB-INF/classes"/>
<copy todir="${dist}">
<fileset dir="WebContent"/>
</copy>
<copy todir="${dist}/WEB-INF/classes">
<fileset dir="yourClassDir"/>
</copy>
<!-- other stuff to copy-->
</target>