ant unable to make a war, it stops while compiling classes - ant

I have a build.xml file from which i was building war for three months. but currently it stops when it reaches at compling the code. my version of ant is 1.8. Last time i made war was on last friday evening and it was working fine that time.
here is my build.xml file
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Written By Waqas Sadiq on 14062011 -->
<project name="smi-core" default="all" basedir="..">
<property name="name" value="EchelonSurvey"/>
<property name="common.deploy" value="../deploy"/>
<property name="home.dir" value="./WebRoot"/>
<property name="src.dir" value="./src"/>
<property name="oi.dir" value="./openInviter"/>
<property name="as.dir" value="./about-us"/>
<property name="rr.dir" value="./ResponsesReport"/>
<property name="lib.dir" value="./WebRoot/WEB-INF/lib"/>
<property name="images.dir" value="./WebRoot/images"/>
<property name="tabcontent.dir" value="./WebRoot/tabcontent"/>
<property name="css.dir" value="./WebRoot/css"/>
<property name="js.dir" value="./WebRoot/js"/>
<property name="jsp.dir" value="./WebRoot/jsp"/>
<property name="config.web" value="./WebRoot/WEB-INF"/>
<property name="config.web.class" value="./WebRoot/WEB-INF/classes"/>
<property name="build.dir" value="build/buildoutput"/>
<property name="build.lib" value="${build.dir}/lib"/>
<property name="build.dest" value="${build.dir}/classes"/>
<property name="build.war.dir" value="${build.dir}/EchelonSurvey.war"/>
<property name="sampleapp.name" value="EchelonSurvey"/>
<property name="build.ship.dir" value="build/ship"/>
<property name="build.deploy.dir" value="./deploy"/>
<property name="option.debug" value="on"/>
<property name="option.optimize" value="off"/>
<property name="option.deprecation" value="on"/>
<property name="version" value="1.0"/>
<property name="vendor.name" value="Stafona"/>
<property name="deploy.dir" value="./deploy"/>
<target name="eclipse" if="eclipse.running">
<property name="build.compiler"
value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
</target>
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar"/>
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${build.lib}"/>
<mkdir dir="${build.dest}"/>
</target>
<target name="compile" depends="prepare">
<delete dir="${config.web.class}"/>
<mkdir dir ="${config.web.class}"/>
<copy todir="${config.web.class}">
<fileset dir="${src.dir}" excludes="**/*.java"/>
</copy>
<javac
destdir="${config.web.class}"
debug="${option.debug}"
optimize="${option.optimize}"
deprecation="${option.deprecation}"
includeantruntime="false"
>
<src path="${src.dir}"/>
<classpath refid="classpath"/>
</javac>
<javac
destdir="${build.dest}"
debug="${option.debug}"
optimize="${option.optimize}"
deprecation="${option.deprecation}"
>
<src path="${src.dir}"/>
<classpath refid="classpath"/>
</javac>
</target>
<target name="package-EchelonSurvey"
depends="compile" description="Generates the EchelonSurvey implementation JAR">
<jar destfile="${build.lib}/${name}.jar">
<fileset dir="${build.dest}">
<include name="**/**.class"/>
</fileset>
<manifest>
<attribute name="Built-By" value="${vendor.name}"/>
</manifest>
</jar>
</target>
<target name ="package-web-war" depends ="package-EchelonSurvey" description ="Generates war package">
<mkdir dir ="${build.war.dir}"/>
<mkdir dir ="${build.war.dir}/WEB-INF/classes"/>
<mkdir dir ="${build.war.dir}/WEB-INF/lib"/>
<mkdir dir ="${build.war.dir}/js"/>
<mkdir dir ="${build.war.dir}/jsp"/>
<mkdir dir ="${build.war.dir}/images"/>
<mkdir dir ="${build.war.dir}/css"/>
<copy todir="${build.war.dir}/WEB-INF">
<fileset dir="${config.web}">
<include name="*.xml"/>
<include name="*.log"/>
<include name="*.properties"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/images">
<fileset dir="${images.dir}">
<include name="**/**.*"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/tabcontent">
<fileset dir="${tabcontent.dir}">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/css">
<fileset dir="${css.dir}">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/js">
<fileset dir="${js.dir}">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/jsp">
<fileset dir="${jsp.dir}">
<include name="**/**.jsp"/>
<include name="*.html"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/WEB-INF/classes">
<fileset dir="${config.web.class}">
<include name="**/**.class"/>
<include name="**/**.xml"/>
<include name="**/**.properties"/>
</fileset>
</copy>
<copy todir="${build.war.dir}/WEB-INF/lib">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
<exclude name="EchelonSurvey.jar"/>
</fileset>
</copy>
<copy todir="${build.war.dir}">
<fileset dir="${home.dir}">
<include name="*.jsp"/>
<include name="*.properties"/>
<include name="*.html"/>
<include name="*.xml"/>
<include name="*.txt"/>
<include name="*.do"/>
</fileset>
</copy>
<jar jarfile ="${build.lib}/${sampleapp.name}.war" basedir ="${build.war.dir}">
<manifest>
<attribute name="Built-By" value="${vendor.name}"/>
</manifest>
</jar>
<copy todir="${deploy.dir}">
<fileset dir="${build.lib}">
<include name="*.war"/>
<include name="*.jar"/>
</fileset>
</copy>
<copy todir="${common.deploy}">
<fileset dir="${build.lib}">
<include name="*.war"/>
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="all" depends="package-web-war">
</target>
<target name="ship" depends="all" description="* Generates a .zip file">
</target>
<target name="cleanagain">
<delete dir="${build.dir}" />
</target>
</project>
and here is the output from this. I am running this on Ubunto with java 6 installed on it.
Buildfile: /var/tempproject/suleman/EchlonSurvey/build/build.xml
clean:
[delete] Deleting directory /var/tempproject/suleman/EchlonSurvey/build/buildoutput
prepare:
[mkdir] Created dir: /var/tempproject/suleman/EchlonSurvey/build/buildoutput/lib
[mkdir] Created dir: /var/tempproject/suleman/EchlonSurvey/build/buildoutput/classes
compile:
[delete] Deleting directory /var/tempproject/suleman/EchlonSurvey/WebRoot/WEB-INF/classes
[mkdir] Created dir: /var/tempproject/suleman/EchlonSurvey/WebRoot/WEB-INF/classes
[copy] Copying 39 files to /var/tempproject/suleman/EchlonSurvey/WebRoot/WEB-INF/classes
[copy] Copied 13 empty directories to 9 empty directories under /var/tempproject/suleman/EchlonSurvey/WebRoot/WEB-INF/classes
[javac] Compiling 225 source files to /var/tempproject/suleman/EchlonSurvey/WebRoot/WEB-INF/classes
Killed

