How to correctly build with ant using drools? - java

I am trying to build drools with ant using DroolsCompilerAntTask but I keep running into errors. I was wondering if my setup is wrong or something that should be configured differently.
build.xml
...
<taskdef name="droolscompiler" classpathref="java:buildtime.classpath" classname="org.drools.contrib.DroolsCompilerAntTask" />
<path id="build.path">
<pathelement location="${homedir}/build" />
</path>
<target name="verify-rules">
<droolscompiler srcdir="${homedir}/src/rules" tofile="${homedir}/build/rules.pkg"
binformat="package" classpathref="build.path">
<include name="**/*.drl" />
</droolscompiler>
</target>
...
The error message I got was
BUILD FAILED
C:\Users\John\workspace\project\tools\build.xml:55:
RuleBaseTask failed: Unable to load dialect 'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
Total time: 45 seconds
Update: I only want to compile the rules. I dont need to compile the java files.
Update: Drools versions -
drools-compiler-5.4.0.Final.jar
drools-core-5.4.0.Final-sources.jar
drools-core-5.4.0.Final.jar
drools-decisiontables-5.4.0.Final.jar
drools-jsr94-5.4.0.Final.jar
drools-spring-5.4.0.Final.jar
drools-templates-5.4.0.Final.jar
drools-ant-5.4.0.final.jar

Related

Javac inexplicably failing on Hudson

Our application is built my Hudson from Ant scripts. In my latest work I've recently included Maven. Now Hudson's build process fails when it reaches the compilation task without any explanation.
Hudson build:
[echo] Using Maven Repo at ../.maven/repo/
[javac] Compiling 134 source files to C:\Users\administrator1\.hudson\jobs\SAP_RC\workspace\current\classes
BUILD FAILED
C:\Users\administrator1\.hudson\jobs\SAP_RC\workspace\current\build.xml:68: Error running C:\Program Files (x86)\Java\jdk1.8.0_66\bin\javac.exe compiler
Ant script:
<javac classpathref="lib" destdir="${classesDir}" debug="true" debuglevel="lines,vars,source" verbose="true" fork="true" nowarn="true" memoryMaximumSize="320m" srcdir="${srcDir}" includeantruntime="false" />
I specifically included the Maven repo into the classpath, and that's when it fails inexplicably. When I remove the Maven repo the build throws a compilation error complaining that it can't find Maven dependencies. This makes me suspect that I'm hitting some classpath length limit.
I did it this way because I'm not sure what is the correct way to include Maven dependencies into the classpath. If there is a better way please tell me and I'll open a new question specifically for that.
It seems as though my wildcard in my fileset was the culprit.
<path id="lib">
<fileset dir="${env.maven_repo}">
<include name="*/**"/>
</fileset>
</path>
I changed the ** to *.jar and the build process is no longer (inexplicably) failing.
<path id="lib">
<fileset dir="${env.maven_repo}">
<include name="*/*.jar"/>
</fileset>
</path>

Fail build on PMD errors/warnings

I have a JAVA ANT project and I am trying to integrate PMD scripts with it so that I can check for all errors and warnings in my project.
Below is snippet of ANT script which I have added in my build.xml:
<property name="pmd.dir" value="buildconfig/build/pmd/" />
<path id="pmd.lib" >
<fileset dir="${pmd.dir}">
<include name="*.jar"/>
<exclude name="/rulesets" />
</fileset>
</path>
<target name="pmd" depends="init">
<echo message="PMD Starting-----" />
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.lib"/>
<pmd shortFilenames="true">
<ruleset>unusedcode</ruleset>
<formatter type="text" toFile="${pmd.dir}/pmd-ant-results.txt"/>
<fileset dir="modules/app/">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
ANT build is working fine with PMD giving proper error reports but I need to abort the build as failure when PMD encounters any errors in code.
I tried adding failOnRuleViolation="yes" but that did not stop build.
Is there anything else I need to add in script?
Try failOnRuleViolation="true" instead of failOnRuleViolation="yes"...
<pmd shortFilenames="true" failOnRuleViolation="true">
...
Some Ant tasks treat true and yes as equivalent, but many tasks don't know how to handle yes at all. It is possible that <pmd> is one of those tasks that doesn't handle yes.
As a rule of thumb, avoid this gotcha in the future by always using true and false instead of yes and no.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console

