2

I am trying to use Restlet in embedded OSGi environment. I have added the org.restlet.jar version 2.3.0 in the class path of my restlet test bundled. But it kept giving me the following error.

java.lang.NoClassDefFoundError: com/sun/net/httpserver/HttpHandler

The documentation says that this jar should be enough but it is currently not working. The bundle is started by an Equinox Framework which is started by a standalone launcher, later to be used outside of Eclipse environment.

Is there another jar fie that I should add to get the proper server connector? I will not be using servlets so the Restlet connectors are the only options.

When I manually start the bundle I get the following warning:

WARNING: No available server connector supports the required protocols: 'HTTP' . Please add the JAR of a matching connector to your classpath.

I had already spent a lot of time to get it working with no luck. Thanks in advance!

Excite
  • 484
  • 1
  • 5
  • 19

1 Answers1

4

I have found the solution in the Answer posted here.

So the package com.sun.net.httpserver (which is part of the JDK) needs to be exposed to the OSGi environment. The best solution that has worked for me is to expose it through the system bundle during framework launch by adding it to the following property:

org.osgi.framework.system.packages.extra = com.sun.net.httpserver

If you are using Restlet in an OSGi environment using a custom framework launcher, adding the above solution will make the package available for import. I think they should have added this information in their documentation. This problem does not occur when Restlet is installed in Eclipse and used directly in Eclipse environment using Eclipse launcher because I think the configuration will be automatically setup.

Community
  • 1
  • 1
Excite
  • 484
  • 1
  • 5
  • 19
  • I am having the same problem under KURA which runs above eclipse Equinox, how can I set the property for the system bundle? – sabrina2020 Nov 19 '15 at 13:14
  • @sabrina2020 Sorry for the delay. I don't know the framework you mentioned but if u are working on eclipse another solution I saw was to change eclipse's preference so that it will not consider it as error but may be warning. If I remember correctly preference->java->compiler->errors/warning-> And then on the right side u change "Depreciated and restricted API" rule to "Warning" from "Error" – Excite Nov 21 '15 at 22:45