Related

PMD ANT script gives taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="info" name="MyProject">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<property name="jar.name" value="${ant.project.name}"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="true" nowarn="true" debuglevel="lines,vars,source"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${jar.name}.jar" basedir="${classes.dir}">
<exclude name="**/Main.class" />
<fileset dir="${src.dir}" includes="**/*.java">
<exclude name="**/Main.java" />
</fileset>
<zipgroupfileset dir="${lib.dir}" includes="*.jar">
<exclude name="**/Utils.jar" />
</zipgroupfileset>
</jar>
</target>
<target name="build" depends="jar"/>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" />
<target name="pmd">
<pmd shortFilenames="true" failuresPropertyName="failures.count" rulesetfiles="\path\pmd\ruleSet.xml">
<formatter type="html" toFile="pmd_report.html" toConsole="true"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
<target name="info">
<echo message="Available Targets:"/>
<echo message=" clean"/>
<echo message=" compile"/>
<echo message=" jar"/>
<echo message=" build"/>
<echo message=" pmd"/>
</target>
</project>
This script gives me this " taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]"
I have added PMD library jar file in lib folder of the project,where other libraries are present as jar files.
But if i change add path ref to the library not as a jarfile , it works well.
<path id="pmd.classpath">
<fileset dir="C:\Users\PMD\pmd-bin-5.5.2">
<include name="**/*.jar"/>
</fileset>
</path>
May I know what is the problem? I am pretty new to ANT and PMD , any help will be appreciated.
Thanks
First thing to check is the file pmd-core-*.jar in your lib directory?
Secondly add a reference to the path in the taskdef task:
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="classpath"/>

build.xml:43 compile failed see compiler error output for details

