This discussion is archived
1 Reply Latest reply: Jul 14, 2010 6:42 AM by 800387 RSS

java.lang.NoClassDefFoundError

843810 Newbie
Currently Being Moderated
Hey guys,

I'm brand new to programming and have encountered the all-too-stressful java.lang.NoClassDefFoundError. I understand that implies that my classpath is not set correctly yet I'm still not completely sure how to fix it. The strange part is that the error appears as: "java.lang.NoClassDefFoundError: HttpServlet" - HttpServlet being a library I attempted to import earlier, albeit unsuccessfully. In my attempts to import the library I messed around with my imports so I feel that the root of the problem is there..

The full error message reads:

java.lang.NoClassDefFoundError: HttpServlet
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClassCond(Unknown Source)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at java.net.URLClassLoader.defineClass(Unknown Source)
     at java.net.URLClassLoader.access$000(Unknown Source)
     at java.net.URLClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
Caused by: java.lang.ClassNotFoundException: HttpServlet
     at java.net.URLClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     ... 12 more
Exception in thread "main"

If anyone knows how to fix this please let me know!

Thanks,
Alejandro
  • 1. Re: java.lang.NoClassDefFoundError
    800387 Newbie
    Currently Being Moderated
    NoClassDefFound indicates a runtime (not compile time) classpath issue. You imported and compiled fine. However, at runtime, the relevant JAR (likely servlet.jar or javaee.jar) was not on the classpath. Are you running this in a J2EE container ala Tomcat or JBoss or Jetty? I would be surprised to find you using HttpServlet outside of a Servlet container.

    - Saish