this question is quite silly, but I can't find anyone else in the internet it seems who got the same problem and can't fix it themself.
This is my build.xml
I took it from an forum and changed the lines I knew what to put in.
<project name="RPGEssentials" default="dist" basedir="/var/lib/jenkins/workspace/RPGEssentials">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac includeantruntime="false" srcdir="${src}" destdir="${build}" encoding="iso-
8859-1"> <include name="../APIs/*.jar" /> </javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/RPGEssentials-0.0.1.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
This is the console output after building:
Started by user G4meM0ment
Building in workspace /var/lib/jenkins/workspace/RPGEssentials
Checkout:RPGEssentials / /var/lib/jenkins/workspace/RPGEssentials -
hudson.remoting.LocalChannel#389329d0
Using strategy: Default
Last Built Revision: Revision 4b5d8a711c78fbe32efb06f91dd88d8f0660f5c0 (origin/master,
origin/HEAD)
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Seen 2 remote branches
Commencing build of Revision 4b5d8a711c78fbe32efb06f91dd88d8f0660f5c0 (origin/master,
origin/HEAD)
Checking out Revision 4b5d8a711c78fbe32efb06f91dd88d8f0660f5c0 (origin/master,
origin/HEAD)
Warning : There are multiple branch changesets here
[RPGEssentials] $ ant
Buildfile: /var/lib/jenkins/workspace/RPGEssentials/build.xml
init:
compile:
dist:
BUILD SUCCESSFUL
Total time: 0 seconds
Archiving artifacts
Finished: SUCCESS
I'm pretty sure the error is in the build.xml the but I don't know what could be wrong.
The resulting jar-file contains some empty directories!
http://www.imagebanana.com/view/v68chgps/jarcontains.jpg
Thanks for your help
~Julian
Related
I am new to jacoco and trying to add jacoco coverage for a web application. i saw some links and came to know that we have to add javaagent below are the things that i did.
build.xml
<?xml version="1.0" ?>
<project xmlns:jacoco="antlib:org.jacoco.ant" name="Example Ant Build with JaCoCo" default="rebuild">
<description>
Example Ant build file that demonstrates how a JaCoCo coverage report can be itegrated into an existing build in three simple steps.
</description>
<property name="src.dir" location="./src"/>
<property name="result.dir" location="./target"/>
<property name="result.classes.dir" location="${result.dir}/classes"/>
<property name="result.report.dir" location="${result.dir}/site/jacoco"/>
<property name="result.exec.file" location="${result.dir}/jacoco.exec"/>
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="../../../lib/jacocoant.jar"/>
</taskdef>
<target name="clean">
<delete dir="${result.dir}"/>
</target>
<target name="compile">
<mkdir dir="${result.classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false"/>
</target>
<target name="test" depends="compile">
<!--
Step 2: Wrap test execution with the JaCoCo coverage task
-->
<jacoco:coverage destfile="${result.exec.file}" includes="*">
<java classname="com.antspringmvc.exp.Math" fork="true" >
<classpath path="${result.classes.dir}"/>
</java>
</jacoco:coverage>
</target>
<target name="report" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!--
This task needs the collected execution data and ...
-->
<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}"/>
<csv destfile="${result.report.dir}/report.csv"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>
<target name="rebuild" depends="clean,compile,test,report"/>
</project>
I have added the below code to my tomcat:
if ""%1"" == ""stop"" goto skip_agent
set "JAVA_OPTS=%JAVA_OPTS% -javaagent: C:\Users\kk\Desktop\Personal\jars\jacocoagent.jar=destfile=C:\Users\kk\Desktop\Personal\WorkSpace\JacocoExample\target\jacoco.exec,append=true,output=tcpserver,address=localhost,port=8080,includes=*"
i thought after stopping the server the report will be generated but that has not happened.
am i missing something in the configuration
From your build.xml seems that you expect JaCoCo agent to generate jacoco.exec file, however according to
if ""%1"" == ""stop"" goto skip_agent
set "JAVA_OPTS=%JAVA_OPTS% -javaagent: C:\Users\kk\Desktop\Personal\jars\jacocoagent.jar=destfile=C:\Users\kk\Desktop\Personal\WorkSpace\JacocoExample\target\jacoco.exec,append=true,output=tcpserver,address=localhost,port=8080,includes=*"
you configure agent with output=tcpserver, which means quoting documentation at http://www.jacoco.org/jacoco/trunk/doc/agent.html :
The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
When I run my code in the console, it runs fine. It also runs fine on eclipse. But when I try to build on Jenkins, it is asking for a src folder:
"C:\Program Files (x86)\Jenkins\Work space\job1\src" does not exist!
build.xml
<project name="Sample Ant build" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<!-- set global properties for build -->
<property name="basedir" value="." />
<property name="lib" value="${basedir}/lib" />
<property name="src" value="${basedir}/src" />
<property name="bin" value="${basedir}/bin" />
<property name="report-dir" value="${basedir}/Test-Report" />
<property name="testng-report-dir" value="${report-dir}/TestNGreport" />
<!-- ====== Set the classpath ==== -->
<path id="classpath">
<pathelement location="${bin}" />
<fileset dir="C:\WebDriver\Selenium">
<include name="*.jar" />
</fileset>
</path>
<!-- Delete directories -->
<target name="delete-dir">
<delete dir="${bin}" />
<delete dir="${report-dir}" />
</target>
<!-- Creating directories -->
<target name="create" depends="delete-dir">
<mkdir dir="${bin}" />
<mkdir dir="${report-dir}" />
</target>
<!-- Compile the java code from ${src} into ${bin} -->
<target name="compile" depends="create">
<javac srcdir="${src}" classpathref="classpath" includeAntRuntime="No" destdir="${bin}" />
<echo> /* Compiled Directory Classes */ </echo>
</target>
<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="classpath" />
<target name="testng-execution" depends="compile">
<mkdir dir="${testng-report-dir}" />
<testng outputdir="${testng-report-dir}" classpathref="classpath" useDefaultListeners="true">
<xmlfileset dir="${basedir}" includes="testng.xml" />
</testng>
</target>
Eclipse uses a workspace, Jenkins uses a workspace (and in our case, TFS also uses a workspace). They are not the same thing. (Your query is missing some details to answer authoritatively, some some assumptions were made)
Your build.xml script sets BASEDIR to ".", or the working directory. For a Jenkins job, that is as below - See Administering Jenkins:
JENKINS_HOME
+- workspace (working directory for the version control system)
+- [JOBNAME] (sub directory for each job)
In your case, JENKINS_HOME\workspace\[JOBNAME] is C:\Program Files (x86)\Jenkins\Work space\job1.
My money is that is not where your Eclipse workspace is mapped to.
I would make the following recommendations:
Develop your code and test it in Your Eclipse IDE. When satisfied, commit to your version control system (VCS).
Setup Jenkins to pull code from your VCS into the local workspace of your job and build there. As it's separate to your working copy it helps isolate changes and ensures you have committed everything to source control so your builds come from a know, reproducible source.
Set JEKNINS_HOME to a location outside of C:\Program Files ...; it's bad practice to place data (like source files and a build) in a location from installation binaries. Lots of goods reasons to do so, including security, easier space management, etc.
Choose an appropriate location and set the directory configurations for the Master (Jenkins | Manage Jenkins | Configure System; the first 3 values)
IF using distributed builds (master/node), within your node configuration (Jenkins | Manage Jenkins | Manage Nodes | Configure => Remote Root directory ) to an appropriate location
I am trying to learn ant and found an example build file in the docs.
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
I'm assuming the clean step should run before the init step however neither step depends on the other. Should init depend on clean step? If not, how does ant know the proper order?
When this ant build file runs, the clean target will not be executed. It isn't in the dependency chain. You would have to explicitly trigger it form the command line, e.g.
ant -f _buildFile.xml clean
ant -f _buildFile.xml
I've done that within a bash file. This is an example file, though, so it isn't necessarily how your final build system will work.
Maybe doing a dist should do clean first (seems reasonable), but that should be part of the dist dependencies, not the init target. For instance, you might want to compile and not do a clean. So
<target name="dist" depends="clean, compile"...
Or you could add a new target, clean_dist, for instance and add the dependency there. Then you could do a quick distribution build and real distribution build by specifying the target on the command line.
I am struggling with maven-ant build with eclipse.
I did work like below steps.
[GUI] new java project
add build.xml in project top folder
run ant file and SUCCEED!
trying to code, but somehow auto completion does not work.(guessing eclipse can not read maven-ant dependency.path)
So I tried.
add ~/.m2/repository in build path as a External class folder - does not work - It looks weird to me to include whole this folder. My current project, I need little libraries, but it has whole libraries that I uses in other projects.
add builders with build.xml like Want an eclipse java project to run ant build files automatically - does not work neither.
How can I add this maven-ant libraries properly? Thanks for sharing your experiences and answers XD
=========== Extra Information ====================
This is my build.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project name="HibernateEx2" default="db" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="data.dir" value="data"/>
<artifact:dependencies pathId="dependency.classpath">
<dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.10"/>
<dependency groupId="org.hibernate" artifactId="hibernate-core" version="4.3.10.Final">
<exclusion groupId="javax.transaction" artifactId="jta"/>
</dependency>
<!-- 3.2.4.GA - After hibernate4 need upgrade hibernate-tools -->
<dependency groupId="org.hibernate" artifactId="hibernate-tools" version="4.3.1.CR1"/>
<dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec" version="1.1.1"/>
<!-- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory -->
<dependency groupId="commons-logging" artifactId="commons-logging" version="1.2"/>
<dependency groupId="log4j" artifactId="log4j" version="1.2.17"/>
<!-- java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder -->
<dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.7.12"/>
</artifact:dependencies>
<path id="project.class.path">
<pathelement location="${class.root}"/>
<path refid="dependency.classpath" />
</path>
<!-- Explaining how to use hibernate -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.class.path"/>
<target name="db" description="Run HSQLDB database management UI against the database file -- use when application is not running">
<java classname="org.hsqldb.util.DatabaseManager" fork="yes">
<classpath refid="project.class.path"/>
<arg value="-driver"/>
<arg value="org.hsqldb.jdbcDriver"/>
<arg value="-url"/>
<arg value="jdbc:hsqldb:${data.dir}/music/"/>
<arg value="-user"/>
<arg value="sa"/>
</java>
</target>
<target name="print-classpath" description="Show the dependency class path">
<property name="class.path" refid="dependency.classpath"/>
<echo>${class.path}</echo>
</target>
<!-- Generate java code -->
<target name="codegen" description="Generate Java source from the OR mapping files">
<hibernatetool destdir="${source.root}">
<configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
<hbm2java/>
</hibernatetool>
</target>
<!-- Creating Sub drectories -->
<target name="prepare" description="Set up build structures">
<mkdir dir="${class.root}"/>
<copy todir="${class.root}">
<fileset dir="${source.root}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<!-- Creating Schema for mapping files -->
<target name="schema" depends="prepare" description="Generate DB schema from the OR mappinf files">
<hibernatetool destdir="${source.root}">
<configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
<hbm2ddl drop="yes"/>
</hibernatetool>
</target>
<!-- Compile Java -->
<!-- added includeantruntime="false" to javac, since terminal compile warning -->
<target name="compile" depends="prepare">
<javac srcdir="${source.root}" destdir="${class.root}"
debug="on" optimize="off" deprecation="on" includeantruntime="false">
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="ctest" depends="compile">
<java classname="org.owls.ht.CreateTest" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>
</project>
and This is what my project looks like.
src
-- source codes (includes hibernate.cfg.xml)
classes
-- compiled classes
data
-- logs and queries
build.xml
FYI, I am doing this with a book named [[Harness Hibernate]] written by James Elliot from O'reilly.
Thanks again b
For what you are trying to do, you need the filesetId and versionsId="dependency.versions" in your declaration of:
<artifact:dependencies filesetId="dependency.fileset" versionsId="dependency.versions"
Then add a copy task like so:
<copy todir="${lib.dir}">
<fileset refid="dependency.fileset" />
<mapper classpathref="maven-ant-tasks.classpath"
classname="org.apache.maven.artifact.ant.VersionMapper"
from="${dependency.versions}" to="flatten" />
</copy>
The to="flatten" will flaten your dependencies into a single folder, then you can include that folder on the classpath of eclipse project or wherever you need it.
In the documentation to socket.io-java by nkzawa is mentioned that to add ant dependency should be used next snippet:
<dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1-SNAPSHOT">
<artifact name="socket.io-client" type="jar" />
</dependency>
In which file and how I should include it? How I should compile my application after that?
In order to manage dependency with ant you'll need to use Ivy
But I agree with Bart Kiers - switch to Gradle, especially as you're already using IDEA.
The socket.io-client documentation is misleading. ANT has an extension called ivy for performing dependency management, but it is not bundled by default.
Once setup you can list your project's dependencies in an ivy.xml file or within your build.xml using the cachepath task:
<ivy:cachepath pathid="compile.path">
<dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1" />
</ivy:cachepath>
I have included a more complete example below. It details how to configure your ANT build to automatically setup ivy.
I am not an android programmer, so not able to recommend the best build tool. What I can say is that adding dependency management to your build process is a very good idea. ANT pre-dates more modern tools like Maven and Gradle that have this feature baked in.
Example
build.xml
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
================
Build properties
================
-->
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
===========
Build setup
===========
-->
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
<ivy:cachepath pathid="compile.path">
<dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1" />
</ivy:cachepath>
</target>
<!--
===============
Compile targets
===============
-->
<target name="build" depends="resolve" description="Project build logic goes here">
<javac .... classpathref="compile.path">
</javac>
...
</target>
<!--
===============
Clean-up targets
===============
-->
<target name="clean" description="Cleanup build files">
<delete dir="build"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>