I am trying to compile and build the source files into a jar file using ant from the command line. (windows 7)
However I am getting the following error:
....\build.xml:43: Compile failed see the copiler error output for details
My build file is given below:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="jar.client">
<!--Auto generated ant build file-->
<property environment="env"/>
<property name="axis2.home" value="${env.AXIS2_HOME}"/>
<property name="project.base.dir" value="."/>
<property name="maven.class.path" value=""/>
<property name="name" value="addtaxihire_14cabs"/>
<property name="src" value="${project.base.dir}/src"/>
<property name="test" value="${project.base.dir}/test"/>
<property name="build" value="${project.base.dir}/build"/>
<property name="classes" value="${build}/classes"/>
<property name="lib" value="${build}/lib"/>
<property name="resources" value="${project.base.dir}/resources"/>
<property value="" name="jars.ok"/>
<path id="axis2.class.path">
<pathelement path="${java.class.path}"/>
<pathelement path="${maven.class.path}"/>
<fileset dir="${axis2.home}">
<include name="lib/*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${lib}"/>
</target>
<target depends="init" name="pre.compile.test">
<!--Test the classpath for the availability of necesary classes-->
<available classpathref="axis2.class.path" property="stax.available" classname="javax.xml.stream.XMLStreamReader"/>
<available classpathref="axis2.class.path" property="axis2.available" classname="org.apache.axis2.engine.AxisEngine"/>
<condition property="jars.ok">
<and>
<isset property="stax.available"/>
<isset property="axis2.available"/>
</and>
</condition>
<!--Print out the availabilities-->
<echo message="Stax Availability= ${stax.available}"/>
<echo message="Axis2 Availability= ${axis2.available}"/>
</target>
<target depends="pre.compile.test" name="compile.src" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="compile.src" name="compile.test" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}">
<src path="${test}"/>
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="pre.compile.test" name="echo.classpath.problem" unless="jars.ok">
<echo message="The class path is not set right! Please make sure the following classes are in the classpath 1. XmlBeans 2. Stax 3. Axis2 "/>
</target>
<target depends="jar.server, jar.client" name="jar.all"/>
<target depends="compile.src,echo.classpath.problem" name="jar.server" if="jars.ok">
<copy toDir="${classes}/META-INF" failonerror="false">
<fileset dir="${resources}">
<include name="*.xml"/>
<include name="*.wsdl"/>
<include name="*.xsd"/>
</fileset>
</copy>
<jar destfile="${lib}/${name}.aar">
<fileset excludes="**/Test.class" dir="${classes}"/>
</jar>
</target>
<target if="jars.ok" name="jar.client" depends="compile.src">
<jar destfile="${lib}/${name}-test-client.jar">
<fileset dir="${classes}">
<exclude name="**/META-INF/*.*"/>
<exclude name="**/lib/*.*"/>
<exclude name="**/*MessageReceiver.class"/>
<exclude name="**/*Skeleton.class"/>
</fileset>
</jar>
</target>
<target if="jars.ok" depends="jar.server" name="make.repo">
<mkdir dir="${build}/repo/"/>
<mkdir dir="${build}/repo/services"/>
<copy file="${build}/lib/${name}.aar" toDir="${build}/repo/services/"/>
</target>
<target if="jars.ok" depends="make.repo" name="start.server">
<java fork="true" classname="org.apache.axis2.transport.http.SimpleHTTPServer">
<arg value="${build}/repo"/>
<classpath refid="axis2.class.path"/>
</java>
</target>
<target if="jars.ok" depends="compile.test" name="run.test">
<path id="test.class.path">
<pathelement location="${lib}/${name}-test-client.jar"/>
<path refid="axis2.class.path"/>
<pathelement location="${classes}"/>
</path>
<mkdir dir="${build}/test-reports/"/>
<junit haltonfailure="yes" printsummary="yes">
<classpath refid="test.class.path"/>
<formatter type="plain"/>
<batchtest fork="yes" toDir="${build}/test-reports/">
<fileset dir="${test}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
</project>
and probably the 43rd-45th lines of the build file are:
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
Thanks in advance for any solution/suggestion.
The problem is not in the build.xml. It's in your java code. This implies the message:
Compile failed see the compiler error output for details

Ant war and ear is not generating

