1
votes

I am new to OSGi. I am using eclipse PDE 'Kepler Service Release 2'.

I want to make classes inside the javax.servlet package available for my test clients. But I am getting NoClassDefFoundError when , just for testing, trying to create a ServletException object.

java.lang.NoClassDefFoundError: javax/servlet/ServletException.

I have tried these two ways. both are not working:

Try 1: using system packages

I have these startup parameters in my eclipse OSGI Framework:

-Dorg.osgi.framework.system.packages.extra=javax.servlet
-Dorg.osgi.framework.system.capabilities="osgi.ee; osgi.ee=\"JavaSE \";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8\""

I can see this Export-Package in the System Bundle (0) : javax.servlet; version="0.0.0"[exported] Im my bundle I have this Import-Package: org.osgi.framework;version="[1.5,2)",javax.servlet.

I could not get this working even with a flag -Dorg.osgi.framework.bootdelegation=* while starting the container.

Try 2: using the ExtensionBundle

My ExtensionBundle has the jar javaee-api-6.0.jar in its classpath and exports the javax.servlet package. But still I am getting 'java.lang.NoClassDefFoundError: javax/servlet/ServletException'.

I dont have any startup parameters for this.

In the Manifest.mf of the extension bundle: ...

Bundle-ClassPath: .,javaee-api-6.0.jar
Export-Package: ....,javax.servlet,...
Fragment-Host: system.bundle;extension:=framework

...

Am I missing anything.

Thanks in advance.

1

1 Answers

1
votes

The JRE does not contain the package javax.servlet. So you can not simply export it. You can take a look at the bundle below in maven central. It exports the package. Also remember that the servlet API will not be enough to run a servlet. You will also need an implementation of the osgi HTTPService. Possible implementations are: felix http service, org.eclipse.equinox.http.jetty, pax-web. So the even better solution might be to install one of these.

javax.servlet:javax.servlet-api:3.1.0