I am trying to use log4j2 in my Ant build.xml to create executable .jar. The jar works fine but it seems like log4j2.xml is not being recognized. I currently have the file under src folder. and have classpath set in my build.xml as below. This happens for all my projects. What would be the proper directory to put log4j2.xml? Is there something other than adding it to classpath in build.xml to do?
<path id = "classpath">
<pathelement location="${junitJar}/junit-4.11.jar"/>
<pathelement location="${junitJar}/hamcrest-core-1.3.jar" />
<pathelement location="${classes.dir}"/>
<pathelement location="${log4jJar}/log4j-api-2.1.jar" />
<pathelement location="${log4jJar}/log4j-core-2.1.jar" />
<pathelement location="${src.dir}/log4j2.xml" />
</path>
compile:
jar:
run:
[java] ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
[java] Hello World!
main:
BUILD SUCCESSFUL
Total time: 1 second
Changing the last pathelement to:
<pathelement location="${src.dir}/" />
will work, but in practice you should probably have this file somewhere else.
In an ant build it's normal to copy these files into the classes directory so it gets included in the jar file.

Ant compile does not recognize plugin.jar library

i am facing an issue in an ant build xml during compile process. My Ant command is pretty simple:
<target name="compile" description="Compilation target">
<javac srcdir="src" destdir="JARbuild">
<compilerarg value="-Xlint:deprecation"/>
</javac>
</target>
However i always get the following error
error: cannot find symbol
private final static JSObject jso = JSObject.getWindow(JMain.getInstance());
I am able to compile my project with netbeans ide, without running into an error, since the corresponding jar file (plugin.jar) is recognized as a library. I tried to add the library to classPath by setting sth. similar to:
<classpath>
<path>
<pathelement location="C:\Program Files\Java\jre7\lib\plugin.jar" />
</path>
</classpath>
However error still occurs. Somebody got a solution?
Thanks.
Have you tried using escaped-backlashes, or unix-style seprators in your Windows path?
E.g.
<pathelement location="C:\\Program Files\\Java\\jre7\\lib\\plugin.jar"
or
<pathelement location="C:/Program Files/Java/jre7/lib/plugin.jar"

Cobertura ant script is missing Log4J classes

I tried to get Cobertura running inside my ant script, but I'm stuck right at the beginning. When I try to insert the cobertura taskdef I'm missing the Log4J libraries.
Ant properties & classpath
<property name="cobertura.dir" location="/full/path/to/cobertura-1.9.3" />
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
My ant target
<!-- =================================
target: cobertura
================================= -->
<target name="cobertura" depends="clean, init" description="Generates cobertura coverage reports">
<cobertura-instrument todir="${dir.build.instrumented}">
<fileset dir="${dir.build}">
<include name="**/*.class" />
</fileset>
</cobertura-instrument>
</target>
I think I did everything like it is described in the Cobertura documentation but I get this
Ant build error
BUILD FAILED
build.xml:95: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
Inside the ${cobertura.dir} there is the lib directory with all files. I unzipped it from the cobertura distribution ZIP directly into that directory.
Am I missing a step? Something wrong with my configuration so far?
I also encountered this problem today and solved it by specifying the location of all the required libraries as part of the class path provided to my taskDef task.
<path id="cobertura.class.path">
<pathelement location="${common.dir}/../tools/cobertura/cobertura.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/asm-3.0.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/asm-tree-3.0.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/log4j-1.2.9.jar" />
<pathelement location="${common.dir}/../tools/cobertura/lib/jakarta-oro-2.0.8.jar" />
</path>
<taskdef classpathref="cobertura.class.path" resource="tasks.properties" />
Go to your ant/lib dir and make sure there is NO file cobertura.jar there. If it's there - remove it and try again.
Change this
<include name="lib/**/*.jar" />
to
<include name="*.jar" />
Hope this helps!
I just upgraded to the latest cobertura and mine works fine. Is it possible that something else is on the CLASSPATH with a different version of log4j so it is picking up wrong one?
Make sure that classpath used in taskdef and cobertura-instrument are the same. This helped me with the same issue.
I too faced this problem, I just added all jars given with cobertura in the classpath to resolve this issue

Categories

Resources