ant-contrib installation failure on linux - ant

I would like to use 'ant-contrib', but I could not use it. I tried to use 3 way, without success.
Apache Ant(TM) version 1.8.2
echo $ANT_HOME
/usr/share/ant
./usr/share/ant/lib/ant-contrib-1.0b2.jar
./usr/share/java/ant/ant-contrib-1.0b2.jar
./usr/share/java/ant.jar
*1.*
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
RESULT:
Buildfile: /home/username/build.xml
[taskdef] Could not load definitions from resource net/sf/antcontrib
/antcontrib.properties. It could not be found.
*2.*
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
RESULT:
Buildfile: /home/username/build.xml
[taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
*3.* build.xml in my home, and ant-contrib in home/lib
<classpath id="contrib.classpath.ref">
<fileset dir="${basedir}/lib"/>
</classpath>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="contrib.classpath.ref"/>
RESULT:
Buildfile: /home/username/build.xml:2: Problem: failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
I dont know other solution where I can iterate through a fileset/custom list doing something on them one by one. Thats why its important me.
Honestly, why there is no clear documentation ?

The problem was that YAN mentioned above. I have more ant in my system.
All in all, I removed them, a tried again my build xml with a brand new downloaded ant.
What is not on the PATH, and started from directory where it is.
I know this is not the best settings, but I could try it what I want, and solving the right setting is just question of time.
Thanks guys above your time and effort.

Related

MobileFirst Platform native iOS app building have error while building .wlapp

I am working on MobileFirst Platform version7 using ant script to build the project .war, .wlapp, .adapter.
Everything was working fine while our project was a hybrid one. Now the project is migrated to native-iOS in.
I am using following code to build .wlapp.
<target name="build-wlapp">
<app-builder worklightServerHost="localhost:10080"
applicationFolder="//Users/admin/Documents/workspace/NewProj/apps/Try"
environments="iOSnative"
nativeProjectPrefix="NewProj"
outputFolder="/Users/admin/Documents/workspace/NewProj/bin"/>
it is throwing below error:
build.xml:66: Failed building application: The build could not be
completed due to invalid application-descriptor.xml.(cvc-elt.1: Cannot
find the declaration of element 'nativeIOSApp'.)
I am not getting where the flaw is...
Assuming the application-descriptor.xml you posted in your comment is complete, it looks like you have a stray semicolon after your xmlns declaration. That's not valid XML. Not sure how it got like that (check your source control system?), but you probably need to remove/revert it.
Sorry For the Wrong answer first.
You were using the wrong code to generate the .wlapp file the ant script is below.
<project default="change">
<target name="change">
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="worklight-ant-builder.jar"/>
</classpath>
</taskdef>
<native-app-builder
sourceFolder="C:\Workspace\Test\apps\Test" DestinationFolder="bin"
worklightServerHost="http://111.111.111.111:10080">
</native-app-builder>
</target>
</project>

ant copy task hanging when the source file is missing

In one of our build script, we have following simple copy task added ->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
This copy task started hanging when the glassfish jar name got changed (version upgrade which are not in our control) at the source location. I was expecting it to error out causing the build failure in that case. Actually at first I was not able to figure out at what particular step build was hanging. Then when I added "-debug" to the ant command and I realized its successfully completing a step prior to this copy task and still there was no trace of copy command that is hung. When I updated the new jar name, it worked fine and build was successful which proved that the copy task is hanging because of filename got changed. To make it easy to debug next time, I added an echo statement like below just prior to that copy task ->
<echo message="Copying glassfish jar to ${targetdir}.."/>
But I am still confused as to why it didn't give error with build failure? I am using Apache Ant version 1.7.1. Could this be a bug? How else I can avoid this situation in future with just the copy task (without using * in the jar name)? TIA
That worked for me. Well, didn't work for me. I got the error message. I am using Ant 1.8 and Ant 1.9.2. I didn't try it with Ant 1.7, but I doubt it's a bug.
Try to use the -v parameter in Ant:
$ ant -v target
And be prepared for a longwinded output. This will give you information what's going on with Ant, and may explain why it's freezing. There's a few things you could do: Use a fileset to specify the file.
<copy todir="${targetdir}">
<fileset dir="${sourcedir}/modules">
<include name="glassfish*.jar"/> <!-- Will catch any glassfish.jar -->
</fileset>
</copy>
Of course, if the file doesn't exist, you won't get an error or even a warning. However, a <fail/> before will detect the issue:
<fail message="missing file ${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar">
<condition>
<not>
<available
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
type="file"/>
</not>
</condition>
</fail>
To force the build to quit, an alternative way
<available file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
property="glassfish.jaxb.xjc.jar.present"/>
<fail message="you message" unless="glassfish.jaxb.xjc.jar.present"/>
just a few lines less :)
If you want to dig into it, try this:
write a simple build file, which contains only one target with copy, and put it to the same place of your main build file.
<target name="test-copy">
<!-- here use an old (wrong) file name -->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
</target>
run it, check if it fails or hangs.
If this simple build file works, it's very possible that something else in your main build file is causing the bug.

