Category Archives: Java

Ant SVN Task (SvnAnt) and Javahl

On a previous post Subversion, Ant and SVN task I talked about how to use the SVN ant task. However for this to work i had to install the svn client. So all of a sudden I have the svn command line, tortoise and subclipse (in eclipse) installed on my system. I rarely use the command line because the tortoise client is efficient and pretty easy to use.
To use svnant without having the svnclient installed in your system is kind of difficult.
Repeating myself.
With the help of the underlying svnClientAdapter, task uses JavaHL (a native JNI interface to the subversion api) if it can find the corresponding library (e.g. svnjavahl.dll on windows). Otherwise it uses svn command line interface.
http://subclipse.tigris.org/svnant/svn.html

So we need to find the native JNI interfaces. I had no idea which these were and even googling did not help. Until it struck me that the subeclipse must have the JNI interfaces because it was working on my colleagues workstation who did not have subversion installed in his system. A quick search through eclipse plugins and we had what we needed. In the eclipse\plugins\org.tigris.subversion.javahl.win32_1.0.2 directory there are the following eight dll files.

  • intl3_svn.dll
  • libapr.dll
  • libapriconv.dll
  • libaprutil.dll
  • libdb43.dll
  • libeay32.dll
  • libsvnjavahl-1.dll
  • ssleay32.dll

These have dependencies about which we had no idea. So we copied all of them and placed them in the ant lib directory.

Now we set the javahl=”true” for the ant task and viola it works. Nice no, easy no way, but if you really want to run svn from ant then this is the way to go I guess. How to install subclipse in eclipse to get the dll files?

Installing Subclipse

Link to Javahl – courtesy Thomas


Ant prompt for username/password for Oracle / Svnant

While ant is usually used to run scripts automatically there are times when one requires that a the user name and password be dynamically be fed. For this the ant core task Input is available. It is really a cool task which will allow for the prompting of required variables at runtime.

To syntax for this task is:
<input message=”Please enter db-username:” addproperty=”db.user” defaultvalue=”Scott-Tiger”/>

Using this will create a prompt when the script is run. But wait for password you don’t want the password to be seen by others do you? Well Input does not provide for that. You can extend Ant’s input capabilities by writing a subclass of org.apache.tools.ant.input.InputHandler where you replace each character with a * or you can use Jera Ant Tasks. The query Task should fulfill ones needs.


Ant SQL Task Oracle procedures

Since we generally deal with Oracle as soon as we got the tables created via an ant script we ran into problems with the procedures. The ant transaction which takes in a file assumes that every line is to be executed separately . This makes it difficult to compile procedures. However the sql task provides for that as well.

<sql driver=”oracle.jdbc.driver.OracleDriver” url=”url” userid=”username” password=”password” delimiter=”/” delimitertype=”row” keepformat=”yes”>


Subversion, Ant and SVN task

Running subversion with Ant can be a bit of a tedious process.

First it requires the three jars (svnant.jar, svnClientAdapter.jar,svnjavahl.jar) which need to be loaded. For ‘ant’ this can be done in two ways. Either you place all the jars in the ant lib directory. The other method is to load the jars when running ant via the command prompt.

ant -lib /home/svn/java/lib

with this one is setup to use svn with ant. Unfortunately that is not enough.

With the help of the underlying svnClientAdapter, <svn> task uses JavaHL (a native JNI interface to the subversion api) if it can find the corresponding library (e.g. svnjavahl.dll on windows). Otherwise it uses svn command line interface.

http://subclipse.tigris.org/svnant/svn.html

So now you are either have to have the native JNI interface or you have to have subversion installed in the system. I had subversion installed in my system.

So now we can move forward to the ant build file.

<typedef resource=”svntask.properties”/>

This is required as it defines the svn task. the svntask.properties can be found in svnant.jar. This defines the task svn to map to org.tigris.subversion.svnant.SvnTask.

It is equivalent as to writing
<taskdef name=”svn” classname=”org.tigris.subversion.svnant.SvnTask” />

To checkout the xml is

<svn javahl=”false” username=”${svnant.repository.user}” password=”${svnant.repository.passwd}”>
<checkout url=”${svn.url}” destPath=”${svn.workdirectory}” />
</svn>

javahl defaults to true. So unless you have the native JNI interface it is better to install subversion and use javahl=”false”.

The various subversion commands which can be used in ant can be found insubclipse:Svn task


Ant Sql Task with SYSDBA

When connecting to oracle the syntax is CONNECT username/password@url

The equvalent sql task for ant is

<sql driver=”oracle.jdbc.driver.OracleDriver” url=”url” userid=”username” password=”password”>

However when one wants to connect as the sysdba one has to use CONNECT username/password@url as sysdba

Using the sys username and password int the ant task throws theexception.

java.sql.SQLExpection: connection to sys should be as sysdba or sysoper

The ant task can stil be used however. To overcome this you need to use:

<sql driver=”oracle.jdbc.driver.OracleDriver” url=”url” userid=”username as sysdba” password=”password”>