Here's how I am trying to load and reference the ruleset.xml file,
<property name="xms3k-build.pmd.rule.url" value="${xms3k-build.url}/${xms3k-build.version}/ruleset.xml" />
<property name="xms3k-build.pmd.rule.file" value="${xms3k-build.dir}/ruleset.xml" />
<!-- PMD static analysis task. -->
<target name="pmd" depends="compile, init-pmd">
<path id="pmd.aux.classpath">
<fileset dir="${lib.dir}/${ivy.conf.test}"/>
</path>
<pmd rulesetfiles="xms3k-build.pmd.rule.file" >
<formatter type="xml" toFile="pmd_report.xml" />
<fileset dir="${source.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${source-test.dir}">
<include name="**/*.java" />
</fileset>
</pmd>
The following error occurred while executing this line:
common.xml:481: Can't find resource 'null' for rule 'xms3k-build.pmd.rule.file'.
Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /usr/share/java/ant.jar:/usr/share/java/ant-launcher.jar:/usr/share/java/jaxp_parser_impl.jar:/usr/share/java/xml-commons-apis.jar:/usr/share/java/junit.jar:/usr/share/java/ant/ant-junit.jar:/usr/share/java/junit.jar:/usr/share/java/ant/ant-junit4.jar:/usr/java/jdk1.7.0_45/lib/tools.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-junit4.jar:/usr/share/ant/lib/ant-bootstrap.jar:/usr/share/ant/lib/ant-junit.jar
I have tried many variants of the style.xml file. Here is what I am currently trying:
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
This ruleset checks my code for bad stuff
</description>
<rule ref="rulesets/strings.xml"/>
</ruleset>
As adangel has posted in a comment the answer lied in a typo,
As "ms3k-build.pmd.rule.file" is a property, I'd try to use it like this: <pmd rulesetfiles="${xms3k-build.pmd.rule.file}" > – adangel
Related
I am using Eclipse Helios with Tomcat 7 on Windows and have imported Apache Ant-1.8.4 and works fine but I had to set up the same environment on another machine and when I attempted to build the project using Ant in Eclipse it failed with the following message;
C:\eclipsehelios\workspace\projectname\build.xml:207: Problem: failed to
create task or type emmajava
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken
place
I have had this error before and just required to ensure the build file had the correct path to the Ant folder but this didn't resolve things this time. I found by copying in the following files to the Ant's lib folder solved the problem but these were not required in my own PC and wondered if someone would tell me if this was the correct way to resolve this problem and if so why do I not require these on my own PC?
antlr-2.7.6.jar
commons-beanutils-1.8.3-javadoc.jar
commons-beanutils-1.8.3-sources.jar
commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-cli-1.2-javadoc.jar
commons-cli-1.2-sources.jar
commons-cli-1.2.jar
commons-logging.jar
ganymed.jar
guava-13.0.1-sources.jar.sav
guava-13.0.1.jar.sav
guava-gwt-13.0.1-sources.jar.sav
guava-r07-javadoc.jar.sav
guava-r07-sources.jar.sav
guava-r07.jar.sav
jna.jar
svnant-1.3.1.jar
svnant.jar
svnClientAdapter.jar
svnjavahl.jar
svnkit.jar
EDIT:
If I click on the line "C:\eclipsehelios\workspace\projectname\build.xml:207" it goes to the following section of the build file with the top line "
<emmajava enabled="${emma.enabled}" libclasspathref="emma.lib"
fullmetadata="yes" filter="${emma.filter}" sourcepath="src"
classname="the.company.domain.test.EmmaLoginMain">
<classpath>
<pathelement path="test" />
<pathelement path="build/classes" />
<pathelement path="build_tests/classes" />
<pathelement path="test" />
<fileset dir="${libDir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${tomcat_lib}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${test_lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
<!-- regular <java> options are still available: -->
<!--<arg value="somearg" /> -->
<!-- <emmajava> option extensions [see the reference manual for
complete details]: -->
<xml outfile="${test.reports.dir}/emma/coverage.xml" />
<txt outfile="${test.reports.dir}/emma/coverage.txt" />
<html outfile="${test.reports.dir}/emma/coverage.html" />
</emmajava>
I have a ant build script which creates a war file. The file content are as follows.
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestProj" default="war" basedir=".">
<property name="project-name" value="${ant.project.name}" />
<property name="builder" value="IaasTeam" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src" />
<property name="classes-directory" value="build/classes" />
<property name="web-directory" value="WebContent" />
<property name="web-xml-file" value="WebContent/WEB-INF/web.xml" />
<property name="lib.dir" value="WebContent/WEB-INF/lib" />
<property name="catalina.home" value="../../outside/project/lib"/>
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<property name="build-directory" value="build" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${catalina.home}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac includeantruntime="false" srcdir="src" destdir="build/classes" classpathref="classpath" />
</target>
<target name="war" depends="clean,compile">
<mkdir dir="${build-directory}" />
<delete file="${build-directory}/${war-file-name}" />
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${classes-directory}" />
<fileset dir="${web-directory}">
<!-- Need to exclude it since webxml is an attribute of the war tag above -->
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
I am using Jenkins as a build server (this is hosted on different machine kind of DEV environment).
I also use Gitlab as a repository and after pushing the latest code I have a hook for Jenkins job which gets triggered automatically and calls this build.xml.
Now the issues here is that when I run this script on my local machine everything works well but when Jenkins execute this it fails during the compilation phase giving me below error.
compile:
[mkdir] Created dir: /app/infra/jenkins/workspace/TestProj/build/classes
[javac] Compiling 49 source files to /app/infra/jenkins/workspace/TestProj/build/classes
BUILD FAILED
/app/infra/jenkins/workspace/TestProj/build.xml:27: /app/infra/jenkins/outside/project/lib does not exist.
The reason for this issue is the build server does not have any directoy called outside/project/lib.
The only reason of adding this directory in my build.xml is to have the container specific jar files ready for compiling.
How can I fix this issue?
Do I need to copy container specific jars on my build server? Or is there any way to tell Jenkins that not to copy this external jars but just use them for compilation.
Where would Jenkins find the jars? They need to be accessible otherwise your build will fail. If you don't want to have the files checked in (which is very sensible), you could use Apache Ivy to download them for you.
This is the most common way of handling the situation you're having. Using a dependency management framework like Ivy (or Maven, or similar) will save you a lot of headaches down the line. I recommend you have a look at their tutorial. After you set it up, your ant build will take care of downloading the files you need.
I have the following problem in ant:
[taskdef] Could not load definitions from resource net/sf/antcontrib/antcontri
b.properties. It could not be found.
BUILD FAILED
build.xml:5: Problem:
failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Running the following ant build.xml:
<?xml version="1.0"?>
<project default="main" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<classpath>
<fileset dir=".">
<include name="**/*.jar" />
</fileset>
</classpath>
<target name="main">
</target >
</project>
Although, running
<project default="main" basedir=".">
<path id="path.svnant">
<pathelement location="${basedir}/ant-contrib-1.0b3.jar" />
</path>
<typedef resource="net/sf/antcontrib/antcontrib.properties" classpathref="path.svnant" />
<target name="main">
</target >
</project>
Results no errors what so ever.
So the question is why the first build.xml is wrong??
I suppose because <classpath/> element must be inside </taskdef> element.
<taskdef resource="net/sf/antcontrib/antcontrib.properties" >
<classpath>
<fileset dir=".">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>
How can we add additional parameters to manifest file using Maven to third party jars. After Java 7_25 version the Java web start requires codebase and permissions to be add in all downloading jar files. I want to insert them jar singing time.
Please let me know if you need any information. Thanks in advance.
i made a little ant script (this is an extract, in fact it also excludes some crypto file).
just set directory property value to a directory that contains jars to be updated and launch the target "give-permissions".
it should be easy to use with maven-ant:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="project">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property name="directory" value="WebContent/jnlpApplication" />
<target name="give-permissions">
<foreach target="_re-jar" param="currentFile" parallel="false">
<path>
<fileset dir="${directory}" casesensitive="yes">
<include name="**/*.jar" />
</fileset>
</path>
</foreach>
<move todir="${directory}" overwrite="true">
<fileset dir="${directory}.tmp" casesensitive="yes">
<include name="**/*.jar" />
</fileset>
</move>
<delete dir="${directory}.tmp" />
</target>
<target name="_re-jar">
<basename property="filename" file="${currentFile}" />
<jar destfile="${directory}.tmp/${filename}">
<zipfileset src="${currentFile}">
<exclude name="META-INF/**.RSA" />
<exclude name="META-INF/**.SF" />
</zipfileset>
<manifest>
<attribute name="Permissions" value="all-permissions" />
<attribute name="Codebase" value="*" />
<attribute name="Application-Name" value="jnlpApplicationName" />
</manifest>
</jar>
</target>
</project>
Given a zipfile with an unknown directory, how can I rename or move that directory to a normalized path?
<!-- Going to fetch some stuff -->
<target name="get.remote">
<!-- Get the zipfile -->
<get src="http://myhost.com/package.zip"
dest="package.zip"/>
<!-- Unzip the file -->
<unzip src="package.zip"
dest="./"/>
<!-- Now there is a package-3d28djh3 directory. The part after package- is
a hash and cannot be known ahead of time -->
<!-- Remove the zipfile -->
<delete file="package.zip"/>
<!-- Now we need to rename "package-3d28djh3" to "package". My best attempt
is below, but it just moves package-3d28djh3 into package instead of
renaming the directory. -->
<!-- Make a new home for the contents. -->
<mkdir dir="package" />
<!-- Move the contents -->
<move todir="package/">
<fileset dir=".">
<include name="package-*/*"/>
</fileset>
</move>
</target>
I'm not much of an ant user, any insight would be helpful.
Thanks much, -Matt
This will only work as long as the dirset only returns 1 item.
<project name="Test rename" basedir=".">
<target name="rename">
<path id="package_name">
<dirset dir=".">
<include name="package-*"/>
</dirset>
</path>
<property name="pkg-name" refid="package_name" />
<echo message="renaming ${pkg-name} to package" />
<move file="${pkg-name}" tofile="package" />
</target>
</project>
If there are no subdirectories inside the package-3d28djh3 directory (or whatever it is called once you extracted it) you can use
<move todir="package" flatten="true" />
<fileset dir=".">
<include name="package-*/*"/>
</fileset>
</move>
Otherwise, use the regexp mapper for the move task and get rid of the package-xxx directory:
<move todir="package">
<fileset dir=".">
<include name="package-*/*"/>
</fileset>
<mapper type="regexp" from="^package-.*/(.*)" to="\1"/>
</move>