Ant: failed to create task or type runtarget - ant

I am running into the following error when trying to run ant:
Problem: failed to create task or type runtarget
I am building on a mac 10.8.3.
Prior research has suggested that I add ant-contrib-0.3.jar to my ANT_HOME installation directory, which I have done (that had actually gotten rid of another 'failed to create task or type' error)
I used ant-contrib-0.3.jar because research suggested that this jar is mapped to the line:
< taskdef resource="net/sf/antcontrib/antcontrib.properties" />
which is in the build.xml file I am using.
The project builds on windows machines ( I even got it to build using https://code.google.com/p/winant/ ) but am trying to get it built on a mac. I am thus not looking to change the build.xml file.
An example of the run target line is:
<target name="setPASProps" depends="" description="setup the properties">
<property name="systemname" value="PAS"/>
<runtarget target="setSystemProps"/>
</target>
Here is some info from running ant -diagnostics
-------------------------------------------
ANT PROPERTIES
-------------------------------------------
ant.version: Apache Ant(TM) version 1.8.2 compiled on June 20 2012
ant.java.version: 1.7
Is this the Apache Harmony VM? no
Is this the Kaffe VM? no
Is this gij/gcj? no
ant.core.lib: /usr/share/ant/lib/ant.jar
ant.home: /usr/share/ant
-------------------------------------------
ANT_HOME/lib jar listing
-------------------------------------------
ant.home: /usr/share/ant
ant-antlr.jar (5756 bytes)
ant-contrib-0.3.jar (17708 bytes)
ant-jmf.jar (6745 bytes)
ant-junit.jar (102350 bytes)
ant-junit4.jar (7126 bytes)
ant-launcher.jar (12321 bytes)
ant-swing.jar (7563 bytes)
ant-testutil.jar (15198 bytes)
ant.jar (1937098 bytes)
Thanks !

It would be helpful if you posted your build.xml too.
You usually get this error if Ant sees a task, but there's a problem with the definition.
Here's my recommendation:
In your project create a directory antlib/ant-contrib.
Download this zip file. Ant-contrib is a wee bit strange is that there is a separate jar for C compiling and for all of the other Ant tasks. The latest version is 1.0b3. When you unzip this zip file, you will see ant-contrib-1.0b3.jar inside this folder.
Put that ant-contrib-1.0b3.jar inside the antlib/ant-contrib folder.
Now, in your build.xml, use the following <taskdef/>:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ant-contrib"/>
</classpath>
</taskdef>
Make sure this is not inside a target. You want this to be executed before any targets are executed.
I like doing the definition this way because the Ant Contrib jar file becomes part of my project, and anyone who needs to run my project will not have to manually install the Ant Contrib jar before they can use my project.
Take a look at your build.xml and see where that <Runtarget> task is being used. I've never used it, and the documentation for this task is so clear and helpful. Actually, I'm not even sure if it works. If you are still having problems, you try to see if you can remove the defined <target/> that contains this task, and see if that gets rid of the issue.

Removed ant-contrib-0.3.jar and added ant-contrib-1.0b3.jar and ant-contrib.jar to my ANT_HOME directory since these are the jars installed with https://code.google.com/p/winant/ (and it was working on windows machines).
This did the trick.

Related

Error preverifying class com.google.common.collect.Ordering in blackberry

I got this error when I included guava-11.0-rc1.jar which contains the package com.google.common.* . But when I try to package it, it gives me the error:
Error preverifying class com.google.common.collect.Ordering MyApp line 0
BlackBerry Packaging Problem
Can anybody tell me what can be done to solve this? Thanks in advance.
Make sure the classes in that library are Java-ME compatible. Remember CLDC is a subset of Java SE and the equivalent desktop compilation level would be 1.2
If they were compatible, then to solve the preverification error you must first preverify your jar. You might be wondering what preverification is. There's a good explanation in this answer.
Preverification is usually done (or should be done) by the Eclipse plugin, but some versions do not. If this is your case, you should do it manually. In your JDE folder, there is a tool called preverify. You could find it in a path that typically looks like this in a Windows machine:
(1) C:\Program files\Research In Motion\BlackBerry JDE <vers>\bin\
You'll also need a library called net_rim_api.jar located in a path like this:
(2) C:\Program files\Research In Motion\BlackBerry JDE <vers>\lib\net_rim_api.jar`
This is all you need to launch the command. Open command line and change dir to the bin folder (1). Then type :
preverify -classpath <classpath for lib> -d <output directory> <file to preverify>
Where:
<classpath for lib> is the path in (2)
<output directory> is the directory where the preverified jar will be saved.
<file to preverify> is the absolute path to the file you want to preverify (guava-11.0-rc1.jar in your case)
If everything went well, now you'll have a new jar in <output directory> which is slightly bigger than the input jar file. This is the one you should include in your project. The preverify tool does not change your original jar.

bndwrap ant task not working

I'm trying to create an OSGi wrapper for the newest version of jTDS. I'm trying to add the wrapping process to the existing jTDS build process (Ant-based). I've downloaded the latest bnd.jar and added the following to the jTDS build.xml:
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="bnd.jar"/>
<bndwrap trace="true" definitions="${basedir}/bnd" output="${build}/${ant.project.name}-${version}.osgi.jar">
<fileset dir="${build}" includes="*.jar"/>
</bndwrap>
I've also got a very simple bnd definition defined:
version=1.2.6
Export-Package: net.sourceforge.jtds*;version=${version}
Bundle-Version: ${version}
Bundle-Name: net.sourceforge.jtds
When I execute the dist task in Ant, it should be creating a JAR with the proper OSGi manifest. It IS creating another JAR, but the manifest is identical to the original.
If I execute the same wrap directly against the bnd JAR:
java -jar bnd.jar wrap -p bnd\jtds-1.2.6.bnd -o build\jtds-1.2.6.osgi.jar build\jtds-1.2.6.jar
I get the correct OSGi manifest.
What is going wrong during the Ant build?
It seems to be a problem with the latest version of bnd, found here. The Ant WrapTask was retooled some and just doesn't seem to work (maybe it's just misconfigured; documentation hasn't kept up with code).
I dropped in version 1.50.0 instead and everything worked as expected both through the bnd.jar and through Ant.

CruiseControl.net ndk-build on Windows 64bit without Cygwin

Latest Android NDK (version 8) allows to call ndk-build without additional cygwin installed.
My question is: can I plug this into CruiseControl.Net for periodical native build?
I assume that most likely I would need to use Ant as a build method and then add it to ccnet server config.
So the questions are:
How to call ndk-build.cmd from an Ant command
How to configure build.xml file?
I tried several approaches, but all of those failed. Could you give me some clues if it is possible at all?
I ran into the same problem (the CreateProcess failures, etc) when trying to invoke "ndk-build.cmd" directly from build.xml, using CC.net on Windows. I figured out how to get this to work, and so I felt compelled to share my solution.
First, create a 1-line Windows command file as follows (I named it "ndkwrapper.cmd"):
sh ndkwrap.sh %1 %2 %3
Next, create a simple bash shell script as follows (named "ndkwrap.sh"):
#!/usr/bin/sh
# Wrapper around ndk-build script for Windows
#
NDK_PROJECT_PATH=/cygdrive/c/workspace/agnc_android
export NDK_PROJECT_PATH
/cygdrive/c/Android/android-ndk-r8b/ndk-build $1 $2 $3
Of course, your exact paths (for your workspace and NDK directories) may be different, but note, in particular, that "/cygdrive/c" refers to "C:".
One very important step here, after you create the script above, is to convert the line endings from Windows to UNIX. You can do this with a utility called "dos2unix.exe" which is freely available. I don't remember where I got it, but it was part of some open source package of GNU/Linux tools ported to Windows. (Google on "UNIX file utilities for Windows".) If you don't convert the line endings, then sh or bash will have trouble reading the script, and you'll get all kinds of erros about "\r" ...
So, to invoke the equivalent of "ndk-build.cmd clean", for example, you'd type "ndkwrapper.cmd clean" to delete your intermediate and output NDK-related build files, in preparation for a full NDK build.
In your build.xml file for CC.net on Windows, you can invoke the NDK makefile as follows:
<tasks>
<exec>
<executable>cmd.exe</executable>
<baseDirectory>C:\Android</baseDirectory>
<buildArgs>/C ndkwrapper.cmd clean</buildArgs>
</exec>
Hope this helps!
Ben
i observed problems with running ndk-build as an CCNET task as well.
It took me a while, but at the end i noticed, that you have to provide HOST_OS and HOST_ARCH as ndk-build parameters to let it run.
<exec>
<executable>cmd</executable>
<buildArgs>/C ndk-build HOST_OS=windows HOST_ARCH=x86 -B NDK_PROJECT_PATH=[PROJECT] APP_BUILD_SCRIPT=[ANDROIDMKFILE] NDK_APPLICATION_MK=[APPLICATIONMKFILE] NDK_LOG=1</buildArgs>
<buildTimeoutSeconds>120</buildTimeoutSeconds>
</exec>
hope it helps anyone to save time.
Ok I got some progress, I am able to build the jni code via ant or nant but in both cases plugging it to the cc.net server config gives me strane error:
but now CC.net gives me strange errors:
<builderror>
<type>NAnt.Core.BuildException</type>
<message><![CDATA[External Program Failed: G:\\android-ndk-r8b\\ndk-build.cmd (return code was 2)]]></message>
<location>
<filename>G:/MYPath/project.build</filename>
<linenumber>7</linenumber>
<columnnumber>4</columnnumber>
</location>
<stacktrace><![CDATA[ at NAnt.Core.Tasks.ExternalProgramBase.ExecuteTask()
at NAnt.Core.Tasks.ExecTask.ExecuteTask()
at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute()
at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
at NAnt.Core.Project.Execute()
at NAnt.Core.Project.Run()]]></stacktrace>
</builderror>
</failure>
<duration>296.40000000000003</duration>
</buildresults>Buildfile: file:///G:/MYPath/project.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: build
clean:
[echo] Starting Android ndk CLEAN ...
[exec] Android NDK: Unable to determine HOST_OS from uname -s:
[exec] Android NDK: Please define HOST_OS in your environment.
[exec] process_begin: CreateProcess(NULL, uname -s, ...) failed.
[exec] G:/android-ndk-r8b/build/core/init.mk:131: *** Android NDK: Aborting. . Stop.
BUILD FAILED - 0 non-fatal error(s), 2 warning(s)
My project in cc.net config:
<project>
<name>MY_PROJECT_NAME</name>
<workingDirectory>PATH_TO_MY_PROJECT</workingDirectory>
<tasks>
<nant>
<executable>G:\nant-0.92\bin\Nant.exe</executable>
<baseDirectory>PATH_TO_MY_PROJECT</baseDirectory>
<buildFile>MYPROJECTNAME.build</buildFile>
<buildArgs>build</buildArgs>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
</nant>
</tasks>
</project>
And my NAnt build file:
<project name="my name" default="build" basedir=".">
<description>My project Build Files.</description>
<target name="clean" description="remove all generated files">
<echo message="Starting Android ndk CLEAN ..."/>
<exec program="G:\\android-ndk-r8b\\ndk-build.cmd" failonerror="true"
basedir="MY PROJECT PATH">
<arg value="clean" />
</exec>
<echo message="Android ndk CLEAN done."/>
</target>
<target name="build" description="remove all generated files" depends="clean">
<echo message="Starting Android ndk BUILD ..."/>
<exec program="G:/android-ndk-r8b/ndk-build.cmd" failonerror="true" />
<echo message="Android ndk BUILD done."/>
</target>
</project>
As I said I can run a Nant.exe for my project and it cleans and build correctly.
It looks like the cc.net tries to run the other ndk-build commend which is used for linux and is missing some commands as uname.
Do you have any idea what cI could be doing wrong ?
The original question is asking about ant builds. This answer is related to a problem in CC.NET and ant and gradle builds are going to be affected in the same way.
We are using gradle and with some custom gradle tasks it is possible to compile the native code of your project as well by calling ndk-build.cmd (from a path that has no spaces in it).
After the gradle file is prepared properly shell initiated gradle builds will work but cc.net initiated builds will fail.
Our CC.NET task is defined as follows:
<exec executable=".\gradlew.bat">
<baseDirectory>$(projSrcDir)</baseDirectory>
<buildArgs>clean assemblePlayRelease assembleProRelease</buildArgs>
<buildTimeoutSeconds>900</buildTimeoutSeconds>
</exec>
The problem is related to a CC.NET bug that causes the shell variable names to be in lower case. Windows shell scripts do not care about the case of shell variable names but because the NDK fires up make variable case becomes an issue. The init.mk make file that is part of the build process relies on shell variable names to identify the host OS type. In particular the shell variable OS. Normally the OS value is defined like this:
OS=Windows_NT
But when the variable is passed to gradle from CC.NET it gets transformed into this:
os=Windows_NT
This causes the detection mechanism in init.mk to fail and tries to execute the unix detection sequence and looks for the Unix uname utility that is not present on Windows resulting in:
Android NDK: Unable to determine HOST_OS from uname -s:
Android NDK: Please define HOST_OS in your environment.
make.exe: Entering directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'
make.exe: Leaving directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'
And ultimately:
process_begin: CreateProcess(NULL, uname -s, ...) failed.
c:/ndk/build/core/init.mk:160: *** Android NDK: Aborting. . Stop.
FAILURE: Build failed with an exception.
The workaround is less then ideal but it gets the job done. The idea is to edit the ndk-build.cmd and change the case of the passed variables only when we are building from CC.NET.
Simply insert this code after the #echo off line in ndk-build.cmd:
IF DEFINED ccnetproject (
ECHO Applying Environment variable hack for CC.NET.
SET OS2=%os%
SET OS=
REM SET PATH=%path%
SET TEMP2=%temp%
SET TEMP=
)
IF DEFINED ccnetproject (
SET OS=%OS2%
SET OS2=
SET TEMP=%TEMP2%
SET TEMP2=
)
This script first makes temporary copies of values in the lower case OS and TEMP variables. Next it undefines them by clearing their values. An finally the reverse is done.
Two steps are needed because just saying
SET OS=%os%
doesn't do much since scripts are case insensitive. It first locates the OS variable, finds a lower case version and assigns its own value back to itself.
This was tested on CC.NET v1.6.7981.1, gradle v1.1.0 and Android NDK v10 (64bit).

Could not create task or type: getProjectData from Ant

I am trying to run an Ant task from within IBM RSA IDE using Ant build ...
I get the following error message:
BUILD FAILED
build.xml:21: Could
not create task or type of type: getProjectData.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
- You have misspelt 'getProjectData'.
Fix: check your spelling.
- The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
- The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
- The task is not an Ant core or optional task
and needs to be declared using <taskdef>.
- You are attempting to use a task defined using
<presetdef> or <macrodef> but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.
Here's the Ant buildfile:
<!-- Get property locationName. -->
<target name="config">
<echo message="${ear.project.name}" />
<getProjectData projectName="${ear.project.name}" />
</target>
I am not quite sure what the problem is here because the error message seems not helpful. Any suggestions?
I believe getProjectData is an IBM extension to ant. Like you, I had a similar error, but I was able to get it working after ensuring the Run in the same JRE as the workspace option was enabled (which you can find by right-clicking the build file, run-as, Ant Build..., and selecting the option on the JRE tab).
I discovered the solution on the IBM info center:
The Run in the same JRE as the workspace option enables the classpath
of the workbench to access the additional Ant tasks that perform
operations that are specific to the workbench, such as projectImport,
projectBuild, workspaceBuild, ejbDeploy, or earExport. If your Ant
build script uses any Ant tasks that perform workbench operations,
verify that you selected the Run in the same JRE as the workspace
option; otherwise you might get the following error message in the
Console view:
Problem: failed to create task or type <Ant task> Cause:
The name is undefined.
The build file I used looked like this:
<?xml version="1.0"?>
<project name="Test" default="config" basedir=".">
<target name="config">
<getProjectData Basedir="${basedir}" />
<echo message="getProjectData: projectName=${projectName}
nature=${natureName}
workspace=${workspaceName}
basedir=${basedir}" />
</target>
</project>
And output:
Buildfile: C:\DATA\java\workspace\test-java\build.xml
config:
[getProjectData] Setting projectName=test-java
[getProjectData] Retrieved following Project Data :
[getProjectData] workspaceName=C:\DATA\java\workspace
[getProjectData] natureName=Java
[echo] getProjectData: projectName=test-java
nature=Java
workspace=C:\DATA\java\workspace
basedir=C:\DATA\java\workspace\test-java
BUILD SUCCESSFUL
Total time: 78 milliseconds

Error using Ant to create EJB after upgrading WAS from 6.0 to 7.0

Ant task breaks at the <wsejbdeploy> tag. The exception message is :
[wsejbdeploy] Error executing deployment: java.lang.ClassNotFoundException.
Error is com.ibm.etools.ejbdeploy.batch.plugin.BatchExtension.
[wsejbdeploy] java.lang.ClassNotFoundException:
com.ibm.etools.ejbdeploy.batch.plugin.BatchExtension
[wsejbdeploy] at java.lang.Class.forName(Class.java:136)
In addition to that, ivy.xml reports problems, but when I inspect it, the messages have no sense (screenshot). I suspect the problems could be:
a) Additional files that I have for the build which conflict with the upgraded Ant (in RSA 7.0 i've had Ant 1.6.5 and RSA 8.0 comes with Ant 1.7.1). Additional files are:
required for ant tasks execution
ant-contrib/ant-contrib.jar
antelope-tasks/AntelopeTasks_3.2.10.jar
antform/antform.jar
antform/defaultStyle.txt
antlr/antlr.jar
checkstyle/checkstyle-4.2.jar
checkstyle/checkstyle-optional-4.2.jar
checkstyle/checkstyle-frames-errors.xsl
clover/clover.jar
clover/cenquatasks.jar
clover/clover.license
doccheck/doccheck-modified.jar
ivy/ivy-20060723172807.jar
jakarta-commons/commons-beanutils.jar
resources/checkstyle/checks-source.xml
resources/checkstyle/checksTransformation.xsl
b) Changes in the Ant regarding EJB build which require some settings to be reconfigured.
c) Something else :)
Except the Error, everything else is a stab in the dark so feel free to ask for any additional info.
The problem was in the additional file needed for wsejbdeploy. In the 6.0 version, you copy wsanttasks.jar and wsprofile.jar from the websphere 6.0 installation folder and then reference it like this
<taskdef name="wsejbdeploy" classname="com.ibm.websphere.ant.tasks.WsEjbDeploy"
classpathref="all-libs"/>
where "all-libs" is a reference to the folder where you copied the jars. In websphere 7.0 there is no wsanttasks.jar and you must reference the runtime file, eg
<taskdef name="wsejbdeploy" classname="com.ibm.websphere.ant.tasks.WsEjbDeploy">
<classpath>
<pathelement path="C:/IBM/SDP80/runtimes/base_v7/plugins/com.ibm.ws.runtime.jar" />
</classpath>

Resources