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.

27 comments:

Unknown said...
This comment has been removed by the author.
javin paul said...

As per java doc java.lang.classNotFoundException comes in following cases:
1) When we try to load a class by using Class.forName () method and Class is not available in classpath.
2) When Classloader try to load a class by using findSystemClass () method.
3) While using loadClass() method of class ClassLoader in Java.

and it could be even more difficult to find out the real cause in integrated environment like J2EE where different web server use different classloaders and it can come if class is not visible to classloader.

Thanks
NoClassDefFoundError vs ClassNotFoundException

P-H said...

Hi Chris and nice tips on how to resolve java.lang.ClassNotFoundException problems.

Sometimes the root cause can be simple or very hard such as complex classloader problems. As per Javin, it can be particularely challenging when debugging such problem within a big Java EE system with dozens of applications deployed.

Regards,
P-H
Java EE Support Patterns

john said...

Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
or learn thru Java Online Training from India Students.

afiah b said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

Java training in Marathahalli

Java training in Btm layout

Java training in Rajaji nagar

sasitamil said...


This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 


Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

service care said...

Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definitely interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
lg mobile service chennai
lg mobile repair
lg mobile service center near me

atharveducation said...


Nuvigil smart drug is the trade name for Armodafinil smart drug and is the enantiopure compound of Modafinil. There are a number of health benefits that the use of Nuvigil smart drug has to offer to its users. So, you can buy Nuvigil online. The use of the smart drug is safe and has no health issues attached to its usage. In the year 2006, the FDA approved the use of generic Nuvigil smart drug to be used to treat a number of mental issues. Buy Nuvigil online as the use of Nuvigil smart drug has long effect when compared to other smart drugs. This is mainly because Armodafinil smart drug has a longer half-life than the other smart drugs. Therefore more and more people are depending on Nuvigil smart drug to carry on their daily routine smoothly.
Buy Nuvigil online

Customer relationship management said...

This is really an awesome post, thanks for it. Keep adding more information to this.mulesoft training in bangalore

Customer relationship management said...

Really it was an awesome article,very interesting to read.You have provided an nice article,Thanks for sharing.salesforce developer training in bangalore

Customer relationship management said...

Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving.salesforce admin training in bangalore

Customer relationship management said...

Linking is very useful thing.you have really helped lots of people who visit blog and provide them use full information.servicenow training in bangalore

Customer relationship management said...

Your articles really impressed for me,because of all information so nice.cloud computing training in bangalore

watson said...

Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts.web designing training in bangalore

Bangalore Training Academy said...

Thank you so much for the great and very beneficial stuff that you have shared with the world.

Bangalore Training Academy is a Best Institute of Salesforce Admin Training in Bangalore . We Offer Quality Salesforce Admin with 100% Placement Assistance on affordable training course fees in Bangalore. We also provide advanced classroom and lab facility.

Softgen Infotech said...

Such great information for blogger I am a professional blogger thanks…

Advance your career as a SharePoint Admin Engineer by doing SharePoint Admin Courses from Softgen Infotech located @BTM Layout Bangalore.

Softgen Infotech said...

Such great information for blogger i am a professional blogger thanks…

Became An Expert In UiPath Course ! Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM.

Softgen Infotech said...

Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

Get SAP HANA Admin Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.

watson said...

Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.

sap abap training in bangalore

sap abap courses in bangalore

sap abap classes in bangalore

sap abap course syllabus

best sap abap training

sap abap training center

sap abap training institute in bangalore

watson said...


It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful

sap hana courses in bangalore

sap hana classes in bangalore

sap hana training institute in bangalore

sap hana course syllabus

best sap hana training

sap hana training centers

best sap hana training

watson said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.

sap mm training in bangalore

sap mm courses in bangalore

sap mm classes in bangalore

sap mm training institute in bangalore

sap mm course syllabus

best sap mm training

sap mm training centers

watson said...

Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind

sap fico training in bangalore

sap fico courses in bangalore

sap fico classes in bangalore

sap fico training institute in bangalore

sap fico course syllabus

best sap fico training

sap fico training centers

meritstep Technology said...

Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
servicenow online training

Customer relationship management said...

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

Blockchain certification Online Training in bangalore

Blockchain certification courses in bangalore

Blockchain certification classes in bangalore

Blockchain certification Online Training institute in bangalore

Blockchain certification course syllabus

best Blockchain certification Online Training

Blockchain certification Online Training centers

Customer relationship management said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.

Hadoop Online Training

Hadoop Classes Online

Hadoop Training Online

Online Hadoop Course

Hadoop Course Online

Customer relationship management said...

This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me.

Tableau Online Training

Tableau Classes Online

Tableau Training Online

Online Tableau Course

Tableau Course Online

radhika said...

This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me.

AWS training in Chennai

AWS Online Training in Chennai

AWS training in Bangalore

AWS training in Hyderabad

AWS training in Coimbatore

AWS training


The Ultimate Enterprise Java Build Solution Revisited

In May of 2009, I wrote the blog post The Ultimate Enterprise Java Build Solution . Over the past 7 years since I wrote the post I have help...