When is a Missing Class File Not Missing?

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.

Leave a Reply

Your email address will not be published. Required fields are marked *