This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException

 
paul wheaton
Trailboss
Pie
Posts: 21597
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!?"

 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) check the class path; print it using System.getProperty("java.class.path") when in doubt.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic