I have an ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTest" basedir="." default="clean">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<target name="clean" description="delete all generated files">
<delete dir="${classes.dir}" failonerror="false"/>
<echo message="Hello" />
<delete dir="${ant.project.name}.jar"/>
</target>
<target name="compile" description="compile the task">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" description="create jars of task" depends="compile">
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}" />
</target>
<target name="use" description="use the created jars" depends="jar">
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar" />
<ntTest/>
</target>
</project>
And output is
Buildfile: D:\Work\D3000\AntTest\Build.xml
clean:
[delete] Deleting directory D:\Work\D3000\AntTest\classes
[echo] Hello
compile:
[mkdir] Created dir: D:\Work\D3000\AntTest\classes
[javac] Compiling 1 source file to D:\Work\D3000\AntTest\classes
compile:
jar:
[jar] Building jar: D:\Work\D3000\AntTest\AntTest.jar
compile:
jar:
use:
BUILD FAILED
D:\Work\D3000\AntTest\Build.xml:24: taskdef class AntTest cannot be found
using the classloader AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
Total time: 758 milliseconds
Can anybody tell me why this error is coming:
BUILD FAILED D:\Work\D3000\AntTest\Build.xml:24: taskdef class AntTest
cannot be found using the classloader
AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
My class file contains class named AntTest
Seems like the classname is wrong, you need the full qualified classname.
instead of :
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar"/>
try :
<taskdef name="ntTest" classname="com.yourdomain.AntTest" classpath="${ant.project.name}.jar"/>
Related
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"
I am a selenium user trying to generate xslt reports using Ant, but when I run Ant in cmd it is showing me error of build.xml not exist while I have build.xml file in my project folder.
I am using eclispe juno on windows 7 and and kept the build.xml file under the project.
I have java JDK1.7 on my machine and I have already set the environment variables(Java and ant both) as per instructions given on apache.org
Ant version is apache-ant-1.9.1
I have imported all necessary jar files (selenium + maven +saxon + all required for xslt report through ant) in my project in eclipse.
When I am trying to run ant through cmd it is showing me this error:-
BUILD FAILED
D:\Projects\Project\Selenium\Workspace\build.xml:70: Compile failed; see the compiler error output for details.
Below is my build.xml file:-
<project name="Plumslice" default="usage" basedir=".">
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="D:\All jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<!--target name="start-selenium-server">
<java jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.7"
classpath="${test.classpath}">
</javac>
<copy todir="${test.dest}">
<fileset dir="${test.src}" excludes="**/*.java"/>
</copy>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng classpath = "${test.classpath}:${test.dest}" suitename = "suite1" >
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
<!--
<testng classpath="${test.classpath}:${test.dest}" groups="fast">
<classfileset dir="${test.dest}" includes="example1/*.class"/>
</testng>
-->
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target name="email" >
<java classname="com.qtpselenium.util.SendMail" classpath="${test.dest}" classpathref="test.c" />
</target>
<target name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="src/com/testing/xslt/testng-results.xsl"
out="${ws.home}/XSLT_Reports/output/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt>
</target>
</project>
Thanks you all for your great help, I have resolved that error ..
It was related to the path of the jar files , I provided incorrect path to the jars.
This was line 70 : -
<javac debug="true" destdir="${test.dest}" srcdir="${test.src}"
target="1.7" classpath="${test.classpath}">
this is related to the path to the jars and in the top line of my file I did provided this path - D:\All jars , while all required jars was not in this folder, now I updated the jar folder and it is working fine now.
<?xml version="1.0" ?>
<project name="javaGui" default="execute">
<target name="init" depends="clean">
<mkdir dir="build/classes" />
<mkdir dir="dist" />
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="build/classes" />
</target>
<target name="execute" depends="compile">
<java classname="Swing" classpath="build/classes" />
<jar destfile="dist/final.jar" basedir="build/classes" />
</target>
<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>
This is ant script to generate jar file.problem is those code will generate jar but when i click on that jar it is not opening means it not showing any GUI.
im new to this please let me know what is going wrong.
javaGUI is project and Swing is class name
jar file will not open in GUI. You need to run jar file from console.
Go to dist directory -> run this command:
$ java -jar final.jar [optional parameters]
For more details : see this reference
UPDATE
Instead of giving ant from target execute, try this :
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="Swing"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>
Here is an example of my ant xml file:
<!--A reference to the classpath that contains the database driver, liquibase.jar, and the changelog.xml file-->
<path id="liquibase.classpath.id">
<pathelement location="${PROJECT_DIR}/lib/liquibase-2.0.2.jar"/>
<pathelement location="${jdbc.classpath}"/>
<fileset dir="${PROJECT_DIR}/db/changelog" includes="db.changelog*.xml"/>
</path>
<pathconvert refid="liquibase.classpath.id" property="liquibase.classpath.id.text" />
<echo message="${liquibase.classpath.id.text}" />
<updateDatabase loglevel="debug"
changeLogFile="${db.changelog.file}"
driver="${jdbc.driver}"
url="${jdbc.url}"
username="${database.username}"
password="${database.password}"
dropFirst="false"
classpathref="liquibase.classpath.id"
/>
I'm getting the following output from <echo message="${liquibase.classpath.id.text}" /> as expected:
G:\My Documents\PROJECTS\DataSource\lib\liquibase-2.0.2.jar;
G:\My Documents\PROJECTS\DataSource\lib\hsqldb-2.2.5.jar;;
G:\My Documents\PROJECTS\DataSource\db\changelog\db.changelog-1.0.xml;
G:\My Documents\PROJECTS\DataSource\db\changelog\db.changelog-master.xml
But updateDatabase throws the following exception:
java.lang.ClassNotFoundException: org.hsqldb.jdbc.JDBCDriver
What am I doing wrong? Please tell me.
I can't see where you're defining the value for jdbc.driver, but the class name should be org.hsqldb.jdbc.JDBCDriver, not org.hsqldb.jdbcDriver
Is that the name of hsqldb's driver? Docs I've seen show org.hsqldb.jdbc.JDBCDriver.
As already pointed out, the JDBC driver should be org.hsqldb.jdbc.JDBCDriver. I think your second problem is that ANT cannot find your hsqldb jar file. You absolutely sure the path is correct?
Here's my working example (I delegate classpath management to the ivy plug-in).
liquibase.properties
url=jdbc:hsqldb:file:build/testdb
driver=org.hsqldb.jdbc.JDBCDriver
username=sa
password=""
build.xml
<project basedir="." default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
====================
Properties and paths
====================
-->
<property file="liquibase.properties" prefix="db"/>
<property name="build.dir" location="build"/>
<property name="db.changelog.file" location="src/scottTiger.xml"/>
<!--
=======
Targets
=======
-->
<target name="init" description="Download 3rd party dependencies">
<ivy:resolve/>
<ivy:cachepath pathid="ant.path" conf="ant"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="build" depends="init" description="Create the database">
<taskdef resource="liquibasetasks.properties" classpathref="ant.path"/>
<fail unless="db.changelog.file">db.changelog.file not set</fail>
<fail unless="db.url">db.url not set</fail>
<fail unless="db.driver">db.driver not set</fail>
<fail unless="db.username">db.username not set</fail>
<fail unless="db.password">db.password not set</fail>
<updateDatabase
changeLogFile="${db.changelog.file}"
driver="${db.driver}"
url="${db.url}"
username="${db.username}"
password="${db.password}"
promptOnNonLocalDatabase="false"
dropFirst="false"
classpathref="ant.path"
/>
</target>
<target name="clean" description="Cleanup all built files">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean">
<ivy:cleancache/>
</target>
</project>
ivy.xml
Build is configured to download the latest release versions, available from Maven Central
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="scott-tiger"/>
<configurations defaultconfmapping="ant->default">
<conf name="ant" description="Ant build dependencies"/>
</configurations>
<dependencies>
<dependency org="org.liquibase" name="liquibase-core" rev="latest.release"/>
<dependency org="org.hsqldb" name="hsqldb" rev="latest.release"/>
</dependencies>
</ivy-module>
I've got an ant file which looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project name="p" default="compile" basedir=".">
<path id="compile.cliClasspath">
<fileset dir="./WebContent/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp />
</target>
<target name="compile" description="compile the source" >
<javac srcdir="./src/" destdir="C:\TEMP\build">
<classpath refid="compile.cliClasspath" />
</javac>
</target>
<target name="createWar" depends="compile" description="create web archive">
<war destfile="C:\TEMP\client.war"
webxml="./WebContent/WEB-INF/web.xml"
needxmlfile="true"
basedir="./WebContent"
excludesfile="./WebContent/WEB-INF/application.xml">
<lib dir="./WebContent/WEB-INF/lib" />
<classes dir="C:\TEMP\build" />
</war>
</target>
<target name="createEar" depends="compile, createWar" description="create enterprise archive">
<ear destfile="C:\TEMP\Client.ear"
appxml="./WebContent/WEB-INF/application.xml"
includes="C:\TEMP\Client.war" />
</target>
<target name="cleanUp" depends="compile, createWar, createEar" description="clean up">
<delete includeemptydirs="true">
<fileset dir="C:\TEMP\build" includes="**/*" />
</delete>
</target>
</project>
The idea being to create an ear with the content of my web app. When I run this (run as with order as in the file, from galileo) I get this:
Buildfile: C:\Client-was7.xml
<snip>init:
compile:
[javac] Compiling 47 source files to C:\TEMP\build
compile:
[javac] Compiling 47 source files to C:\TEMP\build
createWar:
[war] Building war: C:\TEMP\Client.war
compile:
[javac] Compiling 47 source files to C:\TEMP\build
createWar:
[war] Building war: C:\TEMP\Client.war
createEar:
compile:
[javac] Compiling 47 source files to C:\TEMP\build
createWar:
[war] Building war: C:\TEMP\Client.war
createEar:
cleanUp:
BUILD SUCCESSFUL
Total time: 15 seconds
Why isn't the output:
init:
compile:
createWar:
createEar:
cleanUp:
BUILD SUCCESSFUL
Total time: 15 seconds
?
Thanks
I think it may have to do with the depends targets. when you run create ear, you first run compile, and then create war, which also depends on compile and so on.