You are viewing outdated content for BUG. If you have a BUG Y.T. edition or 2.0 series device, please visit our updated wiki: http://wiki.buglabs.net



Java.lang.NoClassDefFoundError

From BUG Wiki

Jump to: navigation, search

Introduction

One of the most common issue is the java.lang.NoClassDefFoundError Exception. The most common cause is that in your source code, you've imported a package, but you have not specified this in your app's MANIFEST.MF.

Howto

Here's an example of error:

java.lang.NoClassDefFoundError: javax.servlet.ServletException
	at sensorstatuspage.Activator.start(Activator.java:27)
	at ch.ethz.iks.concierge.framework.BundleImpl.startBundle(BundleImpl.java:459)
	at ch.ethz.iks.concierge.framework.BundleImpl.start(BundleImpl.java:418)
	at com.buglabs.bug.program.UserAppManager.startApp(UserAppManager.java:149)
	at com.buglabs.bug.program.UserAppManager.processQueue(UserAppManager.java:129)
	at com.buglabs.bug.program.UserAppManager.run(UserAppManager.java:104)
	at com.buglabs.bug.program.ProgramServlet.doPost(ProgramServlet.java:141)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at com.buglabs.osgi.http.HttpServer.processRequest(HttpServer.java:431)
	at com.buglabs.osgi.http.HttpServer.process(HttpServer.java:251)
	at com.buglabs.osgi.http.HttpServer.run(HttpServer.java:93)
	at java.lang.Thread.startup(Thread.java:782)

You can see that it didn't have javax.servlet.ServletException satisfied

(PS: if you wonder why you don't get the line numbers and would like to get them look here)

Here we can see in Activator.java the following code

import javax.servlet.http.*;

which is the reason of the error

In this case, for the servlet lib and packages, you'll need to go back to eclipse and go into the project explorer view, click on your project and expand it, then expand bug libraries. Then look for something like javax.serverlet, here it is:

com.sun.javax.servlet.jar

Then expand it and expand META-INF and doubble-click on MANIFEST.MF and you'll see the following content:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_16-b02 (Sun Microsystems Inc.)
Bundle-SymbolicName: javax.servlet.source
Bundle-Name: javax.servlet.source
Bundle-Version: v200912221442_P
Bundle-Vendor: Eclipse Orbit
Export-Package: javax.servlet, javax.servlet.http, javax.servlet.jsp, 
 javax.servlet.resources
Build-Level: production
Built-On: darner.buglabs.net December 22 2009 1442

So try to add the export package content like this in your Manifest in the Import-Package Section.:

 javax.servlet,
 javax.servlet.http,

So your manifest will look like this at the end:

Manifest-Version: 1.0
Bundle-Name: SensorStatusPage
Bundle-Activator: sensorstatuspage.Activator
Bundle-SymbolicName: SensorStatusPage
Bundle-Version: 1.0.4
Bundle-Vendor: Denis "GNUtoo" Carikli
Bug-Bundle-Type: Application
BUG-API-Version: 1.4.3
Import-Package: com.buglabs.bug.module.sensor.pub,
 com.buglabs.bug.module.vonhippel.pub,
 org.osgi.service.http,
 org.osgi.framework,
 org.osgi.util.tracker,
 com.buglabs.application,
 com.buglabs.util,
 javax.servlet,
 javax.servlet.http

Be careful to add a space before each imported package in the manifest,and to terminate it by a line break that doesn't contain any space. Incorrect spacing will also lead to annoying-to-debug issues.