Archive for May 13th, 2008

May 13 2008

When is a Missing Class File Not Missing?

Published by Mark under Programming

This is the part of the show where experienced Java developers laugh as the C# guy tries to tread water. I’ve been developing a Java console application to import some data files into a MySQL database. The development work has all been done in Eclipse on Debian, testing against a local DB. When the time came to test against a remote DB I was offered a Windows-based VPN client to use for the connection, but nothing for Linux. So I decided I might as well package the app up for deployment and run it on my XP system, where it could connect to the database and do its thing.

I jarred up everything (too much, in fact, but I’ll come back to that) and moved it over to Windows. When I double-clicked the jar file the VM popped an error dialog that said “Could not load main-class: ClassName, program will exit.” That sent me down a path of looking at the manifest and trying to figure out why the VM couldn’t find the main class. The package paths all seemed correct. Finally I tried running it from the command line instead of double-clicking (good thing, too, since as I said above it’s a console app). Now the error I received was “exception in thread ‘main’; java.lang.noClassDefFound: org.quartz.SchedulerException”. Well, that’s different.

Turns out I had naively packaged my dependent .jar files into the main .jar for the app, expecting everything to get loaded correctly. That doesn’t work without some additional plumbing. Once I moved them out to a directory and specified the locations correctly in the Class-Path variable in the manifest, all was well. Lesson learned: always execute my programs from the command line, lest the VM bury my exception in something misleading.

No responses yet

May 13 2008

Eclipse: Refresh the Package View

Published by Mark under Programming

Sometimes it’s those little things that drive you nuts, like expecting that when Eclipse displays the Project Properties dialog and you click the Build Path and then click “Add Jars” the resulting list will contain whatever .jar files you happen to have placed in the project folders. Apparently this is not so. Today I needed to add a few .jar files to a project, so I copied them into the lib folder under my project, where the existing .jar files already live. I then went into the project properties to add the jars to the build path. But there were no jars to add. I stumbled around a bit like the idiot I often am, until I happened to click “File | Refresh” from the menu bar with the package selected. Bingo. Eclipse refreshed the package list and suddenly all my shiny new jars were there and available to be added to the path. I had to select the package first, however. If it wasn’t selected then the “File | Refresh” choice was disabled in the menu.

No responses yet