Showing posts with label Ant. Show all posts
Showing posts with label Ant. Show all posts

Monday, 14 May 2012

Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve

I've just installed NetBeans 7.1.2. When attempting to run an Ivy project I get the following error:

/home/rsharp/projects/project_name/ant-ivy.xml:5: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
        -ANT_HOME/lib
        -the IDE Ant configuration dialogs
BUILD FAILED (total time: 0 seconds)

This was because the default location for Ant in NetBeans is:

/usr/local/netbeans-7.1.2/java/ant

Whereas Ant is actually installed at:

/usr/local/ant

To set this, go to Tools > Options > Miscellaneous > Ant and modify Ant Home.

Wednesday, 14 March 2012

Ant target shortcuts in NetBeans

To solve some time, Ant targets can be given short cuts in the NetBeans IDE. To do this:

1. Open the build.xml  (e.g. through the Files tab). Within the Navigator tab you will see the file contents (i.e., the targets).
2. RIght click on a target and select Create Shortcut. A wizard will open that lets you configure the shortcut (e.g., toolbar button or a keyboard shortcut).

Tuesday, 23 August 2011

Writing to a properties file with Ant

I find this useful when I want to change how the application works depending on where and why it is being deployed. This blog post assumes you have Ant installed!

In the build.xml file;

<!-- Add the property file -->
<property file="project.properties"/>

<!--  Write a property to the file with a value based on the target -->
<target name="liveExample">
     <echo message="This target example has the live properties"/>
     <propertyfile
          file="project.properties"
          comment="Setting important system procedure variable to 100">
          <entry key="importantVariable" value="100"/>
          </propertyfile>
</target>

<target name="testExample">
     <echo message="This target example has the test properties"/>
     <propertyfile
          file="project.properties"
          comment="Setting important system procedure variable to 10 for testing purposes">
          <entry key="importantVariable" value="10"/>
          </propertyfile>
</target>

How it works

The properties file (project.properties) has a key/value pair written to it. Based on what target is run, the key has a different value. This allows us to control how the application works based on how we deploy it. For further reading on Ant's PropertyFile task see their manual.