ant, copy file with it's directory structure - ant

I am trying to write a ant script to automate the update process of our web application.
When some files is going to be updated, I need to backup that file. my question is how to copy that file to backup directory and also create the directory structure relative to the root directory of my web application?
for example:
${WEB_APP_ROOT}/dir1/file1
${WEB_APP_ROOT}/dir2/subdir1/file2
copied to backup folder should be:
${BACK_UP_DIR}/dir1/file1
${BACK_UP_DIR}/dir2/subdir1/file2
currently, I can only copy all files to backup folder, but if two file with same name but located in different folder will cause problem.
my ant code:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- 对公信贷自动更新Ant任务脚本 created by ggfan#bgzchina.com at 2013.11.14 -->
<project default="patch" basedir=".">
<!-- 引入Weblogic安装目录下的antcontrib包,才能使用if,foreach,propertyregex-->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/home/weblogic/Oracle/Middleware/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar" />
</classpath>
</taskdef>
<!-- 发布目标路径 -->
<property name="target_dir" value="/home/weblogic/amarsoft/ccms/war/CCMS" />
<!-- 数据库连接配置属性 -->
<property name="db_driver" value="oracle.jdbc.OracleDriver" />
<property name="db_url" value="jdbc:oracle:thin:#10.53.1.116:1521:credit" />
<property name="db_user" value="als_sit" />
<property name="db_pswd" value="als_sit" />
<!-- WLST配置 -->
<property name="wl_target_server" value="AdminServer" />
<property name="wl_admin_url" value="t3://10.53.1.117:7001" />
<property name="wl_user" value="weblogic" />
<property name="wl_pswd" value="weblogic123" />
<property name="wl_app_name" value="CCMS" />
<target name="patch">
<!-- 检查是否存在WEB-INF目录,如果有则说明更新了配置文件或者JAVA类需要重新加载应用 -->
<available file="${patch_dir}/WebRoot/WEB-INF" type="dir" property="WEB-INF.present"/>
<!-- 检查是否存在数据库更新脚本 -->
<available file="${patch_dir}/update.sql" type="file" property="sql.present"/>
<!-- 创建备份目录 -->
<mkdir dir="${patch_dir}/backup" />
<!-- 针对单个文件,检查是否更新还是新增,如果是更新则要先备份 -->
<foreach target="move-to-backup" param="theFile">
<path>
<fileset dir="${patch_dir}/WebRoot" />
</path>
</foreach>
<!-- 提醒用户检查更新列表预览 -->
<input message="Is patching preview above correct?" validargs="y,n" addproperty="patch.continue" />
<!-- 用户确认无误则更新 -->
<if>
<equals arg1="${patch.continue}" arg2="y" />
<then>
<!-- 存在WEB-INF目录,则先停止应用 -->
<if>
<equals arg1="${WEB-INF.present}" arg2="true" />
<then>
<echo message="Directory [WEB-INF] found in patching dir, application will be stoped" />
<wldeploy action="stop" graceful="true" name="${wl_app_name}" user="${wl_user}" password="${wl_pswd}"
verbose="true" adminurl="${wl_admin_url}" targets="${wl_target_server}" />
</then>
</if>
<copy todir="${target_dir}" verbose="true">
<fileset dir="${patch_dir}/WebRoot/" />
</copy>
<!-- 存在数据库更新脚本则执行 -->
<if>
<equals arg1="${sql.present}" arg2="true" />
<then>
<sql driver="${db_driver}" url="${db_url}" userid="${db_user}" password="${db_pswd}">
<classpath>
<pathelement location="/home/weblogic/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar" />
</classpath>
<transaction src="${patch_dir}/update.sql"/>
</sql>
</then>
</if>
<!-- 更新完成后,重启应用 -->
<if>
<equals arg1="${WEB-INF.present}" arg2="true" />
<then>
<echo message="Application will be started again." />
<wldeploy action="start" name="${wl_app_name}" user="${wl_user}" password="${wl_pswd}"
verbose="true" adminurl="${wl_admin_url}" targets="${wl_target_server}" />
</then>
</if>
<echo message="Patching done! " />
</then>
</if>
</target>
<target name="move-to-backup">
<propertyregex property="target.file" input="${theFile}" regexp=".+/${patch_dir}/WebRoot/(.+)" replace="${target_dir}/\1" casesensitive="true" />
<available file="${target.file}" type="file" property="target.file.exist" />
<if>
<equals arg1="${target.file.exist}" arg2="true" />
<then>
<echo message="[UPDATE] ${target.file}" />
<copy todir="${patch_dir}/backup" verbose="false">
<fileset file="${target.file}" />
</copy>
</then>
<else>
<echo message="[ADD ] ${target.file}" />
</else>
</if>
</target>
</project>

In your target move-to-backup you have this copy task:
<copy todir="${patch_dir}/backup" verbose="false">
<fileset file="${target.file}" />
</copy>
When you define a fileset as a single file, it uses the directory containing the file as the base directory for the fileset, and the path to the file is relative to that: simply the name of the file.
You can do something like this instead, so that the path to the file to be copied is relative to the root of your application:
<copy todir="${patch_dir}/backup" verbose="false">
<fileset dir="${WEB_APP_ROOT}">
<include name="${target.file}" />
</fileset>
</copy>
If your file was
${WEB_APP_ROOT}/x/y/z/file.txt
It would then be copied to
${patch_dir}/backup/x/y/z/file.txt

Related

jenkins build configuration- packaging EAR issue

