Ant task "javac" was successful but doesn't produce any output - ant

I'm trying to compile a project using ant. I guess the "javac" task was successful as i can see the following message on the console:
[javac] Compiling 151 source file to /var/lib/jenkins/jobs/project1/workspace/build
Here is the complete output of the command "ant compile"
clean:
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/build
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/docs
[delete] Deleting directory /var/lib/jenkins/jobs/project1/workspace/dist
makedir:
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/build
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/docs
[mkdir] Created dir: /var/lib/jenkins/jobs/project1/workspace/dist
compile:
[javac] /var/lib/jenkins/jobs/project1/workspace/build.xml:43: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 151 source file to /var/lib/jenkins/jobs/project1/workspace/build
BUILD SUCCESSFUL
Total time: 1 second
The problem is there is nothing produced in the folder "build" !
I'm using the same build.xml template file in other projects and it works very well, but here i can't understand why i can't find the compiled sources in the build folder.
Please help.
Here is my build.xml file:
<?xml version="1.0"?>
<project name="project1" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="lib.dir" location="WebContent/WEB-INF/lib" />
<property name="server.common.lib.dir" location="/home/ghali/jboss-5.1.0.GA/common/lib" />
<property name="server.lib.dir" location="/home/ghali/jboss-5.1.0.GA/lib" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${server.common.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${server.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code -->
<target name="compile" depends="clean, makedir">
<javac destdir="${build.dir}" classpathref="build.classpath" debug="true">
<src path="${src.dir}" />
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="package" depends="compile">
<war destfile="${dist.dir}/project1.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<lib dir="WebContent/WEB-INF/lib" />
<classes dir="${build.dir}" />
</war>
</target>
<target name="main" depends="compile, package, docs">
<description>Main target</description>
</target>
</project>

Related

TestNg/Selenium call by ant always return Cannot find class in the classpath

I'm pretty new with this setup. And having issue to call my project with TestNG by ant.
I can run the testng.xml without any problem in Eclipse but I alway receive Cannot find class in classpath by ant.
Build.xml
<project basedir="." default="runTest" name="Ant file for TestNG">
<property name="src" location="src" />
<property name="bin" location="bin" />
<property name="telus" location="C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\resources\suite\local" />
<property name="libs" location="lib" />
<path id="class.path">
<pathelement location="${libs}/testng-6.4.jar" />
<pathelement location="${libs}/selenium-java-client-driver.jar" />
<pathelement location="${libs}/selenium-server-standalone-2.39.0.jar" />
<pathelement location="${bin}"/>
<pathelement location="${telus}"/>
</path>
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="${libs}/testng-6.4.jar"/>
</classpath>
</taskdef>
<target name="runTest">
<echo message="mkdir"/>
<mkdir dir="testng_output"/><!-- Create the output directory. -->
<echo message= "TestNg Start"/>
<testng outputdir="testng_output" classpathref="class.path">
<xmlfileset dir="${telus}" includes="testng.xml"/>
<!-- <xmlfileset dir="." includes="TestNG2.xml"/> -->
</testng>
</target>
</project>
Testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Bolt harness QA" verbose="1">
<parameter name="test.env" value="qa" />
<parameter name="selenium.url" value="https://www.google.com" />
<!-- Valid values for browser: FF, IE, Chrome -->
<parameter name="selenium.browser" value="Chrome" />
<listeners>
<listener class-name="com.gdo.test.integration.listener.SoftAssertTestListener" />
</listeners>
<test name="Test_MS_Website" preserve-order="true">
<classes>
<class name="com.gdo.telus.SC006">
<methods>
<include name="Web_InvalidPassword" />
<exclude name="Web_LockedAccount" />
</methods>
</class>
</classes>
</test>
</suite>
My Class are at this path :
C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\java\com\gdo\telus
Thanks for your help.
Try my build.xml file, I did add the ReportNG plugin into this build.xml file to generate better looking reports instead of the default TestNG reports. You can just download the jar file for ReportNG and place it into your lib folder and it should still work fine:
<project name="Some Bullshit Goes Here" default="clean" basedir=".">
<!-- Initilization properties -->
<!-- <property name="lib.dir" value="${basedir}/lib"/> -->
<!-- using the ${basedir} allows you to use relative paths. It will use the working directory and add folders that you specify -->
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="hardcoded value can go here"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="bin.dir" value="${basedir}/bin"/>
<property name="output.dir" value="${basedir}/output"/>
<!-- I chose to hardcode the location where my jar library files will be, it will be used for compilation. Again you can set relative path if you wish.-->
<path id="assloadoflibs">
<fileset dir="/automated/tests/library">
<include name="*.jar"/>
</fileset>
<pathelement path="${basedir}/bin"/>
</path>
<!-- setting libraries -->
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/"/>
<fileset dir="/automated/tests/library" includes="*.jar"/>
</path>
<!-- Convert jar collection from a given reference into one list, storing the result into a given property, separated by colon -->
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<target name="loadTestNG" depends="setClassPath">
<!-- Creating task definition for TestNG task -->
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<!-- Creating build directory structure used by compile -->
<mkdir dir="${build.dir}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<!-- In compile target dependency is given over clean target followed by init,
this order makes sure that build directory gets created before compile takes place
This is how a clean complile is achieved.
-->
<target name="compile" depends="clean,init,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling..."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<target name="run" depends="compile">
<!-- testng classpath has been provided reference of jar files and compiled classes
this will generate report NG report.
-->
<testng classpath="${test.classpath}:${build.dir}" outputdir="${basedir}/output" haltonfailure="false" useDefaultListeners="true" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter" classpathref="reportnglibs">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
<!-- This value here will show the title of the report -->
<sysproperty key="org.uncommons.reportng.title" value="Example Test Report"/>
</testng>
</target>
</project>
Here is my TestNG.xml file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Example Test Suite">
<test name ="Example TestCase Name">
<classes>
<class name="packageName.JavaFilename"></class>
</classes>
</test>
</suite>
I've found my answer on this site. I need to use maven to call my solution.
http://rationaleemotions.wordpress.com/2012/05/14/continuous-integration-with-selenium/
but thanx anyway for your help

Compiled classes are not included in generated Jar

I am creating a jar bundle using ant build script. The problem is that the .class files are not included in the generated .jar file. I have also tried the {build.dest} in making the jar, but with no effect.
remaining all the files i require are in .jar file.
Here is my build script
<?xml version="1.0"?>
<project name="TaskNodeBundle" default="all" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="bundlename" value="task-node-bundle" />
<property name="src.dir" location="../src" />
<property name="lib.dir" location="../lib" />
<property name="build.dir" location="/buildoutput" />
<property name="build.dest" location="../build/dest" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<!-- Deletes the existing build directory -->
<target name="mkdir" depends="clean">
<mkdir dir="${build.dest}"/>
</target>
<!-- Compiles the java code -->
<target name="compile" depends="mkdir">
<javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
</target>
<target name="package-bundle" depends="compile" description="Generates the bundle" >
<jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
</target>
<target name="all" depends="package-bundle">
</target>
</project>
Firstly, what do you mean by "tried {build.dest} in making the jar"?
Whatever, you need to take a look at this part of your build:
<jar destfile="${build.dest}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
You compiled class files are in ${build.dest}, so you should use ${build.dest} as the root dir for the nested <fileset> of the <jar> task. But now you are pointing the <fileset> to your source code folder.
You should avoid putting the generated jar file in the same directory where the class files are. For example, you can put the jar in ${dist.dir}, which is another directory.
So try this:
You have a property:
<property name="dist.dir" value="../build/dist" />
And then,
<jar destfile="${dist.dir}/${bundlename}.jar" manifest="${src.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.dest}">
<include name="**/*.class" />
</fileset>
<fileset dir="${src.dir}">
<include name="**/*.properties"/>
<include name="/META-INF/**/*.*" />
<include name="/META-INF/spring/**/*.*" />
</fileset>
</jar>

MANIFEST.MF is override after running build.xml using ant

have following directory structure
src/com
src/META-INF/MANIFEST.MF
src/META-INF/spring
src/META-INF/spring/context.xml
now when i run the script, my menifest file is override, i don't want that, because i have to add custom enteries in it and i want that to be adding in generated .jar file. THing is all other files are copied, but this one is override.
my build.xml is as follows
<project name="TaskNodeBundle" default="all" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="bundlename" value="tasknodebundle" />
<property name="src.dir" location="../src" />
<property name="lib.dir" location="../lib" />
<property name="build.dir" location="/buildoutput" />
<property name="build.dest" location="../build/dest" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<!-- Deletes the existing build directory-->
<target name="mkdir" depends="clean">
<mkdir dir="${build.dest}"/>
</target>
<!-- Compiles the java code -->
<target name="compile" depends="mkdir">
<javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
</target>
<target name="package-bundle" depends="compile" description="Generates the bundle">
<jar destfile="${build.dest}/${bundlename}.jar">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
</target>
<target name="all" depends="package-bundle">
</target>
</project>
See http://ant.apache.org/manual/Tasks/jar.html.
If the manifest is omitted, a simple one will be supplied by Apache
Ant.
Just add manifest attribute or use zip task.
Also ant path masks are used incorrectly. See http://en.wikibooks.org/wiki/Apache_Ant/Fileset.
Corrected version:
<zip destfile="${build.dest}/${bundlename}.jar">
<fileset dir="${src.dir}">
<include name="META-INF/**" />
<include name="**/*.class" />
<include name="**/*.properties"/>
</fileset>
</zip>

ant build script don't run on windows using command line

i have written an ant script, which runs ok and generate the .jar file when i use it with eclipse.
But when i use it on command prompt on windows xp, it's shows successfull, but nothing happens. ant is properly configured and also i can run other ant scripts.
here is my build.xml file
<?xml version="1.0"?>
<project name="TaskNodeBundle" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="bundlename" value="task-node-bundle" />
<property name="src.dir" location="../src" />
<property name="lib.dir" location="../lib" />
<property name="build.dir" location="/buildoutput" />
<property name="build.dest" location="build/dest" />
<!--
Create a classpath container which can be later used in the ant task
-->
<path id="classpath">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${build.dest}" />
</target>
<!-- Deletes the existing build directory-->
<target name="mkdir" depends="clean">
<mkdir dir="${build.dest}"/>
</target>
<!-- Compiles the java code -->
<target name="compile" depends="mkdir">
<javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
</target>
<target name="package-bundle" depends="compile" description="Generates the bundle">
<jar destfile="${dist.dir}/${bundlename}.jar">
<fileset dir="${src.dir}">
<include name="**/**.class" />
<include name="**/**.properties"/>
<include name="/META-INF/**.*" />
<include name="/META-INF/spring/**.*" />
</fileset>
</jar>
</target>
</project>
When you execute an ant script from the command line it will execute the first target defined in the build.xml file (in your case clean).
You can specify the target(s) to be executed on the command line
$ ant target1 target2
or define a default target in your build.xml file with the default attribute of the <project> tag:
<project name="TaskNodeBundle" basedir="." default="package-bundle">

Ant not running all targets

I have the following ant file that is not running the targets "prepForDeployment" and "deployToStaging". This task is being run by Jenkins and I'm not getting any build errors when I look at the console output of the test.
<?xml version="1.0" encoding="UTF-8"?>
<project name="deploy" default="runUnitTests" basedir=".">
<description>
Deploys to staging.
</description>
<target name="init">
<taskdef name="mxunittask" classname="org.mxunit.ant.MXUnitAntTask" classpathref="project.classpath" />
<!-- dump the properties -->
<echoproperties prefix="test" />
</target>
<target name="clean" depends="init">
<mkdir dir="${test.junitoutput}" />
</target>
<target name="runUnitTests" depends="init,prepForTests">
<mkdir dir="${test.output.xml}/unit" />
<runTestDirectory directoryName="." excludes=""/>
</target>
<target name="runAllTests" description="Make output directories and run the MXUnit task" depends="init,clean,runUnitTests">
<!-- generate pretty reports -->
<antcall target="junitreport" />
<fail if="tests.bombed" message="Failing the build due to test failures"/>
</target>
<target name="junitreport" depends="init" description="Runs the report without running the tests">
<junitreport todir="${test.junitoutput}">
<fileset dir="${test.output.xml}">
<include name="*.xml" />
</fileset>
<report format="frames" todir="${test.junitoutput}" />
</junitreport>
</target>
<target name="prepForTests">
<!-- just a bunch of replace tasks, runs OK -->
</target>
<target name="prepForDeployment" depends="init">
<replace file="Application.cfc">
<replacetoken>dbcreate="dropcreate"</replacetoken>
<replacevalue>dbcreate="update"</replacevalue>
</replace>
<replace file="Application.cfc">
<replacetoken>logSQL = true</replacetoken>
<replacevalue>logSQL = false</replacevalue>
</replace>
<echo message="Prepping for deployment done." />
</target>
<target name="deployToStaging" depends="prepForDeployment">
<sequential>
<!--copy the files to a temp directory-->
<copy todir="${staging}_temp" overwrite="true">
<!-- -->
</copy>
<!-- delete applicaiton files on staging -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}" />
</delete>
<!-- copy files from temp dir to application dir -->
<copy todir="${staging}" overwrite="true">
<fileset dir="${staging}_temp" />
</copy>
<!-- remove temp dir -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}_temp" />
</delete>
</sequential>
<echo message="The files have been copied to staging." />
</target>
<macrodef name="runTestDirectory">
<attribute name="directoryName"/>
<attribute name="excludes" default=""/>
<sequential>
<mxunittask server="${test.server}" port="${test.serverport}" defaultrunner="${test.runner}" outputdir="${test.output.xml}/#{directoryName}" verbose="true" failureproperty="tests.bombed" errorproperty="tests.bombed">
<directory path="${test.dir.location}/#{directoryName}" recurse="true" packageName="${test.cfcpath}.#{directoryName}" componentPath="${test.cfcpath}.#{directoryName}" excludes="#{excludes}" />
</mxunittask>
</sequential>
</macrodef>
</project>
If you're not telling Jenkins to run the prepForDeployment and deployToStaging targets then it won't run them, just the same as when you run Ant on the command line.
If you want those targets to run, add them to the target list under your "Invoke Ant" build step.

Resources