Ant script split file name and extension into 2 separate properties

I have a fileset that has say 10 files with extensions. I need to then take this and get the filename and extension into 2 separate properties/variables but not sure how. The reason I need to do this as a file starts out on Unix as XB12345.FILE which I need to move to an I/5 system with the file name as XB12345.FILE and the member as FILE.MBR. Most of the files do not have a consistent extension and will only be known at run time. Any help would be appreciated.
This sounds like a job for the Ant-Contrib tasks.
The Ant-Contrib tasks have been around for a long time and are quite common to see in Ant projects. The PropertyRegex task will do what you want. In fact, there's even a For task that can handle loops.
The <PropertyRegEx> task would look something like this:
<propertyregex property="base.name"
input="file.name"
regexp="(.*)\.(.*)"
select="\1"/>
<propertyregex property="suffix.name"
input="file.name"
regexp="(.*)\.(.*)"
select="\2"/>
Installing the Ant-Contrib tasks is fairly easy if you follow these steps:
Download the ant-contrib-1.0b3.jar.
Create a directory in the root of your project called antlib/ac.
Put the ant-contrib-1.0b3.jar file in theantlib/ac` directory.
Add the task definition.
Like this:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ac"/>
<classpath>
</taskdef>
If you use a version control system, check in the ant-contrib-1.0b3.jar file into your version control system for the project. Now, when someone needs to do a build, they checkout your project, and the Ant Contrib tasks are already defined and the Ant-Contrib jar is there. There's no need for the developer to install Ant-Contrib. Your build just works.
Though propertyregex is the solution for the intended problem, but you must use override property for you solution.
<propertyregex property="base.name"
input="file.name"
regexp="(.*)\.(.*)"
select="\1" override="true"/>
<propertyregex property="suffix.name"
input="file.name"
regexp="(.*)\.(.*)"
select="\2" override="true"/>

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

Ant fails with liquibase path

I am trying to get phing to work nice with liquibase. But pPing gives this illustrous error (which I honestly can't find online)
Execution of target "update-database" failed for the following reason: PathElement (unknown) doesn't support the 'location' attribute.
BUILD FAILED
PathElement (unknown) doesn't support the 'location' attribute.
Total time: 0.1206 seconds
the specific commands for that are:
<path id="liquibasepath">
<pathelement location="${basedir}/install/lib/liquibase.jar" />
<pathelement location="${basedir}/install/lib/jdbc-mysql.jar" />
</path>
I tried searching online but there is no good documentation for using phing with liquibase. and the error's neither turn up decent results.
Try using the "path" attribute in pathelement instead of location
The correct answer should be: This is ant, not phing. I was trying to run it with the wrong program. (there really should be some indication of this in build files ;)).
The person who commented got me on hte right track, can't accept that as an answer tho.

Resources