I have the build configuration set up for jenkins and while packaging EAR it is neglecting an xml file while it builds. I want to make sure that file gets updated via build configuration .
''''''EAR Packager file
<property name="librariesFolderPath" value="${basedir}/../libs" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${librariesFolderPath}/ant-contrib.jar" />
</classpath>
</taskdef>
<property environment="env" />
<condition property="partialWsPath" value="**/${TO_BUILD}/**" else="**">
<and>
<isset property="TO_BUILD" />
<not>
<equals arg1="${TO_BUILD}" arg2="" trim="true" />
</not>
</and>
</condition>
<condition property="lurch.properties.file" value="${project.properties.file}" else="lurchproject.properties">
<and>
<isset property="project.properties.file" />
<not>
<equals arg1="${project.properties.file}" arg2="" trim="true" />
</not>
</and>
</condition>
<pathconvert property="project.properties.path">
<fileset dir="${env.WORKSPACE}" includes="${partialWsPath}/${lurch.properties.file}" />
</pathconvert>
<property file="${project.properties.path}" />
<propertyregex property="studio.buildnumber" input="${studio.version}" regexp="(.*)[a-zA-Z]$" select="\1" defaultvalue="${studio.version}" />
<property file="${basedir}/../config/builderstructure.properties" />
<property file="${basedir}/barpackager.properties" />
<property file="${runtime.properties.file}" />
<property name="lurch.customized.folder.path" value="${basedir}/../../customized" />
<!-- Retriving deploy-project name -->
<propertyregex property="deploy.project.name" input="${deploy.project}" regexp="([^\\/]*)[\\/]?$" select="\1" />
<!-- Retriving the list of libraries that mustn't be in the ear -->
<propertyregex property="targetj2ee" input="${target.j2ee}" regexp=" " replace="_" global="true" />
<propertycopy property="libs2cutoff" from="libs2cutoff.${targetj2ee}" />
<!-- =================================
target: default
================================= -->
<target name="earsPackagingCompleted"
depends="init,evaluateConditions,createDeployJar,generateManifest,createEJB,createWAR,createEar,customizeEar"
description="Calls all the targets needd to generate the ear" />
<!-- =================================
target: init
================================= -->
<target name="init" description="Compute the build order">
<delete dir="${output.ears}" includeemptydirs="true" />
<mkdir dir="${output.ears.tmp.lib}" />
<mkdir dir="${output.ears.tmp.war}/META-INF" />
<mkdir dir="${output.ears.tmp.ejb}/META-INF" />
</target>
<!-- =================================
target: evaluateConditions
================================= -->
<target name="evaluateConditions" depends="" description="Evaluates conditions rekated to ear creation">
<condition property="appl.srv.project.folder"
value="${runtime.projects.to.build}/${deploy.project.name}/${deploy.appl.srv.folder}/${target.j2ee}">
<!-- else="${eclipse.plugins}/${appl.srv.studio.folder}/${target.j2ee}" -->
<and>
<isset property="deploy.appl.srv.folder" />
<not>
<equals arg1="${deploy.appl.srv.folder}" arg2="" trim="true" />
</not>
<isset property="target.j2ee" />
<not>
<equals arg1="${target.j2ee}" arg2="" trim="true" />
</not>
<available file="${runtime.projects.to.build}/${deploy.project.name}/${deploy.appl.srv.folder}" type="dir" />
<available file="${runtime.projects.to.build}/${deploy.project.name}/${deploy.appl.srv.folder}/${target.j2ee}" type="dir" />
<resourcecount when="greater" count="0">
<fileset dir="${runtime.projects.to.build}/${deploy.project.name}/${deploy.appl.srv.folder}/${target.j2ee}" />
</resourcecount>
</and>
</condition>
<echo message="appl.srv.project.folder: ${appl.srv.project.folder}" level="verbose" />
</target>
<!-- =================================
target: createDeployJar
================================= -->
<target name="createDeployJar">
<!-- Add the DeployInfo.xml file and replace the token with the actual J2EE target server -->
<copy file="${eclipse.plugins}/${appl.srv.studio.folder}/.misc/config/DeployInfo.xml"
todir="${runtime.projects.to.build}/${deploy.project.name}/bin/config"
overwrite="true" />
<replace file="${runtime.projects.to.build}/${deploy.project.name}/bin/config/DeployInfo.xml" token="%TargetJ2ee%" value="${target.j2ee}" />
<echo message="[DD] earpackager createDeployJar $${output.jars}/$${deploy.project.name}.jar: '${output.jars}/${deploy.project.name}.jar'."/>
<echo message="[DD] earpackager createDeployJar $${runtime.projects.to.build}/$${deploy.project.name}/bin: '${runtime.projects.to.build}/${deploy.project.name}/bin'."/>
<jar destfile="${output.jars}/${deploy.project.name}.jar" keepcompression="true">
<manifest>
<attribute name="Created-By" value="Finantix Studio ${studio.version}" />
<attribute name="Build-Jdk" value="${java.version} ${java.vendor}" />
<attribute name="Built-By" value="L.U.R.Ch - Fx automated build system - ${builder.full.version}" />
<attribute name="Implementation-Title" value="${deploy.project.name}" />
<attribute name="Implementation-Version" value="${project.full.version}" />
<attribute name="Implementation-Vendor" value="${implementation.vendor}" />
</manifest>
<fileset dir="${runtime.projects.to.build}/${deploy.project.name}/bin" />
</jar>
</target>
<!-- =================================
target: generateManifest
================================= -->
<target name="generateManifest" depends="cleanupJarsForEar" description="Generates the manifest files for the war and ejb files">
<propertyregex property="classpath.runtime.patches" input="${deploy.libraries}" regexp="," replace=" lib/" global="true" />
<propertyregex property="classpath.runtime.patches" input="${classpath.runtime.patches}" regexp="(.*)" select="lib/\1" override="true" />
<echo message="classpath.runtime.patches: ${classpath.runtime.patches}" level="verbose" />
<pathconvert property="classpath.other.runtime.patches" pathsep=" ">
<path>
<fileset dir="${project.libraries.folder.path}/${4Ear.patches}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.patches}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4Ear.lib3p}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.lib3p}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4Ear.libJavaPrj}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.libJavaPrj}"
includes="${selectable.required.libraries}"
excludes="${selectable.deploy.libraries}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.other.runtime.patches: ${classpath.other.runtime.patches}" level="verbose" />
<pathconvert property="classpath.generated.bars" pathsep=" ">
<path>
<fileset dir="${output.bars}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.generated.bars: ${classpath.generated.bars}" level="verbose" />
<pathconvert property="classpath.generated.jars" pathsep=" ">
<path>
<fileset dir="${output.jars}" includes="**/*.*" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.generated.jars: ${classpath.generated.jars}" level="verbose" />
<pathconvert property="classpath.not.generated.libs.and.bars" pathsep=" ">
<path>
<fileset dir="${input.ftp.bars}" includes="${required.bars}" excludes="${libs.and.bars.to.exclude}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.not.generated.libs.and.bars: ${classpath.not.generated.libs.and.bars}" level="verbose" />
<pathconvert property="classpath.studio.bars" pathsep=" ">
<path>
<fileset dir="${eclipse.plugins}" includes="${bars.from.fs.plugins}" excludes="${libs2cutoff}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.studio.bars: ${classpath.studio.bars}" level="verbose" />
<pathconvert property="classpath.fs.plugins.4.ear" pathsep=" ">
<path>
<fileset dir="${eclipse.plugins}" includes="${fs.plugins.4.ear}" excludes="${libs2cutoff},${selectable.required.libraries}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</pathconvert>
<echo message="classpath.fs.plugins.4.ear: ${classpath.fs.plugins.4.ear}" level="verbose" />
<!--property name="EARClasspath" value="${classpath.runtime.patches} ${classpath.generated.jars} ${classpath.generated.bars} ${classpath.not.generated.libs.and.bars} ${classpath.other.runtime.patches} ${classpath.studio.bars} ${classpath.studio.plugins} ${classpath.3rd.parties.libs}" /-->
<property name="EARClasspath"
value="${classpath.runtime.patches} ${classpath.generated.jars} ${classpath.generated.bars} ${classpath.not.generated.libs.and.bars} ${classpath.other.runtime.patches} ${classpath.studio.bars} ${classpath.fs.plugins.4.ear}" />
<propertyregex property="EARClasspath" input="${EARClasspath}" regexp="\s+" replace=" " global="true" override="true" />
<echo message="EARClasspath: ${EARClasspath}" level="verbose" />
<manifest file="${output.ears.tmp.war}/META-INF/MANIFEST.MF">
<attribute name="Created-By" value="Finantix Studio ${studio.version}" />
<attribute name="Build-Jdk" value="${java.version} ${java.vendor}" />
<attribute name="Built-By" value="L.U.R.Ch - Fx automated build system - ${builder.full.version}" />
<attribute name="Implementation-Version" value="${project.full.version}" />
<attribute name="Implementation-Vendor" value="${implementation.vendor}" />
<attribute name="Class-Path" value="${EARClasspath}" />
</manifest>
<copy file="${output.ears.tmp.war}/META-INF/MANIFEST.MF" tofile="${output.ears.tmp.ejb}/META-INF/MANIFEST.MF" />
</target>
<!-- =================================
target: cleanupJarsForEar
================================= -->
<target name="cleanupJarsForEar" depends="cleanupBarsForEar" description="Remove java files from the archives to store in the ear.">
<fileset dir="${output.ears.tmp.lib}" id="jar.files.to.update.id">
<include name="*.jar" />
<exclude name="*_bar.jar" />
</fileset>
<echo level="info" message="********* Removing source code from jar files *******" />
<property name="jar.files.to.update" refid="jar.files.to.update.id" />
<for list="${jar.files.to.update}" delimiter=";" param="jar.file">
<sequential>
<echo message="=========================================" />
<echo message=" Updating ${jar.counter} out of ${number.of.jars.to.update} jar files ..." />
<exec executable="7za">
<arg value="d" />
<arg value="-tzip" />
<arg value="${output.ears.tmp.lib}/#{jar.file}" />
<arg value="*.java" />
<arg value="-r" />
</exec>
<math result="jar.counter" operation="+" operand1="${jar.counter}" operand2="1" datatype="int" />
</sequential>
</for>
</target>
<!-- =================================
target: cleanupBarsForEar
================================= -->
<target name="cleanupBarsForEar" depends="moveLibraries" description="Remove useless files from the archives to store in the ear.">
<resourcecount property="number.of.jars.to.update">
<fileset dir="${output.ears.tmp.lib}">
<include name="*.jar" />
</fileset>
</resourcecount>
<echo level="info" message="********* Removing source code, java and dat files from ${number.of.jars.to.update} bar files *******" />
<var name="jar.counter" value="1" />
<fileset dir="${output.ears.tmp.lib}" id="bar.files.to.update.id">
<include name="*_bar.jar" />
</fileset>
<property name="bar.files.to.update" refid="bar.files.to.update.id" />
<for list="${bar.files.to.update}" delimiter=";" param="bar.file">
<sequential>
<echo message="=========================================" />
<echo message=" Updating ${jar.counter} out of ${number.of.jars.to.update} bar files ..." />
<exec executable="7za">
<arg value="d" />
<arg value="-tzip" />
<arg value="${output.ears.tmp.lib}/#{bar.file}" />
<arg value="META-INF/*.dat" />
<arg value="META-INF/.bar" />
<arg value="src" />
<arg value="*.java" />
<arg value="-r" />
</exec>
<math result="jar.counter" operation="+" operand1="${jar.counter}" operand2="1" datatype="int" />
</sequential>
</for>
</target>
<!-- =================================
target: moveLibraries
================================= -->
<target name="moveLibraries" description="Moves files into the lib folder in the temporary ear folder">
<pathconvert property="libs.and.bars.to.exclude" pathsep=",">
<path>
<fileset dir="${output.bars}" />
<fileset dir="${output.jars}" />
</path>
<chainedmapper>
<mapper type="flatten" />
<regexpmapper from="(.*)" to="**/\1" />
</chainedmapper>
</pathconvert>
<propertyregex property="selectable.deploy.libraries" input="${deploy.libraries}" regexp="," replace=",**/" global="true" />
<propertyregex property="selectable.deploy.libraries" input="${selectable.deploy.libraries}" regexp="(.*)" select="**/\1" override="true" />
<propertyregex property="selectable.required.libraries" input="${required.libraries}" regexp="," replace=",**/" global="true" />
<propertyregex property="selectable.required.libraries"
input="${selectable.required.libraries}"
regexp="(.*)"
select="**/\1"
override="true" />
<copy todir="${output.ears.tmp.lib}" flatten="true" failonerror="true">
<fileset dir="${project.libraries.folder.path}/${4Ear.patches}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.patches}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4Ear.lib3p}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.lib3p}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4Ear.libJavaPrj}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${project.libraries.folder.path}/${4EarAndCompiling.libJavaPrj}"
includes="${selectable.deploy.libraries},${selectable.required.libraries}" />
<fileset dir="${output.bars}" />
<fileset dir="${output.jars}" />
<fileset dir="${input.ftp.bars}" includes="${required.bars}" excludes="${libs.and.bars.to.exclude}" />
<fileset dir="${eclipse.plugins}" includes="${bars.from.fs.plugins}" excludes="${libs2cutoff}" />
<fileset dir="${eclipse.plugins}" includes="${fs.plugins.4.ear}" excludes="${libs2cutoff},${selectable.required.libraries}" />
</copy>
</target>
<!-- =================================
target: createEJB
================================= -->
<target name="createEJB">
<copy todir="${output.ears.tmp.ejb}" overwrite="false">
<fileset dir="${eclipse.plugins}/${appl.srv.studio.folder}/${target.j2ee}/EJB" />
</copy>
<antcall target="updateWithCustomFiles">
<param name="destination.folder" value="${output.ears.tmp.ejb}" />
<param name="source.folder" value="${appl.srv.project.folder}/EJB" />
<param name="overwrite" value="true" />
</antcall>
<jar destfile="${output.ears.tmp}/${ejb.name}.jar" basedir="${output.ears.tmp.ejb}" manifest="${output.ears.tmp.ejb}/META-INF/MANIFEST.MF" />
<delete dir="${output.ears.tmp.ejb}" includeEmptyDirs="true" />
</target>
<!-- =================================
target: createWAR
================================= -->
<target name="createWAR">
<copy todir="${output.ears.tmp.war}" overwrite="true">
<fileset dir="${web.project.folder.path}">
<exclude name="work/" />
<exclude name="**/.classpath" />
<exclude name="**/.project" />
</fileset>
</copy>
<copy todir="${output.ears.tmp.war}" overwrite="false">
<fileset dir="${eclipse.plugins}/${appl.srv.studio.folder}/${target.j2ee}/WAR" />
</copy>
<antcall target="updateWithCustomFiles">
<param name="destination.folder" value="${output.ears.tmp.war}" />
<param name="source.folder" value="${appl.srv.project.folder}/WAR" />
<param name="overwrite" value="true" />
</antcall>
<for list="${web.project.version.files}" delimiter="," param="web.project.version.file">
<sequential>
<replace file="${output.ears.tmp.war}/#{web.project.version.file}"
token="${web.project.version.token}"
value="${project.full.version}" />
</sequential>
</for>
<antcall target="evaluateWebXmlConditions">
<param name="web.xml.path" value="${output.ears.tmp.war}/WEB-INF/web.xml" />
</antcall>
<war destfile="${output.ears.tmp}/${war.name}.war"
basedir="${output.ears.tmp.war}"
manifest="${output.ears.tmp.war}/META-INF/MANIFEST.MF"
webxml="${output.ears.tmp.war}/WEB-INF/web.xml" />
<delete dir="${output.ears.tmp.war}" includeEmptyDirs="true" />
</target>
<!-- =================================
target: evaluateWebXmlConditions
================================= -->
<target name="evaluateWebXmlConditions">
<loadfile property="web.content" srcFile="${web.xml.path}">
<filterchain>
<tokenfilter>
<filetokenizer />
<replaceregex pattern="<!--.*?-->" flags="gs" replace="" />
</tokenfilter>
</filterchain>
</loadfile>
<condition property="workManagerIsToAdd">
<not>
<contains string="${web.content}" substring="<res-ref-name>wm/WorkManager</res-ref-name>" />
</not>
</condition>
<condition property="ejbTimerIsToAdd">
<not>
<contains string="${web.content}" substring="<ejb-ref-name>ejb/EJBTimerServiceExecutorHome</ejb-ref-name>" />
</not>
</condition>
<antcall target="addWorkManager" />
<antcall target="addEjbTimer" />
</target>
<!-- =================================
target: addWorkManager
================================= -->
<target name="addWorkManager" if="workManagerIsToAdd">
<property name="tab" value=" " />
<replaceregexp file="${web.xml.path}"
match="</servlet-mapping>([^\w>]*)<resource-ref>"
replace="</servlet-mapping>${line.separator}${tab}<resource-ref>${line.separator}${tab}${tab}<!--WorkManager-->${line.separator}${tab}${tab}<description>Required for concurrency support</description>${line.separator}${tab}${tab}<res-ref-name>wm/WorkManager</res-ref-name>${line.separator}${tab}${tab}<res-type>commonj\.work\.WorkManager</res-type>${line.separator}${tab}${tab}<res-auth>Container</res-auth>${line.separator}${tab}${tab}<res-sharing-scope>Shareable</res-sharing-scope>${line.separator}${tab}</resource-ref>${line.separator}${tab}<resource-ref>"
flags="s" />
</target>
<!-- =================================
target: addEjbTimer
================================= -->
<target name="addEjbTimer" if="ejbTimerIsToAdd">
<property name="tab" value=" " />
<replaceregexp file="${web.xml.path}"
match="</web-app>"
replace="${tab}<!--EJB Timer reference -->${line.separator}${tab}<ejb-ref>${line.separator}${tab}${tab}<ejb-ref-name>ejb/EJBTimerServiceExecutorHome</ejb-ref-name>${line.separator}${tab}${tab}<ejb-ref-type>Session</ejb-ref-type>${line.separator}${tab}${tab}<home>com.finantix.foundation.integration.ejbtimer.EJBTimerServiceExecutorHome</home>${line.separator}${tab}${tab}<remote>com.finantix.foundation.integration.ejbtimer.EJBTimerServiceExecutor</remote>${line.separator}${tab}${tab}<ejb-link>EJBTimerServiceExecutor</ejb-link>${line.separator}${tab}</ejb-ref>${line.separator}</web-app>"
flags="s" />
</target>
<!-- =================================
target: createEar
================================= -->
<target name="createEar">
<copy todir="${output.ears.tmp}" overwrite="true">
<fileset dir="${eclipse.plugins}/${appl.srv.studio.folder}/${target.j2ee}/EAR" />
</copy>
<antcall target="updateWithCustomFiles">
<param name="destination.folder" value="${output.ears.tmp}" />
<param name="source.folder" value="${appl.srv.project.folder}/EAR" />
<param name="overwrite" value="true" />
</antcall>
<replace file="${output.ears.tmp}/META-INF/application.xml" token="%ContextRoot%" value="${context.root}" />
<replace file="${output.ears.tmp}/META-INF/application.xml" token="%WARName%" value="${war.name}" />
<replace file="${output.ears.tmp}/META-INF/application.xml" token="%EJBName%" value="${ejb.name}" />
<jar destfile="${output.ears}/${ear.name}.ear" basedir="${output.ears.tmp}">
<manifest>
<attribute name="Created-By" value="Finantix Studio ${studio.version}" />
<attribute name="Build-Jdk" value="${java.version} ${java.vendor}" />
<attribute name="Built-By" value="L.U.R.Ch - Fx automated build system - ${builder.full.version}" />
<attribute name="Implementation-Version" value="${project.full.version}" />
<attribute name="Implementation-Vendor" value="${implementation.vendor}" />
</manifest>
</jar>
<delete dir="${output.ears.tmp}" includeEmptyDirs="true" />
</target>
<!-- =================================
target: updateWithCustomFiles
================================= -->
<target name="updateWithCustomFiles" depends="evaluateCopyConditions" if="copy.is.executable">
<copy todir="${destination.folder}" overwrite="${overwrite}">
<fileset dir="${source.folder}" />
</copy>
</target>
<!-- =================================
target: evaluateCopyConditions
================================= -->
<target name="evaluateCopyConditions">
<condition property="copy.is.executable">
<and>
<isset property="appl.srv.project.folder" />
<available file="${source.folder}" type="dir" />
</and>
</condition>
</target>
<!-- =================================
target: customizeEar
================================= -->
<target name="customizeEar" if="custom.script.path" depends="checkForCustomScript">
<propertyregex property="workspaces.folder.path" input="${project.properties.path}" regexp="(.*?)/[^\\/]*$" select="\1" />
<ant antfile="${custom.script.path}" inheritAll="false">
<property name="ant-contrib.jar.path" value="${librariesFolderPath}/ant-contrib.jar" />
<property name="lurch.libraries.folder.path" value="${librariesFolderPath}" />
<property name="output.ears.folder.path" value="${output.ears}" />
<property name="ear.name" value="${ear.name}" />
<property name="deploy.project.name" value="${deploy.project.name}" />
<property name="studio.version" value="${studio.version}" />
<property name="java.version" value="${java.version}" />
<property name="java.vendor" value="${java.vendor}" />
<property name="builder.full.version" value="${builder.full.version}" />
<property name="project.full.version" value="${project.full.version}" />
<property name="workspaces.folder.path" value="${workspaces.folder.path}" />
<property name="output.bars.folder.path" value="${output.bars}" />
<property name="output.jars.folder.path" value="${output.jars}" />
<property name="output.ddls.folder.path" value="${output.ddls}" />
<property name="output.processes.folder.path" value="${output.processes}" />
<property name="output.translations.folder.path" value="${output.translations}" />
<property name="manifest.properties.file" value="${manifest.properties.file}" />
<propertyset>
<propertyref prefix="${custom.ear.properties.prefix}" />
</propertyset>
</ant>
</target>
<!-- =================================
target: checkForCustomScript
================================= -->
<target name="checkForCustomScript">
<condition property="custom.script.path" value="${lurch.customized.folder.path}/${project.phase.id}/${custom.ear.script}">
<and>
<isset property="project.phase.id" />
<not>
<equals arg1="project.phase.id" arg2="" trim="true" />
</not>
<available file="${lurch.customized.folder.path}/${project.phase.id}/${custom.ear.script}" type="file" />
</and>
</condition>
</target>
'''''''''''''''''''
The file name is FxCONF.xml which needs to be packaged in Deploy JAR.
Please advise how can i change the above code to make sure i include this file while pacaging.
Java is not my specialty, but I believe that to move and use the file (FxConf.xml) you need to add this copy action.
If I understand what you need I think the way is here:
How do I create an EAR file with an ant build including certain files?
Here can be another reference.
https://gist.github.com/mudzot/865511
Are you using ant?
I hope to be more helping than hinder. :)

