[Jersey] Re: Live registration of resources

From: Jakub Podlesak <>
Date: Wed, 06 Apr 2011 18:54:04 +0200

Hi Alexandre,

Please see attached for a quickly hacked example,
which uses OSGi Event Admin API to signal there
is a new resource class to be added into the already
running Jersey web application bundle.

The web application in helloworld-osgi-webapp-1.4/war-bundle
is based on the Jersey osgi web bundle example and is enriched,
so that it responds the incoming events requesting new resources
to be added to the running application.

The osgi-single-resource-bundle is an example of a new resource
provider bundle, which emits a "resource added" event once started.

The most important classes are in the web bundle: ReloadServletContainer
and WebAppContextListener.



On 04/06/2011 06:25 PM, Pavel Bucek wrote:
> Hello,
> Jersey creates optimized resource model at startup, but you can force
> "re-creating" almost everything - see ScaningResourceConfig.onReload().
> So, what you probably want to do is extend ScanningResourceConfig and
> implement your own scanner (which you already have, you just need to
> implement that interface and report found resources to
> ScannerListener, see FileScanner class). When you have this in place,
> just call onReload whenever change is detected and jersey will take
> care of reloading/rebuilding inner resource model.
> Le me know whether you need some additional info (I can create sample
> or something which could help you).
> Regards,
> Pavel
> On 04/06/2011 04:35 PM, Alexandre Borgoltz wrote:
>> Hi,
>> I am trying to use jersey as embedded in an OSGi engine (in an
>> Eclipse RCP application with jetty embedded actually).
>> I have developped a nice way to contribute REST resources to an
>> application via eclipse's extension mecanism.
>> Everything works fine except for one thing: resources registration.
>> The default behaviour is an automatic scan of WEB-INF/lib and
>> classes. I have written my own "Application" that replaces the scan
>> of the classpath by a scan of eclipse registry : works fine.
>> BUT it is a good practise in an OSGi environment to track registry
>> changes, instead of reading it once. I could do that cleanly, being
>> notified everytime a new REST resource is contributing - but I
>> haven't found the way to register these resources programmatically
>> once the jersey engine launched.
>> Can Jersey add resources /live/ ? Or is it a limitation that you must
>> know the list of classes or singletons before it starts up?
>> I thank you in advance for your help!
>> --
>> Alexandre