Using Ant To Build War As a Folder - java

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>

Related

How to build jar-file with ant?

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>

Error running apt compiler in Java 1.8 version

I am beginner and its Java legacy applications,I am trying to build this application using Ant but its getting build only with java version 6 but when i build it with java 8 version i am getting below Error can some one suggest me please?
I am unable to resolve it since 2 weeks please suggest some one.
build.xml
<project name="CDMWeb" default="cdmwebweblogic.war" basedir=".">
<!-- ========================================================================================= -->
<!-- CDMWeb APPLICATION ANT BUILD FILE -->
<!-- ========================================================================================= -->
<!-- ***************************************************************** -->
<!-- #author : Muhammad Azeem -->
<!-- #date : 10/16/2008 -->
<!-- #description : Ant Build file for CDMWeb Application. -->
<!-- ***************************************************************** -->
<!-- ============================= START CDMWeb BUILD =================================== -->
<property environment="env" />
<import file="resource/apache-beehive-1.0.2\beehive-imports.xml"/>
<import file="resource/apache-beehive-1.0.2\ant\beehive-tools.xml"/>
<property name="build.dir" location="build"/>
<property name="libs" value="web/WEB-INF/lib"/>
<property name="webapp.dir" location="${basedir}/web"/>
<property name="web.dir" location="${basedir}/web"/>
<property name="tmp.sourcegen.dir" value=".tmpbeansrc"/>
<property name="dist.dir" location="${basedir}/dist"/>
<property name="exploded.dir" location="${dist.dir}/CDMWeb.war"/>
<property name="mqapp.dir" location="${build.dir}/mqapp.war"/>
<property name="explodedmqwebapp.dir" location="${exploded.dir}/MQWeb.war/"/>
<!-- BGW RT interface related Properties -->
<property name="bgw.final.dir" location="${exploded.dir}/WEB-INF/lib" />
<property name="bgw.dir" location="src/bgw"/>
<property name="bgw.build.dir" location="${build.dir}/bgw"/>
<property name="bgw.stager" location="${bgw.dir}/BGWStager"/>
<property name="bgw.stager.generated" location="${bgw.stager}/generated"/>
<property name="bgw.extractor" location="${bgw.dir}/BGWEventExtractor"/>
<property name="bgw.sqlrunner" location="${bgw.dir}/SqlRunner"/>
<property name="bgw.build.stager.dir" location="${bgw.build.dir}/stager"/>
<property name="bgw.build.extractor.dir" location="${bgw.build.dir}/extractor"/>
<property name="bgw.build.extractor.dir" location="${bgw.build.dir}/sqlrunner"/>
<property name="bgw.stager.notification.pkg.name" value="com.verizon.vi.bgw.notification"/>
<property name="bgw.stager.notification.pkg.dir" value="${bgw.stager.generated}/com/verizon/vi/bgw/notification"/>
<!-- Define the classpath used to build the BGW Stager and extractor app -->
<property name="bgw.stager.classpath" value="lib/mail.jar lib/ifxjdbc.jar lib/cem_client.jar lib/cdm_data_dictionary.jar lib/ojdbc6_11.2.0.3.jar"/>
<property name="bgw.extractor.classpath" value="lib/jaas.jar lib/jtds.jar lib/mail.jar lib/ifxjdbc.jar lib/cem_client.jar lib/log4j.jar lib/jta-spec1_0_1.jar lib/jms.jar lib/bgw_vi.jar lib/namespace.jar lib/cdm_data_dictionary.jar lib/BaaisIntfUtils.jar lib/weblogic.jar"/>
<property name="bgw.sqlrunner.classpath" value="lib/ifxjdbc.jar lib/log4j.jar lib/ojdbc6_11.2.0.3.jar"/>
<!-- Define the classpath used to build the app -->
<path id="app.classpath">
<fileset dir="${libs}">
<include name="*.jar"/>
</fileset>
</path>
<path id="webapp.classpath">
<pathelement location="${servlet-api.jar}"/>
<pathelement location="${jsp-api.jar}"/>
<pathelement location="${build.dir}/WEB-INF/classes"/>
<fileset dir="${libs}">
<include name="*.jar"/>
</fileset>
</path>
<path id="webapp.sourcepath">
<pathelement location="${web.dir}"/>
<pathelement location="${web.dir}/src"/>
</path>
<taskdef name="xjc" classpathref="app.classpath" classname="com.sun.tools.xjc.XJCTask"></taskdef>
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="init">
<mkdir dir="${build.dir}/WEB-INF/classes"/>
</target>
<target name="compile.dbgen">
<echo message="[ * --- Compiling dbgen --- * ]"/>
<javac destdir="${build.dir}/WEB-INF/classes" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="dbgen/src"/>
</javac>
</target>
<target name="compile.src">
<echo message="[ * --- Compiling src --- * ]"/>
<javac destdir="${build.dir}/WEB-INF/classes" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="src/com"/>
</javac>
</target>
<target name="compile.web">
<echo message="[ * --- Compiling web --- * ]"/>
<javac destdir="${build.dir}/WEB-INF/classes" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="web/src"/>
</javac>
</target>
<target name="compile.all" depends="init,compile.dbgen,compile.src,compile.web">
<echo message="[ * --- Compiled dbgen,src,web --- * ]"/>
</target>
<target name="copy.web">
<copy todir="${build.dir}/WEB-INF/lib">
<fileset dir="web/WEB-INF/lib">
<include name="*.*"/>
<exclude name="weblogic.jar"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="web/WEB-INF">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.dir}">
<fileset dir="web">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.dir}">
<fileset dir="web">
<include name="**/*.*"/>
<exclude name="src/**"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF/classes">
<fileset dir="resource">
<include name="*.properties"/>
<include name="*.xml"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="resource/beans">
<include name="cdm*.xml"/>
</fileset>
</copy>
</target>
<target name="deploy-beehive" description="Copy the Beehive Page Flow rutime into the target webapp">
<deploy-netui webappDir="${build.dir}"/>
</target>
<target name="compile.jpf" depends="deploy-beehive" description="Build the webapp">
<available property="webapp.dir.available" file="${webapp.dir}" type="dir"/>
<fail unless="webapp.dir.available" message="Can't find the webapp directory ${webapp.dir}"/>
<!-- compile JPFs -->
<echo>Building Page Flows</echo>
<build-pageflows srcdir="${basedir}/web"
webcontentdir="${web.dir}"
destdir="${build.dir}/WEB-INF/classes"
tempdir="${build.dir}/${tmp.sourcegen.dir}"
sourcepathref="webapp.sourcepath"
classpathref="webapp.classpath"/>
</target>
<target name="build" depends="compile.all,copy.web,compile.jpf">
</target>
<target name="buildwar" depends="build" description="Builds a compressed WAR file that can be deployed to Tomcat application container">
<echo message="[ * --- Creating WAR file for Deployment into Tomcat--- * ]"/>
<mkdir dir="${dist.dir}"/>
<war destfile="${dist.dir}/CDMWeb.war" webxml="${build.dir}/WEB-INF/web.xml">
<fileset dir="${build.dir}">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="cdmweb.war" depends="clean,init,build,buildwar">
</target>
<!-- ===================== BGW Stager and Extractor Build - BEGIN ======================= -->
<target name="bgw.build" depends="bgw.init,bgw.build.stager,bgw.build.extractor,bgw.build.sqlrunner,copy.bgw,bgw.clean">
<echo message="[ * --- Created BGWStager.jar and BGWEventExtractor.jar Successfully...."/>
</target>
<!-- Creation of BGW Stager and extractor related directories -->
<target name="bgw.init">
<mkdir dir="${bgw.stager.generated}"/>
<mkdir dir="${bgw.build.dir}"/>
<mkdir dir="${bgw.build.stager.dir}"/>
<mkdir dir="${bgw.build.extractor.dir}"/>
<mkdir dir="${bgw.build.sqlrunner.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<!-- Clean up of BGW Stager and extractor related directories -->
<target name="bgw.clean">
<delete dir="${bgw.stager.generated}"/>
<delete dir="${bgw.build.dir}"/>
<delete dir="${bgw.build.stager.dir}"/>
<delete dir="${bgw.build.extractor.dir}"/>
<delete dir="${bgw.build.sqlrunner.dir}"/>
<!-- If this causes issues may need to move the orginal dest -->
<delete file="${dist.dir}/BGWStager.jar"/>
<delete file="${dist.dir}/BGWEventExtractor.jar"/>
<delete file="${dist.dir}/SqlRunner.jar"/>
</target>
<!-- XJC for creating Java classes for BGW Notification schema -->
<target name="bgw.compile.schema.prepare">
<echo message="Started XJC Compilation of BGW Notification" />
<xjc schema="${bgw.stager}/xml-resources/jaxb/BGWNotification/bgwNotification.xsd" package="${bgw.stager.notification.pkg.name}" destdir="${bgw.stager.generated}">
<produces dir="${bgw.stager.notification.pkg.dir}" />
</xjc>
</target>
<!-- Compilation of Generated BGW Notification Java Classes. -->
<target name="bgw.compile.schema" depends="bgw.compile.schema.prepare">
<echo message="Started Compiling generated BGW Notification" />
<javac destdir="${bgw.build.stager.dir}" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="${bgw.stager.generated}"/>
</javac>
</target>
<!-- BGW Stager Soruces Compilation -->
<target name="bgw.compile.stager" depends="bgw.compile.schema">
<echo message="[ * --- Compiling BGW Stager --- * ]"/>
<javac destdir="${bgw.build.stager.dir}" classpathref="app.classpath" classpath="${bgw.build.stager.dir}" debug="on" debuglevel="lines,source">
<src path="${bgw.stager}/src"/>
</javac>
</target>
<!-- BGW Stager Build -->
<target name="bgw.build.stager" depends="bgw.compile.stager">
<echo message="[ * --- Preparing BGW Stager jar --- * ]"/>
<jar jarfile="${dist.dir}/BGWStager.jar"
basedir="${bgw.build.stager.dir}">
<include name="**/*.class"/>
<manifest>
<attribute name="Main-class" value="com.verizon.vi.bgw.stager.StagerMain"/>
<attribute name="Class-Path" value="${bgw.stager.classpath}"/>
</manifest>
</jar>
</target>
<!-- BGW extractor Soruces Compilation -->
<target name="bgw.compile.extractor">
<echo message="[ * --- Compiling extractor --- * ]"/>
<javac destdir="${bgw.build.extractor.dir}" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="${bgw.extractor}/src"/>
</javac>
</target>
<!-- BGW extractor Build -->
<target name="bgw.build.extractor" depends="bgw.compile.extractor">
<echo message="[ * --- Preparing BGW extractor jar --- * ]"/>
<jar jarfile="${dist.dir}/BGWEventExtractor.jar"
basedir="${bgw.build.extractor.dir}">
<include name="**/*.class"/>
<manifest>
<attribute name="Main-class" value="com.verizon.vi.bgweventextractor.ExtractorMain"/>
<attribute name="Class-Path" value="${bgw.extractor.classpath}"/>
</manifest>
</jar>
</target>
<!-- BGW SQLRunner Soruces Compilation -->
<target name="bgw.compile.sqlrunner">
<echo message="[ * --- Compiling extractor --- * ]"/>
<javac destdir="${bgw.build.sqlrunner.dir}" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="${bgw.sqlrunner}/src"/>
</javac>
</target>
<!-- BGW extractor Build -->
<target name="bgw.build.sqlrunner" depends="bgw.compile.sqlrunner">
<echo message="[ * --- Preparing BGW SQLRunner --- * ]"/>
<jar jarfile="${dist.dir}/SqlRunner.jar"
basedir="${bgw.build.sqlrunner.dir}">
<include name="**/*.class"/>
<manifest>
<attribute name="Main-class" value="sqlrunner.SqlMain"/>
<attribute name="Class-Path" value="${bgw.sqlrunner.classpath}"/>
</manifest>
</jar>
</target>
<target name="copy.bgw">
<copy todir="${bgw.final.dir}">
<fileset dir="${dist.dir}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="cdmwebweblogic.war" depends="clean,init,buildweblogic,buildweblogicwar,mqweblogicapp.war,bgw.build">
</target>
<target name="buildweblogic" depends="compile.all,copyweblogic.web,compile.jpf">
</target>
<target name="copyweblogic.web">
<copy todir="${build.dir}/WEB-INF/lib">
<fileset dir="web/WEB-INF/lib">
<include name="*.*"/>
<exclude name="weblogic.jar"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="web/WEB-INF">
<include name="*.*"/>
</fileset>
</copy>
<!--<move file="${build.dir}/WEB-INF/web_weblogic.xml" tofile="${build.dir}/WEB-INF/web.xml"/>-->
<echo>
web.xml:Replacing cdm-app-context.xml with cdm-app-context_weblogic.xml
</echo>
<replace file="${build.dir}/WEB-INF/web.xml" token="cdm-app-context.xml" value="cdm-app-context_weblogic.xml"/>
<copy todir="${build.dir}">
<fileset dir="web">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.dir}">
<fileset dir="web">
<include name="**/*.*"/>
<exclude name="src/**"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF/classes">
<fileset dir="resource">
<include name="*.properties"/>
<exclude name="jndi.properties"/>
<exclude name="*.xml"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="resource/beans">
<include name="cdm*.xml"/>
</fileset>
</copy>
</target>
<target name="buildweblogicwar" depends="buildweblogic" description="Builds a exploded WAR Directory that can be deployed to Weblogic application container">
<echo message="[ * --- Creating Exploded WAR Directory for Deployment into Weblogic--- * ]"/>
<mkdir dir="${exploded.dir}"/>
<copy todir="${exploded.dir}">
<fileset dir="${build.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<!-- ============================= Above enclosed tasks are for Weblogic alone =================================== -->
<target name="usage" description="Print usage information for this build file">
<echo>
To Create the CDM web deployment WAR:ant cdmweb.war
The WAR gets created in dist directory.
Once the webapp is built, it's ready to deploy onto your application container.
</echo>
</target>
<target name="mqweblogicapp.war" depends="buildmqweblogicwar">
</target>
<target name="mqwebapp.war" depends="buildmqwar">
</target>
<target name="buildmq" depends="cleanmq,initmq,compile.mq,copy.mq">
<echo message="[ * --- Compiled compile.mq --- * ]"/>
</target>
<target name="initmq">
<mkdir dir="${mqapp.dir}/WEB-INF/classes"/>
</target>
<target name="cleanmq">
<delete dir="${mqapp.dir}"/>
</target>
<target name="copy.mq">
<mkdir dir="${mqapp.dir}/WEB-INF/lib"/>
<copy todir="${mqapp.dir}/WEB-INF/lib">
<fileset dir="web/WEB-INF/lib">
<include name="connector.jar"/>
<include name="jta.jar"/>
<include name="com.ibm.mq.jar"/>
<include name="com.ibm.mqjms.jar"/>
<include name="dhbcore.jar"/>
<include name="log4j-1.2.15.jar"/>
</fileset>
</copy>
<copy todir="${mqapp.dir}/WEB-INF/classes">
<fileset dir="resource">
<include name="mq.properties"/>
</fileset>
</copy>
<copy todir="${mqapp.dir}/WEB-INF">
<fileset dir="web/WEB-INF">
<include name="web_mq.xml"/>
</fileset>
</copy>
<move file="${mqapp.dir}/WEB-INF/web_mq.xml" tofile="${mqapp.dir}/WEB-INF/web.xml"/>
</target>
<target name="compile.mq">
<echo message="[ * --- Compiling mq related classes--- * ]"/>
<javac destdir="${mqapp.dir}/WEB-INF/classes" includes = "com/vzb/ions/common/mq/*.java" classpathref="app.classpath" debug="on" debuglevel="lines,source">
<src path="src"/>
</javac>
</target>
<target name="buildmqwar" depends="buildmq" description="Builds a compressed WAR file that can be deployed to Tomcat application container">
<echo message="[ * --- Creating MQ WAR file for Deployment into Tomcat--- * ]"/>
<mkdir dir="${dist.dir}"/>
<war destfile="${dist.dir}/MQWeb.war" webxml="${mqapp.dir}/WEB-INF/web.xml">
<fileset dir="${mqapp.dir}">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="buildmqweblogicwar" depends="buildmq" description="Builds a exploded WAR Directory that can be deployed to Weblogic application container">
<echo message="[ * --- Creating Exploded MQWeb.WAR Directory for Deployment into Weblogic--- * ]"/>
<mkdir dir="${explodedmqwebapp.dir}"/>
<copy todir="${explodedmqwebapp.dir}">
<fileset dir="${mqapp.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
</project>
beehive-tools.xml
<apt srcdir="#{srcdir}"
destdir="#{destdir}"
gendir="#{tempdir}"
classpathref="_pageflow.build.classpath"
sourcepathref="#{sourcepathref}"
srcExtensions="*.jpf,*.jpfs,*.app,*.jsfb,*.java"
processorOptions="web.content.root=#{webcontentdir}"
debug="true"
nocompile="#{nocompile}"/>//This line i am getting error
<delete dir="#{tempdir}"/>
BUILD FAILED
C:\Spring Boot\Jagan Apps\vi_cdm\build.xml:145: The following error occurred while executing this line:
C:\Spring Boot\Jagan Apps\vi_cdm\resource\apache-beehive-1.0.2\ant\beehive-tools.xml:148: Error running apt compiler
I answered this in your other question : How to run ant apt task on java 1.8 version
Essentially apt doesn't exist in java8; only in 5-7. This is documented on ant's apt documentation page...
Just make sure that the jar file that is required for your custom annotation processor stuff is in the classpath; and javac will execute it appropriately.
<javac source="${javac.version}" target="${javac.version}" destdir="${classes.build.dir}" srcdir="${src.dir}" debug="on" debuglevel="source,lines">
<classpath>
<!-- make sure this has "my-annotation-processor.jar" -->
<path refid="main.classpath"/>
</classpath>
</javac>