How to deploy configuration files,jars and ear files in remote weblogic server using ant script

I want to deploy the jar files,configuration files and generated ear file on remote weblogic server using ant script.
I have created ant script that stop the weblogic server,delete old files(jar,config xml files,ear) copy the given source to destination,this script is work when source and destination both are having on same machine.
<project name="Svn" default="startserver">
<property name="bea.home" value="C:/Oracle/Middleware/Oracle_Home" />
<property name="weblogic.home" value="${bea.home}/wlserver" />
<property name="domain.home" value="${bea.home}/user_projects/domains" />
<property name="domain.name" value="NAPF_domain" />
<property name="host" value="10.254.5.191" />
<property name="port" value="7001" />
<property name="username" value="weblogic" />
<property name="password" value="weblogic" />
<property name="admin.server.name" value="AdminServer" />
<property name="libdeploy.dir" value="${domain.home}/${domain.name}/lib/" />
<property name="configdeploy.dir" value="${domain.home}/${domain.name}/pf-appl/config/" />
<property name="eardeploy.dir" value="${domain.home}/${domain.name}/servers/AdminServer/upload/" />
<property name="libsource.dir" value="napf-main/napf-build/release/target/Release/lib/" />
<property name="configsource.dir" value="napf-main/napf-build/release/target/Release/config/" />
<property name="earsource.dir" value="napf-main/napf-build/release/target/Release/dist/" />
<property name="napfscutitysource.dir" value="napf-main/napf-security-lib" />
<property name="sourceMonitorHome" location="NAPF_SERVER_SOURCE/SourceMonitor"/>
<path id="wls.classpath">
<fileset dir="${weblogic.home}/server/lib">
<include name="web*.jar" />
</fileset>
</path>
<taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer" classpathref="wls.classpath" />
<target name="start-server">
<wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" domainname="${domain.name}" servername="${admin.server.name}" action="start" username="${username}" password="${password}" beahome="${bea.home}" weblogichome="${weblogic.home}" verbose="true" noexit="true" protocol="t3" classpath="${weblogic.home}/server/lib/weblogic.jar">
<jvmarg value="-server" />
<jvmarg value="-Xms256m" />
<jvmarg value="-Xmx512m" />
<jvmarg value="-XX:PermSize=128m" />
<jvmarg value="-XX:MaxPermSize=256m" />
</wlserver>
<sleep seconds="2" />
</target>
<target name="stop-server">
<wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" servername="${admin.server.name}" username="${username}" password="${password}" action="shutdown" beahome="${bea.home}" weblogichome="${weblogic.home}" forceshutdown="true" />
</target>
<target name="purge-deploy" description="Delete old deploy files.">
<echo message="Deleting old deploy files..." />
<delete includeEmptyDirs="true">
<!-- Delete all jar files -->
<fileset dir="${libdeploy.dir}" includes="**/*" />
<!-- Delete all config files -->
<fileset dir="${configdeploy.dir}" includes="**/*" />
</delete>
</target>
<target name="copyToSecurityLib" description="Copy files to napf security folder.">
<copy todir="${libdeploy.dir}">
<fileset dir="${napfscutitysource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
<target name="copyToDeploy" description="Copy files to deploy folder.">
<copy todir="${libdeploy.dir}">
<fileset dir="${libsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
<copy todir="${configdeploy.dir}">
<fileset dir="${configsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
<copy todir="${eardeploy.dir}">
<fileset dir="${earsource.dir}">
<include name="**" />
<!-- ignore files/folders starting with svn -->
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
<target name="purgeReport" description="Delete old report files.">
<echo message="Deleting old report files..." />
<delete includeEmptyDirs="true">
<fileset dir="${sourceMonitorHome}" includes="**/*.csv,*.jpeg,*.smp" />
</delete>
</target>
<target name="startSourceMonitor">
<exec dir="${sourceMonitorHome}" executable="cmd" failonerror="true" spawn="false">
<arg value="/c"/>
<arg value="sourcemonitor.bat"/>
</exec>
</target>
<target name="copyReportFiles" description="Copy files to napf source directory to slave workspace directory.">
<delete includeEmptyDirs="true">
<fileset dir="${sourceMonitorWorkSpace}"/>
</delete>
<mkdir dir="${sourceMonitorWorkSpace}"/>
<sleep seconds="1" />
<copy todir="${sourceMonitorWorkSpace}">
<fileset dir="${sourceMonitorHome}">
<include name="**/*.csv" />
<include name="**/*.jpeg" />
<exclude name="**/.svn" />
</fileset>
</copy>
</target>
Please suggest.
You can try wldeploy Ant task.
First, add task definition.
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="${weblogic.home}/server/lib/weblogic.jar"/>
</classpath>
</taskdef>
Next, configure each action of wldeploy task, such as deploy, redeploy, or undeploy specifically.
Example,
<!-- The deployment name for the deployed application.
If you do not specify this attribute, WebLogic Server assigns a deployment name to the application, based on its archive file or exploded directory. -->
<property name="deploy.name" value="MyApp"/>
<!-- The archive file or exploded directory to deploy. -->
<property name="deploy.source" value="MyApp.ear"/>
<!-- The list of target servers to which the application is deployed.
The value of this attribute is a comma-separated list of the target servers, clusters, or virtual hosts.
If you do not specify a target list when deploying an application, the target defaults to the Administration Server instance. -->
<property name="deploy.targets" value="MyCluster"/>
<!-- Deploying Applications -->
<target name="deploy">
<wldeploy action="deploy"
name="${deploy.name}"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
source="${deploy.source}"
targets="${deploy.targets}"/>
</target>
<!-- Redeploying Applications -->
<target name="redeploy">
<wldeploy action="redeploy"
name="${deploy.name}"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
targets="${deploy.targets}"/>
</target>
<!-- Undeploying Applications -->
<target name="undeploy">
<wldeploy action="undeploy"
name="${deploy.name}"
failonerror="false"
user="${username}"
password="${password}"
remote="true"
adminurl="t3://${host}:${port}"
targets="${deploy.targets}"/>
</target>
Please note that if we want to deploy the JAR or EAR to remote WebLogic server, we must explicitly set the remote attribute in wldeploy tag to true, since the default value is false.
More complete reference regarding the task can be found on https://docs.oracle.com/cd/E12839_01/web.1111/e13706/wldeploy.htm
The above task would work if you are just specifying the remote server file path. Essentially you would need two parameters one is remote and other being upload.
The same would work but i see an parameter is missing for the task if you are deploying from a remote server
<target name="deploy1">
<wldeploy action="deploy"
upload="true"
remote="true"
name="${deploy.name.1}"
source="${deploy.source.1}"
user="${wls.username}"
password="${wls.password}"
verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

