This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassNotFoundException" Watch "ClassNotFoundException" New topic
Author

ClassNotFoundException

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20491
    ∞

Noobs get ClassNotFoundException often enough, I thought it would be good to make a list of the most common causes. I plan on making this new thread the "go to" thread ClassNotFoundException.

So, staff, ranchers and other smarty pants types: what is your advice for "Oh no! I got a ClassNotFoundException! What do I do!?"


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

1) check the class path; print it using System.getProperty("java.class.path") when in doubt.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

I guess it would be helpful to first know which class could not be found i.e. an application class, one belonging to a third-party library (JAR) etc.
The environment would dicate what to check specifically. Is it a 'simple' application being run from the command-line? If so, is it packaged inside a JAR file? Is the application running inside a servlet container or application server, if so which one? If it is the list of possible things to check could become quite large and very specific. Maybe even varying between different versions of the same container / application server. Though I guess at that point we'd be moving away from 'most common causes' anyway.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

I find the class myself first when I get a ClassNotFoundException. Usually using Eclipse's open > type for a workspace where it is found. Then I check to see if the class giving a ClassNotFoundException is on the classpath of my application. The runtime classpath (java jar dependencies/manifest) not the build path.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
jQuery in Action, 2nd edition
 
subject: ClassNotFoundException
 
Similar Threads
My head hurts: JDBC + Java
Unable to understand exception
Can you help me to solve this question
Why can I not Class.forName in doPost
HibernateException Pls Help