How to get rid of lib from classpath ANT TESTNG ECLIPSE

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

Ant Classpath Error When Unzipping Input File Java

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

Ant+Junit works on first run and never again

Hey guys I've been trying all day to get an ant file to automatically build my project. The file (appended below) was on a web page I found and is pretty thorough.
My problem is that it works as long as I don't run the "clean" target. Once the I run the "clean" target the "test" target ceases to work. I get NoClassFound errors on all test classes. Even though it worked earlier.
I'm working on a Macbook (10.5.8) using the latest version of eclipse. This error occurs running the file from eclipse and from a terminal using Ant version 1.7.1
I modified the file slightly to adapt it to my file structure which is as follows:
src/
packageA.packageB/
ClassA.java
...
ClassN.java
unittests/
packageA.packageB/
AllClassTests.java
ClassATest.java
...
ClassNTest.java
lib/
junit-4.7.jar
The ant file is:
<project name="SampleJUnitTests" default="dist" basedir=".">
<description>
DataTypes Build File
</description>
<!-- set global properties for this build -->
<property name="project_name" value="DataTypes"/>
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>
<property name="lib" location="lib"/>
<property name="reports" location="reports"/>
<property name="tests" location="unittests"/>
<property name="tmp" location="tmp_file"/>
<!-- the names of various distributable files -->
<property name="jar_name" value="${project_name}.jar"/>
<property name="war_name" value="${project_name}.war"/>
<!-- top level targets -->
<target name="compile" depends="init" description="compile the source code " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distributable files " >
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jar_name}" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
<delete dir="${tmp}"/>
</target>
<target name="run-tests" depends="compile" description="run your test suite" >
<junit printsummary="yes" haltonfailure="no" showoutput="yes" tempdir="${tmp}">
<classpath>
<pathelement path="${build}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="${tests}">
<include name="**/*.java"/>
<exclude name="**/All*Tests.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name ="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>
<target name ="run" depends="" description="if this project can be run, run it" >
</target>
<!-- supporting targets -->
<target name="init" description="initialize the build environment" >
<!-- Create the time stamp -->
<tstamp/>
<!-- Create directory structures -->
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
<mkdir dir="${tmp}"/>
</target>
<target name="all" depends="clean, test">
</target>
I give up and hope that someone can shine a light on my problem.
Thanks a lot!
You haven't got any Ant target which builds the test classes. You could do this as part of the compile target if you wanted:
<target name="compile" depends="init" description="compile the source code " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
<javac srcdir="${tests}" destdir="${build}">
<classpath>
<pathelement path="${build}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>

Categories