Monday, June 30, 2008

Tip: Causes of java.lang.ClassNotFoundException

Class loading issues are a common frustration for many Java developers. The dreaded java.langClassNotFoundException means they can forget about going home at a reasonable hour. While Java class loading is very powerful feature, it is also a very flexible and confusing feature. But don’t let this exception scare you. The majority of the time, there are three very practical things to look at in order to resolve the issue.
  1. If you are loading a class by name either using Class.forName() or an Inversion of Control container like Spring it may be as simple as the class name was spelled incorrectly. Validate the fully qualified class name is spelled correctly. The best way is to use the Eclipse “Copy Qualified Name” feature or copying and pasting the package name and class name directly from the source file.
  2. The mostly likely culprit is the class can not really be found. This can be caused by the directory or jar file containing class not being included in the JVM classpath. The other common cause when multiple class loaders are involved such as in a web container or application server is a visibility problem. For example classes in an ejb-jar do not have access to classes in the war file for the majority of application servers. But classes in the war file have access to classes in the ejb-jar. The reason is the war file typically has its own class loader which is a child class loader of the ear class loader. The basic rule is children class loaders have access to their parents but not visa versa. For this error, check your application server’s class loading documentation and make sure the class that is trying to access the not found class has the acceptable access.
  3. The most challenging cause to debug is a dependency issue during initialization of a class. During initialization if a class can’t find certain resources it depends on such as other classes or files, this may result in a ClassNotFoundException. To resolve this, you may need to validate all dependencies are available. If you have the code, you can look at the class imports and any static initilization. If you don’t, you might need to reverse engineer the class to determine the dependencies.
I hope this helps. Just remember the cause of ClassNotFoundExceptions can be difficult to resolve but they are always deterministic so stick with it.

Thursday, June 26, 2008

Announcing Beginning Groovy and Grails Book

Ok, Beginning Groovy and Grails has been available for about a week and my co-authors have already announced it but I wanted to wait to make my announcement when the electronic/PDF version was available. It was a long but fun process and I am very proud of the results. I think we have managed to put together a book that will easily enable developers to get up to speed with what they need to know in Groovy to begin being productive in Grails. I think the remainder of the book does a good job of providing a strong foundation of the common things, plug-ins and tips a new Grails developer will need to know in order to put together a fully functional Web 2.0 application. Currently Amazon.com is sold out of print versions but you can still order and they will be getting more soon. Or you can purchase the print or electronic version from the Apress website.

Virtualization on the Mac; VMWare Fusion vs. Parallels

Let me start off by disclosing I am an architect, software developer, consultant and author so my use of virtualization may not be the typical use. Your use and results with virtualization are likely to vary. That said the way I primarily take advantage of virtualization on my Mac is segmentation. By that I mean I typically have multiple virtual machines at one time. I organize them by client, project or technology. This enables me to simplify my life. For example, one of the best things about owning a Mac laptop for a consultant is it allows me through virtualization to carry all three major operating system; OSX, Windows and Linux, all on a compact and powerful device. In addition, it enables me to create customized and easily backed up environments for each of my clients. When my assignment or contract ends, I can backup the virtual machine to a large secure hard drive and when my clients return with more work or questions, I am able to bring everything back up the way it was.

I bought my first Mac, a Mac Book Pro, just over a year ago. I immediately purchased a copy of Parallels because at the time it was the only viable virtualization option available for Mac. I successfully used Parallels for about 9 months on OS X 10.4 Tiger. I endured some minor annoyances which I will discuss later but over all I was extremely pleased. Then I upgraded to OS X 1.5 Leopard by backing up my whole machine, formatting the hard drive and reinstalling the OS and all my software. After that, I started running into some stability problems which I will describe later. That made me start evaluating other options. After discovering how my friends enjoyed VMWare Fusion, and based on my experience with other VMWare products, I made the switch. So for the past four months, I have been creating all new VMs in VMWare and using Parallels for my existing VMs.

