Custom CSS

Monday, November 19, 2007

NPE when sending mail (JavaMail 1.4) in Ubuntu

Never noticed this before, but it came up today. I tried to send some mail, and got this nasty exception:

org.springframework.web.util.NestedServletException: Request processing failed; 
  nested exception is java.lang.NullPointerException
Caused by: java.lang.NullPointerException
  at java.lang.String.concat(
  at com.sun.activation.registries.MailcapFile.parseLine(
  at com.sun.activation.registries.MailcapFile.parse(
  at com.sun.activation.registries.MailcapFile.createMailcapHash(
  at com.sun.activation.registries.MailcapFile.<init>(
  at javax.activation.MailcapCommandMap.loadFile(
  at javax.activation.MailcapCommandMap.<init>(

Curiously, this didn't occur until I started Mavenizing the project I was working on, though I was using the same version of JavaMail as before. The fix? Apparently it only happens if you're using Ubuntu. Open up ~/.mailcap and delete the -e at the top of the file.

Thursday, October 25, 2007

DbUnit gotchas on inserting data

If you have an XML dataset that looks something like this:

<orders id="1" date_paid="2000-07-01"/>
<orders id="2" date_paid="2000-04-01" date_voided="2000-04-02"/>
<orders id="3" date_paid="2000-03-01" date_voided="2000-03-02"/>
<orders id="4" date_paid="2000-02-01" date_voided="2000-02-02"/>
<orders id="5" date_paid="2000-01-02" email=""/>

You might be stumped when you run your test and DbUnit won't insert data into the date_voided and email columns (I know I was). Apparently, DbUnit will use the first <orders> element as a template (eg insert into orders(id, date_created, date_paid) values(...)), thus ignoring the other columns. The solution is to change your first element to make all the relevant columns null or some default value:

<orders id="1" date_paid="2000-07-01" date_voided="[null]" email="[null]"/>

Ambiguous MySQL error messages

I got this error message from MySQL the other day:

ERROR 1025 (HY000): Error on rename of './mydatabase/#sql-13c8_8' 
to './mydatabase/mytable' (errno: 150)

It have been nice if MySQL told me I couldn't drop a FK without dropping both the FK constraint and the index (and in that order), but such is life. If you are running a SQL statement like this:

alter table `mytable` drop `mycolumn`;

..then you want to write this instead:

alter table `mytable` drop foreign key `myconstraint`;
alter table `mytable` drop index `myindex`;
alter table `mytable` drop `mycolumn`;

Sunday, October 21, 2007

Getting the Thinkpad T60 media buttons to work

I had originally used XFCE's keyboard preferences applet to configure this, but I found that the tpb package offers volume up/down/mute support (natively, without your needing to write your own scripts), plus it provides a neat little OSD that shows you the volume level. To do this, follow these steps:

  1. Install the tpb package via: sudo apt-get install tpb. You will be prompted to remove hotkey-setup, type y.
  2. Copy the /etc/tpbrc file to ~/.tpbrc.
  3. Edit ~/.tpbrc and look for the THINKPAD line, then change the command on the right to whatever command you want executed when the ThinkVantage button is pressed.
  4. If you have created a .Xmodmap to remap capslock to ctrl, uncomment the line that says XEVENTS OFF.
  5. Finally, make sure that the MIXER settings are all commented out and save the file.
  6. Add yourself to the nvram group via the Users and Groups applet.
  7. Edit /etc/default/tpb and change the line START_TPB="true" to START_TPB="false"; I've found if tpb starts automatically as root and you assign, say, xfce-setting-show to the ThinkVantage button, it won't be managed by your window manager.
  8. Add the following command in your Autostarted Applications applet: tpd -d
  9. Restart and try pressing the volume up/down keys

Troubleshooting: If it doesn't work, you can run tpd -v in the terminal to give you verbose output and help troubleshoot the problem. Type groups and double check that you are in the nvram group.


Don't run tpb -d as root!

Wicd, for great wireless justice

I hate network-manager, wifi-radar, or anything else in the official Ubuntu repositories. All of them have their own share of annoyances and you need to enter your password to connect to a wireless network (yes I realize there are ways around it), but for an easy hassle free interface, I and 4 out of 5 other IT professionals recommend: wicd.

Enabling the framebuffer

To enable the framebuffer for high resolution text consoles (eg when your system is booting up), edit your /boot/grub/menu.lst file, and find a section that looks like this:

title   Ubuntu 7.10, kernel 2.6.22-14-generic
root    (hd0,0)
kernel    /boot/vmlinuz-2.6.22-14-generic root=UUID=fa696915-5ca5-4629-a3ee-296c7e382e2d ro quiet splash
initrd    /boot/initrd.img-2.6.22-14-generic

Add vga=791 to the end of the line that begins with kernel, so it looks like this:

kernel    /boot/vmlinuz-2.6.22-14-generic root=UUID=fa696915-5ca5-4629-a3ee-296c7e382e2d ro quiet vga=791

I usually take out the splash directive so I can actually see all the pretty high resolution text (and figure out what went wrong if something did).

Upgrading to Gutsy Gibbon

If you learn but one thing from this post, learn this: turn off your screensaver before upgrading from Feisty. You don't want what happened to me to happen to you. I left the upgrade process unintended after it started downloading all the files for the install, and when I came back, my screensaver was activated but I could not login. Logins had been disabled for some unknown reason; even trying to make a new login would not work. Hard drive activity had ceased, so I knew the update manager was just waiting on some input from me. Beautiful.

After doing a soft reset, I was halfway between a Gutsy install and a Feisty install. I knew the process probably crapped out as it was configuring installed packages, so after running dpkg --configure -a, I was looking good. Also, I ran the update-manager one more time, and it told me I had an unfinished partial installation, and finished it up for me. Despite running Gutsy smoothly, that nagging feeling in the back of my mind that tells me to use Gentoo is getting stronger.


I also noticed I had to add thinkpad_acpi to my /etc/modules after upgrading, otherwise my fan would not work.


You'll also want to update your 3rd party sources. I use Medibuntu and Wine, and their sources can be updated adding the following lines in /etc/apt/sources.list:

# Medibuntu multimedia packages
# GPG key: 0C5A2783
deb gutsy free non-free
#deb-src gutsy free non-free

# Upstream Wine
# GPG key: 387EE263
deb gutsy main
deb-src gutsy main


VMware doesn't work anymore :( You can download the Gutsy version of VMware here.

Friday, October 12, 2007

Viewing source in Firefox with any editor

You can use any editor you want to view source code in Firefox. Just type about:config in the location bar, and change these values:

view_source.editor.external = true
view_source.editor.path = /usr/bin/gvim

Change /usr/bin/gvim to whatever you like.

Tuesday, October 9, 2007

Module r818x causes Ubuntu Feisty to freeze

If you have an SMP kernel (likely, as the linux-image-generic package is installed by default), the r818x is likely to freeze Feisty when using your wireless card. I found this out through trial and error with my DLink card, and there are only two possible fixes.

One is to download the WinXP driver and use ndiswrapper to install it. This isn't the route I chose, but to do it, just download the WinXP driver, and run:

ndiswrapper -i 
ndiswrapper -l

If the driver and hardware show up after the last command, you're in business. Just edit /etc/modules and add ndiswrapper to that list of modules.

The second way to do it is simply to use a non-SMP kernel, like linux-image-386, which is what I did, because I only have one processor on that machine.

Saturday, October 6, 2007

How to fix double click for Java applications in Xubuntu

No matter how I tweak the mouse sensitivity settings in Xubuntu, the changes aren't reflected in Java applictions I run. This creates ugly problems in IDEA and Netbeans because I can't open files. The fix is to edit the ~/.Xresources and add:

*multiClickTime: 400

Thursday, September 20, 2007

Look at all the pretty colors

I love it when my terminal looks like somebody vomited all over it. It helps me find the specific chunks of logging data I need to see (pun definitely intended). Here's a list of things to colorize, and how to do them:

Output of ls

ls --color=yes. Even if you pipe it through less, the colored output stays.

File types and extensions

See different colors for different files types and extensions. Add the following to your .bash_profile:
eval `dircolors -p`


Set this environment variable to get colored output for ant:
export ANT_ARGS='-logger'


Use Wirble.


Use ANSIColorLayout.

Code on your webpage

Use dp.SyntaxHighlighter (javascript) or Geshi (php only). LousyCoder Blog is powered by the former, and I think it's better anyway.


I have no clue.

Monday, August 13, 2007

Resin 3.0 and HTTPS

How to configure Resin to use SSL: SSL with Resin. The directions on the site are accurate, but the directories for openssl were a little confusing for me in Ubuntu Feisty Fawn. Here are configure arguments to get things rolling:

./configure --enable-ssl --enable-jni \
  --with-openssl-lib=/usr/lib \
  --with-openssl-include=/usr/include \
  --with-openssl=/usr/lib/ssl \
  --with-jni-include="-I${java.home}/include -I${java.home}/include/linux" \

There is a bug in Resin 3.1.2 that fails to load the library unless the compiler flag is set. Also, you must make with:

make "PROXY_LIBS=-lpthread -lc";

Where ${java.home} is the installation directory for your JDK. Do a locate jni_md.h to find out what the right include directory is; SSL with Resin won't work unless JNI is also enabled.

Tuesday, July 17, 2007

Quartz Clustering with Spring 2.0.x

Today, I was fooling around with trying to get Quartz to work in a clustered environment with Spring 2.0.x. I found this blog post, and all was fine and good, but I ran into a few extra hurdles:

I wasted a bunch of time trying to get 1.5.1 and 1.6.0 working, when 1.5.2 is the only one out there that really works! Grr...

Tuesday, April 17, 2007

Remote debugging with Tomcat or any Java application

This should have been posted a while back, but you can attach a debugger to any running application if you set your runtime opts the right way:

set JAVA_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE \
 -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 \
 -Xmx32m -Xmx128m -XX:MaxPermSize=1024m

I do this for Tomcat; I add that line into my and attach Eclipse's debugger to my running instance of Tomcat. This way I can break my webapp, make some code changes, and see them reflected immediately, without restarting the app server. It's extremely convenient to be able to live in the debugger.

Delete files locked by Windows

Windows loves to lock files that are in use, and not let you delete them. It's one of the most annoying things about Windows, especially when you are trying to say, move a downloaded AVI movie file. There is, however, a registry key you can tweak to change this; you have to delete this key:


Friday, March 16, 2007

More Eclipse IDE Configuration

Here are several Eclipse 3.2 configuration and usage tips that have made my life easier.

Hide JAR files in the project

In the Java Perspective -> Package Explorer -> Icon to the left of close, choose Filters from the context menu. Check *.resources, Libraries from external, Libraries in project. Type *.jar into the Name filter patterns text field. This will ignore any JAR files in the project so they don't clutter your view.

Open Type, Open Resource, and GoToFile

Ctrl + Shift + T will open a search box that will match the Java class you type in, as you type. For example, to open, type MyClass and the search will be refined as you type. The same is done for resources with Ctrl + Shift + R. GoToFile (site down at the moment) will also do fuzzy searches. For example, typing "MCN" will match

Show implementors

If you select an interface or abstract method, and press Ctrl + T, you can see all implementors of that method.

Autocomplete Getters/Setters

Everybody knows you can Right Click on a source file -> Source -> Generate Getters and Setters... to do just that, but if you type "get" and then Ctrl + Space, Eclipse will offer to implement a getter for you. The same works for setters if you type "set" and Ctrl + Space.

Increase memory

Open up eclipse.ini, located in your eclipse home directory. You'll see some configuration that looks like this:


I have these changed to allow at least 256mb and at most 512mb of ram for eclipse:



I also grab the following plugins for development. These are rather well known, but if you don't know what they do, the names are pretty obvious. I develop in a lot of different languages, so I use plugins that aren't specific for Java development:
TestNG, Subclipse, CSSEditor, PHPEclipse, RadRails, M2Eclipse, SpringIDE

There are a couple of other plugins for Eclipse that others like to use, but I don't:
Sysdeo, Amateras

I like to run tomcat from the command line with the "run" option and see the output in a separate terminal, and I felt Amateras was too buggy last time I used it. As of this writing, Aptana is available with RadRails and provides similar functionality.

Sunday, February 4, 2007

The Road to Ubuntu

I finally got my new Thinkpad and prompty installed XUbuntu on it (because I don't like KDE or Gnome), and here were a couple of tweaks I did to get everything working the way I like:

Installing a fingerprint reader

I was pretty excited about getting ThinkFinger to work, but if you read the fine notes, you will find out that neither gksu nor gksudo work with ThinkFinger. There is a bug report filed here about it.

Disabling the PC beep

Edit rc.local and add the following line:

modprobe -r pcspkr

Getting the media keys to work

Get xbindkeys and run xbindkeys-config for a graphical tool to configure buttons. You'll probably want to create shell scripts for volume up, volume down, and mute. I created some but you need aumix for them to work:

# Lowers volume.
aumix -v +$1
aumix -w 75

# Raises volume.
aumix -v -$1
aumix -w 75

Here is a link to the toggle mute.

Fixing the garbled display on startup/shutdown

This is due to buggy ati drivers, I'm assuming. The way to fix this is to edit your /boot/grub/menu.lst by searching for "splash"; it should be the last word in a line that looks like this:

kernel          /boot/vmlinuz-2.6.17-10-generic root=/dev/sda1 ro quiet splash

Remove the splash word, save and reboot, and no garbledness!

Other links to helpful tips

Remote desktop with XUbuntu

Wednesday, January 24, 2007

SpringMVC and HTML Checkboxes

If a checkbox appears on an HTML form, but is not checked, the field will not be submitted by the browser at all. This means that SpringMVC may sometimes fail to bind a changed value. Consider the scenario:

  1. User checks a checkbox and submits.
  2. User is presented with the form again, due to validation errors.
  3. User corrects errors, but changes mind about checkbox selection and unchecks it.
  4. User resubmits form, but checkbox field is not sent, so Spring doesn't bind a value to it.
  5. User's original selection (checked) remains in the command object.

Here's the workaround from Expert Spring MVC and Web Flow:

<form ...>                                      
  <spring:bind path="command.acceptTermsAndConditions">
    <input type="checkbox" name="${status.expression}"
        value="true" ${status.value ? 'checked' : ''}/>
      I agree to the terms and conditions.
    <input type="hidden" name="_${status.expression}"/>