Monday, 3 September 2007
xmlbeans for the impatient
There is an introduction at Apache which is either buggy or out of date. Luckily, a colleague who knows the library well was on hand to point me in the right direction. I have packaged up a modified and extended version of the Apache introduction and put the jar here for anyone who want to get started with no reading whatsoever. The jar includes an ant build file. The default ant target will compile everything and run the 'print' example. There are also targets 'add-item' and 'save-order' run two more examples.
After extracting the jar, you will need to cd into the xmlbeans directory, make the 'lib' directory and copy these files into it:
asm.jar
jsr_api.jar
resolver.jar
saxon8.jar
xbean.jar
xbean_xpath.jar
xmlbeans-qname-2.3.0.jar
xmlpublic.jar
You will need to read the xmlbeans install guide to find these files.
Monday, 13 August 2007
Managing ant dependencies
My colleague Jon Siddle decided to write his own ant dependency manager which he has called decorum. It does just enough dependency management -- it doesn't download stuff from ibiblio, but it does know about other ant projects in the same file system and will build them if their targets are out of date. I works very well in a project with many sibling sub-projects. It also builds the path refs for the compile and test targets. And it handles external jars (which we don't usually build) nicely as well.
Here's a simple example: say my project needs log4j. All I need to do it put these lines in my build.xml:
<taskdef name="dependencies" classname="org.trapdoor.decorum.Decorum">
<classpath location="${lib.dir}/decorum-0.2.jar" />
</taskdef>
This tells ant to add Decorum's task definition. Now I can add dependencies entries to my build.xml:
<dependencies id="main" libdir="${lib.dir}" excludes="clean">When I use the generated path in my compile target, it will find the most recent version of log4j in the library directory:
<dependency name="log4j" />
</dependencies>
<target name="compile" depends="init">In this example "path.main" refers back to the id I gave my dependencies.
<javac srcdir="${src.dir}/main/java" destdir="${build.dir}/main/classes"
includes="**/*.java" classpathref="path.main">
Here is a complete [FILE REMOVED -- I no longer use decorum] example with minimal decorum dependencies. In my next post I will illustrate some of the more advanced features like version and building.
Thursday, 9 August 2007
Making the most of vim: vimproject saves typing
The solution is a small Python script and the vim-python package available on some Linux distributions (Ubuntu, for example). By adding a few lines to ~/.gvimrc and writing a simple XML file, you can get vim to add a menu which allows you to open files quickly, with no typing and without resorting to a huge, slow IDE. Full instructions are on the vimproject page.
vimproject works with vim in GUI mode -- it needs the GUI's menu bar, so it won't work with the non-GUI version. It could probably be done in vim's built-in language, but I don't know that and don't have the time or the inclination to learn it.
Making the most of vim: ant and javac
First, vim allows us to set an external program to be called for the :make command. This goes in ~/.vimrc
set makeprg=ant
Now, when you issue a :make command to vim, it will call ant to build the project. Now with a bit more configuration, we can get vim to parse the error messages from javac and step through them.
Back to ~/.vimrc to tell vim what javac's messages look like:
set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,\%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
Make sure that horrendous code goes on one line. It came from a bit of head scratching and a lot of vim's documentation.
Now, after a :make you can step forward and back through the compiler messages using :cn and :cp.
That is all the IDE I need -- just enough help without getting in the way.
Wednesday, 8 August 2007
Using the Presentation Model pattern
At work, we are are about to begin coding a pretty large Swing application which will model most of the company's business. We are going to be using JGoodies binding and Presentation Model for this. I wrote a reasonably complex prototype to test out some ideas we are considering using. I used the same prototype to try out Presentation Model and binding. I like it a lot. There is a bit of a learning curve at the start, but this is rewarded with a lot less code to write. In particular, there is less boring, repetitive and error-prone code to write to synchronise the view with the domain model.
Anyone about to implement a Java Swing application should take a look.
Monday, 6 August 2007
Configuring Linux WiFi (wireless) without a GUI
I put together a collection of bits to make a small sever this weekend. I wanted to use Debian Etch, but it doesn't support my RaLink RT2561/RT61 wireless card out of the box and the build & install instructions for the driver were hopeless.
I decided to use Ubuntu 7.04 Server instead -- it supports the RaLink chipset out of the box. But configuring the card was a nightmare -- everywhere I looked for help suggested I fire up the network configuration GUI which I don't have as I installed the server version. I almost gave up, but did try a find/grep in /etc to see what I could find. And there it is, plain and simple at the bottom /etc/network/interfaces:
iface ra0 inet dhcp
wireless-essid whisperingwind
wireless-key FFFFFFFFFF
The last line is the WEP key. So all that was needed was to edit this file and insert the appropriate values. Easy when you know.