I think both solutions are excellent and I will be the first to admit that some of my issues with Parallels could be self-inflicted. But this experience encouraged me to provide a comparison of the features and things I like and dislike about both products. I hope it helps if you are trying to evaluate virtualization solutions for the Mac.

VMWare Fusion

Over all, I have found VMWare Fusion to be extremely stable and simple which is why it is now my primary VM solution. However, it lacks many of the Mac integrations I enjoy in Parallels and does not have very many configuration options.

+ Stable, works well on OS X 10.5 Leopard and with Spaces
+ Larger community
+ Many reconfigured images
+ VMs can be shared between Windows and Mac versions of VMWare
+ VM is stored in a single stand alone file
- Not very may configurations, including changing a VM name - the solution for that feels very hacky
- Poor integration with the Mac - integration between the Mac and VM is the same as having two separate machines on a network.
- Start up performance from sleep seems slower than Parallels, but that might be because it uses an overlay until the machine is ready so it may just be perceived performance
- Making a clone is just copying a file. When you start the new VM copy, it prompts you as to whether this is a move or a clone which feels very reactive not proactive.
- Virtual library window stays up in the background after the VM is started
- Sound doesn’t work even after following forum and tech tips

Parallels Desktop for Mac

Over all, Parallels excels in Mac integration.

+ Great Mac integration - I love the fact it shows up as a device like any disk image
+ Parallels explorer enables you to see file contents of a VM with out starting it up which can save time when you just need a file
- Unstable with OS X 1.5 especially when using Spaces
- Constantly crashes my whole machine when I plug in a projector while it is running
- Prompts me with warnings of missing devices every time the VM starts up after removing the original base VM I cloned from
- I can not stand that the applications running in the VM are added to my dock. This needs to be changed to a configurable option
- Some times it does not want to shut down without forcing it when certain applications are running
- With Spaces turned on after my Mac wakes up, I get horrible screen painting issues in my VM

Wednesday, June 18, 2008

My Biggest Fan

I recently received copies of the third book I co-authored for Apress, Beginning Groovy and Grails. Since then my four year old son has been carrying around copies of all my book saying things like "I love your books, the ones that you wrote" and "I love the books your pictures are on". But that did not prepare me for coming home today and finding my son had taken all the Apress books off my shelves, which are quite a fews, in an effort to find my picture on the back of them.

Saturday, June 14, 2008

Eclipse Productivity Tips

I gave a presentation this week at COJUG (Central Ohio Java Users Group) called 10 (or so) Eclipse Productivity Tips. The presentation was very well attended, especially for a lunch meeting. We had over 50 people. The slides are available on the link above if you want to check them out.

Friday, June 13, 2008

eApps is great for Grails hosting

In episode 58 of the Grails Podcast, Glen and Sven spoke about a Grails hosting service that costs about a dollar a day if used in production. So, I thought I would share my experiences in hosting Grails applications. For the past year I have used eApps for my Java, PHP and Grails hosting. I have been extemely happy with them from a support, feature and price perspective. I have used many hosting services in the past including other Java hosting services and eApps is definitely the best. My Beginning Groovy and Grails co-authors, Joseph Nusairat and Jim Shingler also use them for hosting as well.

eApps starts Java hosting at $20 a month for Tomcat and a offers a $30 option for JBoss or Glassfish which is less than a dollar a day. It also includes database options of MySQL, PostgreSQL or Derby. It has a load of other standard options such as email, ftp, control panel, PHP, Ruby On Rails, etc. But my favorite features are root access to my own virtual server, DNS configuration through control panel, easily hosting of multiple domains with one account (which can bring the daily cost down furture) and a Subversion or CVS repository.

I personally use the JBoss option while Joseph and Jim are using the Tomcat option.

AWS EC2 Hibernate Java SDK v2 Example

I recently wanted to automate the creation of developer VMs in AWS using EC2 instances. To improve the developer experience (DX), I didn'...