felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Evan Ruff <evan.r...@hendersonsawmill.com>
Subject Getting Started with Felix/Jetty
Date Thu, 14 Jun 2012 21:03:02 GMT
Hey guys,

I'm just getting started with Felix and OSGi in general. I've
been cursing around trying to find some information about using Felix and
I've gotten stuck on the most trivial example! I think I must be missing
some sort of basic concept and I was hoping someone could tell me what I'm
doing wrong?

For a little background, I'm trying to migrate a web-app to a more modular,
OSGi based, installable application. I want to distribute my application
and currently, that requires the administrator to set up a Jetty server and
install my Webapp. I'd much rather have a single application that contains
it's own Jetty server and then have the web-apps and their supporting J2EE
pieces be installed as OSGi modules.

To start, I've created a new Java Project, added felix to the class path
and spun up the following main:
public static void main( String[] args ) throws BundleException
 {
FrameworkFactory frameworkFactory = ServiceLoader.load(
FrameworkFactory.class ).iterator().next();
 Map<String, String> config = new HashMap<String, String>();
Framework framework = frameworkFactory.newFramework( config );
 framework.start();
 BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();

installedBundles.add( context.installBundle(
"file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
 installedBundles.add( context.installBundle(
"file:lib/org.apache.felix.log-1.0.1.jar" ) );
 installedBundles.add( context.installBundle(
"file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );

for ( Bundle bundle : installedBundles )
{
 System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
bundle.start();
 }
}

Which I pulled out of a  tutorial about embedding Felix.

I'm running into trouble when I get to the HelloServlet bundle. The
HelloServlet bundle is the simpliest thing I could write based off of the
HelloOSGi tutorials that were around. It's a pretty basic Activator,
registering the servlet as described in the Felix docs:

public void start( BundleContext context ) throws Exception
{
 ServiceReference<HttpService> sRef = context.getServiceReference(
HttpService.class );
if (sRef != null)
 {
HttpService service = (HttpService) context.getService( sRef );
 service.registerServlet( "/hello", new HelloServlet(), null, null );
}
 }

The HelloServlet bundle has org.osgi.framework and org.osgi.service.http in
the "Import-Package" part of the manifest.

When I run everything, I get a "Unable to resolve 4.0: missing requirement
[4.0] osgi.wiring.package;
(&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))" exception
when starting the HelloServlet bundle. I assume this is because my Felix
container isn't registering th http-bundle properly.

How do I get this sort of thing to work in an embedded scenario like this?

FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"org.osgi.service.http; version=4.0.0" ); Iin there and, when that
happened, I was getting a NoClassDefFoundError NamespaceException, assuming
that it was looking for something other than the felix.http.bundle.

I really appreciate any help you guys can give me. Thanks!

E

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message