Build fails on Jenkins but works in Eclipse

I got a Spring project built using Ant that fails when executed on Jenkins, but not when I run the exact same Ant target from Eclipse (Ant view).
Jenkins version is 2.19.4
Jenkins Console Output excerpt
Started by user Morin, Charles
Building in workspace D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs update -d -P -r HEAD -D 26 Jan 2017 10:09:39 -0500 MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs rlog -S -d25 Jan 2017 00:08:54 -0500<26 Jan 2017 10:09:39 -0500 MY-PROJECT
[MY-PROJECT] $ cmd.exe /C "D:\APPS\jenkins-2.19.4\ant\bin\ant.bat -file build.xml compile && exit %%ERRORLEVEL%%"
Buildfile: build.xml
[echo] ========================================================================
[echo] *** Starting MY-PROJECT build
[echo] ========================================================================
print-version:
[echo] Java/JVM version: 1.6
[echo] Java/JVM detailed version: 1.7.0_25
create-directories:
compile:
[javac] Compiling 41 source files to D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\target\classes
[javac] Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
[javac] D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\src\path\to\my\class\MyClass.java:28: error: cannot find symbol
[javac] import path.to.my.class.MyClass_;
[javac] ^
[javac] symbol: class MyClass_
[javac] location: package path.to.my.class
The problem is that my JPA metamodels are not being found during the compilation. However, we can see the following line that confirms the generation of JPA Metamodels:
Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
The only difference I can see is in the print-version Ant target. When executed locally, I got this:
print-version:
[echo] Java/JVM version: 1.7
[echo] Java/JVM detailed version: 1.7.0_25
I also have several other projects with the exact same setup, and I don't have that issue.
build.xml
<?xml version="1.0" encoding="utf-8"?>
<project name="MY-PROJECT" default="create-war-and-deploy-to-jboss" basedir="." xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property name="verbose" value="false" />
<property name="javaVersion" value="1.7" />
<!-- Provides access to OS environment variables (eg: env.USERNAME) -->
<property environment="env" />
<!-- Application's directories -->
<property name="dir.build" value="${basedir}/build" />
<property name="dir.src" value="${basedir}/src" />
<property name="dir.dist" value="${basedir}/dist" />
<property name="dir.lib" location="${basedir}/lib" />
<property name="dir.target" value="${basedir}/target" />
<property name="dir.build.classes" value="${dir.target}/classes" />
<property name="dir.test" value="${basedir}/test" />
<property name="dir.web" value="${basedir}/WebContent" />
<property name="dir.webinf.lib" value="${dir.web}/WEB-INF/lib" />
<!-- Loading the application.properties file -->
<property file="${dir.src}/resources/application.properties" prefix="app." />
<!-- Loading the build.properties file -->
<property file="build.properties" prefix="buildProp." />
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd HH:mm" />
</tstamp>
<echo message="========================================================================" />
<echo message="*** Starting ${app.name} build " />
<echo message="========================================================================" />
<!-- JBoss directories -->
<property name="dir.jboss" value="${buildProp.jboss.home}" />
<property name="dir.jboss.domain" value="${dir.jboss}/${buildProp.jboss.domain}" />
<property name="dir.jboss.libs" value="${dir.jboss}/${buildProp.jboss.libs}" />
<property name="dir.jboss.deploy" value="${dir.jboss.domain}/${buildProp.jboss.deploy}" />
<!-- Path for unit tests -->
<path id="run.classpath.tests">
<pathelement path="${dir.build.classes}" />
<pathelement path="${dir.test}/build/classes" />
<path refid="compile.classpath.tests" />
</path>
<!-- Provided dependencies from the container -->
<path id="compile.classpath.server">
<fileset dir="${dir.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Dependencies specific to this application -->
<path id="compile.classpath.web">
<fileset dir="${dir.web}/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
</path>
<path id="compile.classpath.target">
<fileset dir="${dir.lib}">
<include name="hibernate-jpamodelgen-5.1.0.Final.jar" />
</fileset>
<fileset dir="${dir.target}">
<include name="**/*.java" />
</fileset>
</path>
<!-- Dependencies specifically for unit testing purposes -->
<path id="compile.classpath.tests">
<fileset dir="${dir.test}/lib/">
<include name="junit-4.6.jar" />
<include name="mockito-all-1.9.5.jar" />
</fileset>
<fileset dir="${dir.webinf.lib}" />
<pathelement location="${dir.build.classes}" />
<path refid="compile.classpath.server" />
</path>
<!-- PRINT-VERSION -->
<target name="print-version">
<echo>Java/JVM version: ${ant.java.version}</echo>
<echo>Java/JVM detailed version: ${java.version}</echo>
</target>
<!-- BUILD-DISTRIBUTION -->
<target
name="build-distribution"
description="Generate Deployment unit and stage to appserver directory."
depends="
clean,
run-unit-tests,
create-war,
run-sonarqube-analysis">
<manifest file="${dir.web}/META-INF/MANIFEST.MF">
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Ant-Version" value="1.7.0" />
<attribute name="Created-By" value="${env.USERNAME}" />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="${app.version}" />
<attribute name="Implementation-Vendor" value="Canada Revenue Agency" />
<attribute name="Implementation-Date" value="${build.time}" />
<attribute name="Built-By" value="${env.USERNAME}" />
<attribute name="Dependencies" value="org.hibernate" />
</manifest>
<propertyfile file="${dir.src}/resources/application.properties">
<entry key="lastUpdate" value="${build.time}" />
</propertyfile>
</target>
<!-- CLEAN -->
<target name="clean"
description="Cleans up build-related temporary directories."
depends="delete-directories" />
<!-- CREATE-DIRECTORIES -->
<target name="create-directories" >
<mkdir dir="${dir.build}" />
<mkdir dir="${dir.dist}" />
<mkdir dir="${dir.build.classes}" />
<mkdir dir="${dir.web}/WEB-INF/classes" />
<mkdir dir="${dir.test}/build" />
<mkdir dir="${dir.test}/build/classes" />
<mkdir dir="${dir.test}/reports" />
</target>
<!-- DELETES-DIRECTORIES -->
<target name="delete-directories">
<delete dir=".sonar" />
<!-- /build -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.build}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /dist -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.dist}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /WEB-INF/classes -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.web}/WEB-INF/classes">
<include name="**/*" />
</fileset>
<fileset dir="${dir.web}/WEB-INF/src">
<include name="**/*" />
</fileset>
</delete>
<!-- /target -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.target}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /test/build -->
<delete dir="${dir.test}/build" />
<!-- /test/reports -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.test}/reports" />
</delete>
<!-- Existing WAR file and JBoss marker files -->
<delete dir="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
</target>
<!-- COMPILE -->
<target name="compile" depends="print-version,create-directories">
<javac destdir="${dir.build.classes}" verbose="${verbose}" debug="on" fork="true" failonerror="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath>
<path refid="compile.classpath.server" />
<path refid="compile.classpath.target" />
<path refid="compile.classpath.web" />
</classpath>
<src path="${dir.src}" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
<!--copy property files to classes directory -->
<copy todir="${dir.build.classes}">
<fileset dir="${dir.src}">
<include name="**/*.properties" />
<include name="META-INF/**/*" />
</fileset>
</copy>
</target>
<!-- COMPILE-TESTS -->
<target name="compile-tests" depends="create-directories,compile">
<javac srcdir="${dir.test}/src" destdir="${dir.test}/build/classes" verbose="${verbose}" debug="on" fork="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath refid="compile.classpath.tests" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>
<!-- RUN-UNIT-TESTS -->
<target name="run-unit-tests" depends="compile-tests" description="Runs all unit test classes under the test package.">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="test/lib/org.jacoco.ant-0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.agent_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.core_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.report_0.7.2.201409121644.jar"/>
</taskdef>
<jacoco:coverage destfile="${dir.target}/jacoco.exec">
<junit fork="true" printsummary="yes" haltonfailure="yes" showoutput="no">
<classpath refid="run.classpath.tests" />
<formatter type="xml" />
<batchtest fork="yes" todir="${dir.test}/reports">
<fileset dir="${dir.test}/src">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<!-- CREATE-WAR -->
<target name="create-war" description="Creates a WAR file including all compiled classes and resources." depends="compile">
<war destfile="dist/${app.name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<classes dir="${dir.build.classes}" />
</war>
</target>
<!-- CREATE-WAR-AND-DEPLOY -->
<target name="create-war-and-deploy-to-jboss" description="Creates a WAR file including all compiled classes and resources, and deploys the app to jboss" depends="create-war,deploy-to-jboss" />
<!-- RUN-SONARQUBE -->
<target name="run-sonarqube-analysis" description="Runs the SonarQube analysis and updates statistics on the server." depends="create-war">
<property file="sonar.properties" prefix="sonar." />
<!-- SonarQube properties -->
<property name="sonar.exclusions" value="${sonar.exclusions}" />
<property name="sonar.host.url" value="${sonar.host.url}" />
<property name="sonar.jacoco.reportPath" value="${sonar.jacoco.reportPath}" />
<property name="sonar.java.binaries" value="${sonar.java.binaries}" />
<property name="sonar.java.coveragePlugin" value="${sonar.java.coveragePlugin}" />
<property name="sonar.java.libraries" value="${sonar.java.libraries}" />
<property name="sonar.java.source" value="${javaVersion}" />
<property name="sonar.junit.reportsPath" value="${sonar.junit.reportsPath}" />
<property name="sonar.projectKey" value="${sonar.projectKey}" />
<property name="sonar.projectVersion" value="${app.version}" />
<property name="sonar.projectName" value="${sonar.projectName}" />
<property name="sonar.sources" value="${sonar.sources}" />
<property name="sonar.sourceEncoding" value="${sonar.sources.sourceEncoding}" />
<property name="sonar.tests" value="${sonar.tests}" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${dir.lib}/sonarqube-ant-task-2.4.1.jar" />
</taskdef>
<sonar:sonar/>
</target>
<!-- DEPLOY-TO-JBOSS -->
<target name="deploy-to-jboss" depends="create-war">
<!--delete war file if it already exists and was copied over, we need a directory now-->
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
<!-- copy all of the files except one that will trigger the deployment -->
<copy todir="${dir.jboss.deploy}">
<fileset file="${dir.dist}/${app.name}.war" />
</copy>
</target>
</project>
Thank you
From Manage Jenkins-->Configure System--JDK section, add both JDKs to JDK Installation. From your Job Configuration, in the JDK section, explicitly choose the 1.7 JDK.