I am new to this ant I wrote athe following build.xml file for generating war and ear. it is showing build successfull. but it not generating any war/ear file. I mentioned my script below. please help me what changes i have to do..
Thanks in advance....
<property name="src" value="src"/>
<property name="dst" value="web"/>
<property name="classes" value="WEB-INF/classes"/>
<property name="archiveName" value="medcardets"/>
<property name="archive" value="BuildArchive"/>
<fileset id="lib" dir="${dst}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset id="war.file" dir="/">
<include name="${archiveName}.war"/>
</fileset>
<fileset id="ear.file" dir="/">
<include name="${archiveName}.war"/>
</fileset>
<fileset id="lib.rules" dir="${dst}/WEB-INF/lib/rules">
<include name="*.jar"/>
</fileset>
<fileset id="lib.j2ee" dir="j2ee">
<include name="*.jar"/>
</fileset>
<target name="clear">
<delete dir="${dst}/${classes}"/>
<delete dir="${archive}"/>
</target>
<target name="build" depends="clear">
<mkdir dir="${dst}/${classes}"/>
<javac srcdir="${src}" destdir="${dst}/${classes}" debug="on" debuglevel="lines,vars,source">
<classpath>
<fileset refid="lib"/>
<fileset refid="lib.rules"/>
<fileset refid="lib.j2ee"/>
</classpath>
</javac>
<copy todir="${dst}/${classes}">
<fileset dir="${src}">
<exclude name="**/CVS"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
Your question implies that you have written code that you expect to generate a WAR, but you have no instruction to do so. I see from your comment you are actually asking what the command should be.
Most important: I hope we are all new to things, after 35 years in the industry I learn something every day. Why did you ask the question rather than google? Learning to search is the most important skill. Google ant task WAR gives this task with an example:
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
and a similar entry for EAR:
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war"/>
</ear>

having several directories for libs in ant

How can I show Ant that libraries exist in two different directories?
Right now I have
<property name="lib" value="C:/apache-ant-1.8.4/lib" />
<target name="compile" depends="init">
<javac source="1.6" srcdir="${src}" fork="true" destdir="${bin}" encoding="UTF-8" >
<classpath>
<pathelement path="${bin}">
</pathelement>
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
It's fine if I copy all the libs to the ant \lib folder. How can I show Ant that there are two directories with libraries?
Just add another fileset:
<property name="lib" value="C:/apache-ant-1.8.4/lib" />
<property name="otherLib" value="C:/somePath/lib" />
<target name="compile" depends="init">
<javac source="1.6" srcdir="${src}" fork="true" destdir="${bin}" encoding="UTF-8" >
<classpath>
<pathelement path="${bin}" />
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${otherLib}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>

Ant for EJB project

I am trying to make an ant script for an EJB project. I am using Jboss for this.
I am new to both EJB and Ant and am having problems in getting the beans to compile from ant. It gives me number of errors of the kind
package javax.persistence does not exist
#MappedSuperclass - Cannot find symbol
I created it as an eclipse project initially, and added the jboss runtime through eclipse. Do I need to copy all the jars in a lib folder and include them in the classpath for the beans to compile or is there a better way to do this?
Try setting classpath in Ant appropriately. It ignores any system CLASSPATH or Eclipse setting that you have.
Here's an Ant build.xml that you can start with:
<?xml version="1.0" encoding="UTF-8"?>
<project name="spring-finance" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src/main/java"/>
<property name="production.lib" value="src/main/webapp/WEB-INF/lib"/>
<property name="production.resources" value="src/main/resources"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="src/test/java"/>
<property name="test.lib" value="src/test/lib"/>
<property name="test.resources" value="src/test/resources"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="web.src" value="src/main/webapp"/>
<property name="web.lib" value="${web.src}/WEB-INF/lib"/>
<property name="web.classes" value="${web.src}/WEB-INF/classes"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="test" description="run all unit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<target name="exploded" description="create exploded deployment" depends="test">
<copy todir="${exploded}">
<fileset dir="${web.src}"/>
</copy>
<copy todir="${exploded}/WEB-INF">
<fileset dir="${web.src}/WEB-INF"/>
</copy>
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="jar" description="create jar file" depends="test">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
<target name="war" description="create war file" depends="exploded">
<war basedir="${exploded}" webxml="${exploded}/WEB-INF/web.xml" destfile="${out}/${ant.project.name}.war"/>
</target>
<target name="package" description="create package for deployment" depends="test">
<antcall target="war"/>
</target>
</project>

Resources