XJC with Krasa Plugin - ant

Hello i get a build error when i execute the following ant-script. Can somebody help me to resolve the problem?
ANT output:
Buildfile: D:\workspace\Webformular2\WebContent\WEB-INF\XSD-Pfad.ant
[delete] Deleting directory D:\workspace\Webformular2\WebContent\WEB-INF\src
[mkdir] Created dir: D:\workspace\Webformular2\WebContent\WEB-INF\src xjc:
[xjc] Consider using <depends>/<produces> so that XJC won't do unnecessary compilation
[xjc] Compiling file:/D:/workspace/Webformular2/WebCo ntent/WEB-INF/jaxb/antragsdaten.xsd and others
BUILD FAILED D:\workspace\Webformular2\WebContent\WEB-INF\XSD-Pfad.ant:11: java.lang.NoClassDefFoundError: javax/validation/constraints/NotNull
Ant script
<project default="xjc">
<delete dir="src"/>
<mkdir dir="src" />
<target name="xjc" description="JAXB Generation">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<fileset dir="lib" includes="*.jar" />
</classpath>
</taskdef>`
`
<xjc destdir="src" extension="true">
<schema dir="jaxb" includes="*.xsd"/>
<arg line="
-XJsr303Annotations
-XReplacePrimitives"/>
</xjc>
</target>
</project>`

------- Ant-Skript ---------
<project default="xjc">
<delete dir="src"/>
<mkdir dir="src" />
<target name="xjc" description="JAXB Generation">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<fileset dir="lib" includes="*.jar" />
</classpath>
</taskdef>
<xjc destdir="src" extension="true">
<schema dir="jaxb" includes="*.xsd"/>
<arg line="
-XJsr303Annotations
-XReplacePrimitives"/>
</xjc>
</target>
</project>

You're missing the "validation-api.jar" in your lib directory.
Reference:
Maven Central search for missing class "javax/validation/constraints/NotNull"

Related

PMD ANT script gives taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="info" name="MyProject">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<property name="jar.name" value="${ant.project.name}"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="true" nowarn="true" debuglevel="lines,vars,source"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${jar.name}.jar" basedir="${classes.dir}">
<exclude name="**/Main.class" />
<fileset dir="${src.dir}" includes="**/*.java">
<exclude name="**/Main.java" />
</fileset>
<zipgroupfileset dir="${lib.dir}" includes="*.jar">
<exclude name="**/Utils.jar" />
</zipgroupfileset>
</jar>
</target>
<target name="build" depends="jar"/>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" />
<target name="pmd">
<pmd shortFilenames="true" failuresPropertyName="failures.count" rulesetfiles="\path\pmd\ruleSet.xml">
<formatter type="html" toFile="pmd_report.html" toConsole="true"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
<target name="info">
<echo message="Available Targets:"/>
<echo message=" clean"/>
<echo message=" compile"/>
<echo message=" jar"/>
<echo message=" build"/>
<echo message=" pmd"/>
</target>
</project>
This script gives me this " taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]"
I have added PMD library jar file in lib folder of the project,where other libraries are present as jar files.
But if i change add path ref to the library not as a jarfile , it works well.
<path id="pmd.classpath">
<fileset dir="C:\Users\PMD\pmd-bin-5.5.2">
<include name="**/*.jar"/>
</fileset>
</path>
May I know what is the problem? I am pretty new to ANT and PMD , any help will be appreciated.
Thanks
First thing to check is the file pmd-core-*.jar in your lib directory?
Secondly add a reference to the path in the taskdef task:
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="classpath"/>

How can I zip each file separately instead of putting in one archive?

I have 3 files (eg: m1.txt, m2.txt and m3.txt) in my /tmp/ folder. How can I zip each files as m1.zip, m2.zip and m3.zip?
I used the following coding, but didn't work:
<target name="xzipit">
<foreach target="zipone" param="Files">
<path>
<fileset dir="/tmp/" excludes="*.zip"
includes="*.txt" casesensitive="no" />
</path>
</foreach>
</target>
<target name="zipone">
<zip destfile="${Files}" basedir="/tmp/">
</zip>
</target>
Note use of fileset id, refid usage below and also on specifying includesfile to zip ant task
<fileset dir="/tmp" excludes="*.zip" includes="*.txt" id="zip.fileset.id" casesensitive="no" />
<pathconvert property="zipFileSetProp" refid="zip.fileset.id">
<mapper>
<flattenmapper/>
</mapper>
</pathconvert>
<for list="${zipFileSetProp}" param="fileToZip" delimiter=";">
<sequential>
<echo>fileToZip #{fileToZip}</echo>
<zip destfile="/tmp/#{fileToZip}.zip" basedir="/tmp/" includesfile="/tmp/#{fileToZip}"/>
</sequential>
</for>
I got one more answer to solve this.
<project name="texzip" basedir="." default="zipit">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/tmp/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="zipit">
<foreach target="zipone" param="Files">
<path>
<fileset dir="/tmp/" excludes="*.zip" includes="*.txt" casesensitive="no" />
</path>
</foreach>
</target>
<target name="zipone">
<basename property="basename" file="${Files}" suffix="txt"/>
<zip destfile="${basename}.zip">
<zipfileset dir="." includes="${basename}.txt"/>
</zip>
</target>
</project>

Groovy-TestNG-Ant running error

I've faced with next problem.
Trying to create pilot test-project using Groovy, TestNG, ant.
If I run tests from my IDE (Eclipse) - all is ok.
But when I try run tests using ant - not easy for me problem. Could you help me?
build.xml is present below.
Compile target - pass ok, but on runTest target I see problem:
"Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject"
<project basedir="." default="runTest" name="Ant file for TestNG">
<property name="src" location="src" />
<property name="build" location="build" />
<property name="libs" location="lib" />
<path id="class.path">
<pathelement location="${libs}/testng.jar" />
<pathelement location="lib/testng.jar"/>
<pathelement location="${build}" />
</path>
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/groovy-all.jar"/>
<pathelement location="lib/testng.jar"/>
</classpath>
</taskdef>
<target name="runTest" depends="compile">
<mkdir dir="testng_output"/><!-- Create the output directory. -->
<testng outputdir="testng_output" classpathref="class.path">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
<target name="compile">
<delete dir="build"/>
<mkdir dir="build"/>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpath="lib/groovy-all.jar"/>
<groovyc srcdir="src" destdir="./build">
<classpath>
<pathelement path="lib/groovy-all.jar"/>
<pathelement path="lib/testng.jar"/>
</classpath>
<javac source="1.7" target="1.7" debug="off" />
</groovyc>
</target>
</project>
And this is testng.xml
<suite name="My Test Suite" parallel="methods" thread-count="5">
<test name="My Test">
<classes>
<class name="test1" />
</classes>
</test>
</suite>

Build.xml issue

Selenium - ANT -TestNG
I have written a build.xml, where it produces a error stating " classname attribute of taskdef element is undefined "
Here is my build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name ="AutomationScripts" default="test" basedir=".">
<echo message ="Testing selenium server... Plz wait"/>
<target name="startServer">
<echo message ="Start selenium server... Plz wait"/>
<java jar="..\lib\selenium-server-standalone-2.19.0.jar" fork="true">
<jvmarg value="-Dhttp.proxyHost=192.168.0.200"/>
<jvmarg value="-Dhttp.proxyPort=3128"/> </java>
<echo message ="Started selenium server"/>
</target>
<target name="test" depends="startServer">
<echo message="Test run. Please wait"/>
<mkdir dir="out" />
<java classname="RosettastoneMain" classpath="..\AutomationScripts\bin"
dir="C:\Program Files\Java\jdk1.6.0_11\bin">
<classpath>
<fileset dir="..\AutomationScripts\lib" includes="*.*"/>
</classpatha></java>
<taskdef name="testng" classpath="org.testng.TestNG"> ---------> It produces
error in this stmt
<classpath>
<pathelement location="../lib/testng-6.2.jar"/>
</classpath>
</taskdef>
<property name="testng.output.dir" value="testngOutput"/>
<path id="classes">
<fileset dir="../lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${bin.dir}"/>
</path>
<mkdir dir="${testng.output.dir}"/>
<testng outputdir="${testng.output.dir}" classpathref="classes">
<xmlfileset dir="." includes="testng.xml"/>
</testng> </target>
<target name="stopServer">
<echo message="stop selenium server. Plz wait"/>
<get taskname="selenium-shutdown"
src="http://localhost:4444/selenium-server-standalone-2.0rc2/driver/?cmd=shutDown"
dest="./out/sever.stop.status.txt" ignoreerrors="true"/>
</target>
</project>
Can any one help me out
thanks in advance
You need to specify the class implementing the data type in the 'classname' attribute.
According to the Ant taskdef documentation (and more specifically typedef), this task has two required attributes - 'name' and 'classname', unless 'file' or 'resource' have been specified. The attribute 'classpath' only defines the locations where the class specified in 'classname' can be found.

ant build script issue

I have 2 ant build scripts named "build" and "tarne"
Build:
<?xml version="1.0" ?>
<project name="build" default="zip">
<property name="project.name" value="projectName"/>
<property name="version" value="default_version_value"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/build/ant-contrib.jar"/>
</classpath>
</taskdef>
<var name="version2" value="default_version_value"/>
<property name="tmp" value="tmp"/>
<property name="build.dir" location="${tmp}/component/${project.name}"/>
<property name="java.classes" location="${tmp}/component/${project.name}/classes"/>
<property name="weblayout.dir" location="${tmp}/weblayout/resources/${project.name}"/>
<path id="compile.classpath">
<fileset dir="lib" includes="**/*.jar" />
<fileset dir="lib/build" includes="*.zip" />
</path>
<target name="clean">
<delete dir="${tmp}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${java.classes}" />
</target>
<target name="compile" depends="init">
<javac srcdir="src" source="1.5" target="1.5" encoding="utf-8" includes="**/*.java" destdir="${java.classes}" classpathref="compile.classpath" />
</target>
<target name="copy-resources" depends="compile">
//Lots of copying here
</target>
<target name="read.version" description="Parses the hda file for your version number">
<property file="${project.name}.hda" prefix="hda"/>
<propertyregex property="version" input="${hda.version}" regexp="\." replace="-" global="true" override="true"/>
<var name="version2" value="${version}"/>
<echo>${version}</echo>
<echo>${version2}</echo>
</target>
<target name="zip" depends="copy-resources, read.version" description="Package component">
<zip destfile="${project.name}-${version}.zip" basedir="${tmp}" />
<delete dir="${tmp}" />
</target>
</project>
Tarne:
<?xml version="1.0" ?>
<project default="tarne">
<include file="build.xml"/>
<property name="project.name" value="build.project.name"/>
<target name="tarne">
<antcall target="build.read.version" inheritRefs="true"></antcall>
<property name="version" value="build.version"/>
<property name="version2" value="build.version2"/>
<echo>${version}</echo>
<echo>${version2}</echo>
</target>
</project>
And the output I get when I run tarne.xml is:
Buildfile: tarne.xml
tarne:
build.read.version:
[echo] v1-0-1
[echo] v1-0-1
[echo] default_version_value
[echo] default_version_value
Where the first 2 lines (v1-0-1) are from inside the read.version target of build.xml and the next 2 lines are from tarne.xml. The general idea is that I should be able to access the version number in my tarne.xml build script.
Any ideas on what's going wrong?
Antcall does not support what you intend to do:
http://ant.apache.org/manual/Tasks/antcall.html :
The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.
you could try:
<target name="tarne" depends="build.read.version">
</target>
which would keep the new values.
Try
<property name="version" value="${build.version}"/>
<property name="version2" value="${build.version2}"/>

Resources