Could not execute jacoco on jenkins

When i am trying to gt sonar code coverage of my project through jenkins, i am getting the following error:
Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
but when i am executing it through eclipse it does not show any error. code is same in both case and i have checked that in case of jenkins jacocoant.jar is included.
here is my code:
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="../monet-main/lib/dev/sonar/jacocoant.jar" />
</taskdef>
<property name="sonar.tests" value="test" />
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.surefire.reportsPath" value="output/site/jacoco" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="output/jacoco.exec" />
<target name="test">
<mkdir dir="output/report/junit" />
<javac debug="true" includeantruntime="false" nowarn="true" debuglevel="${debuglevel}" destdir="bin"
encoding="UTF-8" source="1.6" target="1.6" srcdir="test">
<classpath refid="monet-service.classpath" />
</javac>
<jacoco:coverage destfile="${result.exec.file}">
<junit haltonfailure="yes" fork="true">
<classpath>
<path refid="monet-service.classpath" />
<pathelement path="bin" />
</classpath>
<formatter type="plain" usefile="false" />
<formatter type="xml" />
<batchtest fork="yes" todir="output/report/junit">
<fileset dir="test">
<include name="**/CommonTest.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="testReport" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.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>
<!-- Define the SonarQube target -->
<target name="sonar" depends="testReport">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="../monet-main/lib/dev/sonar/sonar-ant-task-2.2.jar" />
</taskdef>
<!-- Execute the SonarQube analysis -->
<sonar:sonar/>
</target>
Is there any problem..

