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.

Thursday 3 May 2012

DriverManager.setLoginTimeout() and DriverManager.getLoginTimeout()


When attempting to connect to a data source which is unreliable, to stop the application from hanging (i.e. waiting for a response from the DriverManager,getConnection(...) method), you can use the login timeout integer. This represents a maximum time in seconds that the data source will wait when attempting to connect to the database.

Description from Oracle Java Docs:

DriverManager.setLoginTimeout ( )  - Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

DriverManager.getLoginTimeout( )  - Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.