Sunday, October 19, 2008

The Agony of Java Preferences

My open source project, JIBS, uses Java preferences to save user settings. That part works very well using the Windows registry or, for Linux, hidden directories on the user's home. So far so good.

Then I have a user who says he want to use JIBS with his data on a thumbdrive as he moves from machine to machine. Well, OK, all I have to do is figure out how to write the property files out and read them back in without going to default registry and leaving garbage on every machine he visits.

So I extend Preferences and use the export function to get the file out. A quick test show that the import function reads it back in nicely. What I didn't notice on the quick test is that the export is a non-static function (meaning it works with my extension great), but the import is a static function (meaning it ignores my extension and write to the system properties - which I am trying to avoid). Argh! The lack of symmetry alone is enough to drive you crazy.

Next up, the preferences can not be changed while a program is running - you have to pass in on the command line. So if I try to use a pseudo preferences, I can write them out but not read them in, and if I use the real preferences, I have to have the user's type them on a command line. Yuck.

So now I have a starter module the forms the correct command line then cranks off another instance of Java. Seems a little silly really. Then I notice I lose all console statement (useful for debugging). So I have to get console output of the second Java instance and print it in the first Java instance and create a single from the second to the first so they will both shut down together.

Got all that working and fired off version 2.3.1. Then I hear from another user that JIBS won't work if he moves it from his download directory. Turns out I tested on paths with no spaces and he moved it to directory with spaces in the paths. So after a bucket of double-quotes I finally fixed that problem.

And all this after my first quick look way "no problem, I see preferences has both export and import"!

No comments: