Build.xml issue - ant

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.

Related

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>

Customised ANT task

I have a ANT build.xml file which goes like this-
<?xml version="1.0"?>
<project name="apache-jena-2.10.0" basedir="." default="notifyme">
<target name="notifyme">
<java classname-"arq.sparql" fork="true">
<arg value="--data=C:\apache-jena-2.10.0\test.ttl"/>
<arg value="--query=C:\apache-jena-2.10.0\ASKTest.rq"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
</target>
</project>
This build.xml basically run a query and return a specefic result.
The result comes like this-
notifyme:
[java] Ask =>No
BUILD SUCCESSFUL
Total time : 1second
Now my question is there any way I can make the build fail if Ask => No, if yes can any one please help me to customise the ANT build file.
Kind regards
Som
Use the resultproperty attribute for java task. It will store standard out in the given property. Then us the fail task, with conditions task:
<?xml version="1.0"?>
<project name="apache-jena-2.10.0" basedir="." default="notifyme">
<target name="notifyme">
<java classname-"arq.sparql" fork="true" failonerror="false" outputproperty="javaresult">
<arg value="--data=C:\apache-jena-2.10.0\test.ttl"/>
<arg value="--query=C:\apache-jena-2.10.0\ASKTest.rq"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
<fail>
<condition>
<matches string="${javaresult} pattern="No"/>
</condition>
</fail>
</target>
</project>
Did not test it. But you can get the idea.

XJC with Krasa Plugin

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"

Build.xml for jsf 2.0 with weblogic 12c

I am new to jsf and jsp.
I know weblogic 12 c comes with jsf 2.0 but when ever i try to deloy my application, i got an stack error., i guess this is due to my build.xml which can not get my jars and wars from weblogic server,
Below is the code of build.xml,please help me asap, will be very thankful.
<property name="weblogic.home" value="/bea/wlserver_12.1/"/>
<path id="WebLogic System Libraries.libraryclasspath">
<pathelement location="../../../../bea/wlserver_12.1/server/lib/api.jar"/>
<pathelement location="../../../../bea/wlserver_12.1/server/lib/wls-api.jar"/>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jsf-2.0.war"/>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jstl-1.2.war"/>
</path>
<path id="Security_Search.classpath">
<pathelement location="build/classes"/>
<path refid="WebLogic System Libraries.libraryclasspath"/>
</path>
<target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist" />
</target>
<path id="compile.classpath">
<fileset dir="${weblogic.home}/common/deployable-libraries">
<include name="*.war"/>
</fileset>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jsf-2.0.war"/>
</path>
<target name="compile" depends="init" >
<javac destdir="build/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="dist/security_Search_JSF.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent">
<exclude name="*.jar"/>
</fileset>
<classes dir="build/classes"/>
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build/classes"/>
</target>
<target name="build"/>
</project>
TTP:101064][WebAppModule(security_Search_JSF:security_Search_JSF.war)] Error parsing descriptor in Web appplication "C:\bea_deploy\security_Search_JSF.war" weblogic.application.ModuleException: VALIDATION PROBLEMS WERE FOUND problem: cvc-complex-type.2.3: Element 'weblogic-web-app#http://xmlns.oracle.com/weblogic/weblogic-web-app' with element-only content type cannot have text content.: at weblogic.servlet.internal.WebAppModule.loadDescriptor(WebAppModule.java:1494) at weblogic.servlet.internal.WebAppModule.init(WebAppModule.java:253) at weblogic.servlet.internal.WebAppModule.init(WebAppModule.java:636) at weblogic.application.internal.flow.ScopedModuleDriver.init(ScopedModuleDriver.java:162) at weblogic.application.internal.ExtensibleModuleWrapper.init(ExtensibleModuleWrapper.java:74) at weblogic.application.internal.flow.ModuleListenerInvoker.init(ModuleListenerInvoker.java:84) at weblogic.application.internal.flow.InitModulesFlow.initModule(InitModulesFlow.java:312) at weblogic.application.internal.flow.InitModulesFlow.initModules(InitModulesFlow.java:325) at weblogic.application.internal.flow.InitModulesFlow.prepare(InitModulesFlow.java:378) at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:706) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:237) at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:48) at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158) at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:96) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:229) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747) at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216) at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:13) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:46) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545) a
now i am getting this error.. please help,,,,
Its error in weblogic.. please
About the original error, it states that your weblogic.xml file has an invalid format.
Here's a sample of a valid weblogic.xml that references the JSF 2.0 shared library you want to use:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>store</wls:context-root>
<wls:library-ref>
<wls:library-name>jsf</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:exact-match>true</wls:exact-match>
</wls:library-ref>
If you already solved this error, please provide details on the next one - is it happening during deployment? Can you print the whole stacktrace?
Cheers,
Fabio

How to macro-ify ant targets?

I want to be able to have different targets doing nearly the same thing, as so:
ant build <- this would be a normal (default) build
ant safari <- building the safari target.
The targets look like this:
<target name="build" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.target}"/>
</java>
</target>
<target name="safari" depends="javac" description="GWT compile to Safari/JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.safari.target}"/>
</java>
</target>
(Nevermind the first thought that strikes: throw out ant! That's not an option just yet.) I tried using macrodef, but got a strange error message (even though the message didn't imply it, it think it had to do with putting a target in sequential). I don't want write a cmdline as so: ant -Dwhatever=nevermind. Any ideas?
My first try (without being able to test it at the moment):
<target name="build" depends="javac, create.mymacro" description="GWT compile to JavaScript">
<mymacro target="${lhs.target}"/>
</target>
<target name="safari" depends="javac, create.mymacro" description="GWT compile to Safari/JavaScript">
<mymacro target="${lhs.safari.target}"/>
</target
<target name="create.mymacro">
<macrodef name="mymacro">
<attribute name="target" default="${lhs.target}"/>
<sequential>
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="#{target}"/>
</java>
</sequential>
</macrodef>
</target>

Resources