Delete files specified via a zipfileset?

I have the following Ant target which extracts contents from a specific .ZIP archive:
<!-- UNPACK-MATH -->
<target name="unpack-math" depends="init-contrib">
<!-- NOTE: the 'unzip' task doesn't fail when it cannot extract over read-only files; however, 'copy' with a 'zipfileset' does. -->
<first id="math.archive">
<fileset dir="${builddir}" includes="MATH_MF*.zip" />
</first>
<if>
<length string="${toString:math.archive}" when="greater" length="0" />
<then>
<copy todir="${basedir}">
<zipfileset src="${toString:math.archive}" />
</copy>
</then>
<else>
<echo message="No math to unpack." />
</else>
</if>
</target>
What I'd like to do now is "clean up" the files that were extracted. However, the following does not work:
<!-- CLEAN-MATH -->
<target name="clean-math" depends="init-contrib">
<first id="math.archive">
<fileset dir="${builddir}" includes="MATH_MF*.zip" />
</first>
<if>
<length string="${toString:math.archive}" when="greater" length="0" />
<then>
<delete>
<zipfileset src="${toString:math.archive}" />
</delete>
</then>
<else>
<echo message="No math to clean." />
</else>
</if>
</target>
I get the following stack trace:
BUILD FAILED
D:\Development\MForce\Games\gamebuild.xml:214: java.lang.ClassCastException: class org.apache.tools.ant.types.resources.ZipResource doesn't provide files
at org.apache.tools.ant.types.resources.comparators.FileSystem.resourceCompare(FileSystem.java:43)
...
Any ideas?
This solution appears to work, but requires unpacking the .ZIP archive (which lists the files you'd like to delete as some other root) first, which I'd prefer to avoid:
<!-- CLEAN-MATH -->
<target name="clean-math" depends="init-contrib">
<first id="math.archive">
<fileset dir="${builddir}" includes="MATH_MF*.zip" />
</first>
<if>
<length string="${toString:math.archive}" when="greater" length="0" />
<then>
<unzip dest="${builddir}/tmp" src="${toString:math.archive}"/>
<delete>
<fileset dir="${basedir}" includes="**/*">
<present present="both" targetdir="${builddir}/tmp"/>
</fileset>
</delete>
<delete dir="${builddir}/tmp"/>
</then>
<else>
<echo message="No math to clean." />
</else>
</if>
</target>

Resources