Question

I am having an issue getting Peaberry/Guice/OSGi/Servlets to place nice. To begin, I have been migrating a Jetty-based, WAR deployed webapp over to OSGi to leverage the plugin architecture. My original application was using guice everywhere.

I have broken everything into modules and Maven-iszed the build. Everything seems to be working except for the pesky installation of the ServletModule.

I receive the following exception when I attempt to install a ServletModule:

java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Preconditions
    at com.google.inject.servlet.ServletModule.configure(ServletModule.java:44)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.AbstractModule.install(AbstractModule.java:118)
at com.payplum.CoreActivator$CoreImportModule.configure(CoreActivator.java:145)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.payplum.CoreActivator.start(CoreActivator.java:53)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)

So I'm not quite clear on why it's failing to find these bundles. I have added the guice-servlet dependency and have verified that it is making it into my deployed bundles.

I guess the other piece of importance is registering the GuiceFilter. I use the ServiceTracker to get the ExtHttpService, as I'm using Jetty. When that Tracker returns, I add register it out using the typical call

service.registerFilter( this.guiceFilter, "/*", null, 0, null );

And that seems to work fine. I'm really struggling to get these things working and I'm a little caught in the middle between the Guice/OSGi/Peaberry part. Any help is much appreciated.

Thanks!

Was it helpful?

Solution

The exception means you're missing a class on your classpath, so you're either missing a jar or one of the jars (surprisingly) doesn't include its required classes. Check the JARs that are included in your final war file e.g. using 'jar -tf thejar.jar' on whether they include the $Preconditions class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top