Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] bootstrapping jetty-plus from eclipse equinox: classloader issue and suggested fix

Hi Jan,
thanks for pointing me to the new packaging.

I have updated the sample project to use jetty-7.0.0.RC5 and identified one trivial bug (bug #289285).

The goal of this experiment is to bootstrap the entire jetty distribution directly from osgi.
This includes starting jetty using the usual xml configuration files.
I am hoping that this will provide a smooth migration to OSGi for traditional j2ee-webapps: they can execute their webapps without any change at all. The configuration of jetty remains also identical.
This also takes full advantage of eclipse-PDE; web-applications are entirely self-contained inside an OSGI-bundle that is developed in the PDE: compile and debug without involving an external build script, a deployment tool and a remote debugger.

Most of the other cases where jetty is embedded in OSGi do not have the issue identified here for these reasons:
- they implement the HttpService of OSGi where they don't use jetty-plus at all: for example equinox's HttpService.
- they place jetty's bundles inside the root-classloader: for example nuxeo.
- they have re-packaged jetty's bundles themselves to make sure that all bundles are able to locate classes directly from each other. For example using Eclipse-BuddyPolicy and similar techniques.

So here is what happen: once all the jetty libraries are loaded by equinox jetty is started like this:
            _server = new Server();
            XmlConfiguration config = new XmlConfiguration(new FileInputStream(
                    System.getProperty("jetty.home") + "/etc/jetty.xml")) {

This fails because org.eclipse.jetty.util's classloader is not able to load classes inside the org.eclipse.jetty.server bundle:
java.lang.ClassNotFoundException: org.eclipse.jetty.server.Server
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(
    at java.lang.ClassLoader.loadClass(
    at org.eclipse.jetty.util.Loader.loadClass(
    at org.eclipse.jetty.xml.XmlConfiguration.nodeClass(
    at org.eclipse.jetty.xml.XmlConfiguration.configure(
    at org.intalio.osgi.jetty.server.JettyBootstrapActivator.start(
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$

org.eclipse.jetty.server depends on org.eclipse.jetty.util but not the other way round;
org.eclipse.jetty.util is in charge of loading org.eclipse.jetty.server.Server but does not import the relevant package and neither does it depend on the bundle.

The workaround I was suggesting was to add headers to the manifest so that the class-resolution happens anyways.
However it is not great. Maybe some extra options to be able to pass the classloader to use to XmlConfiguration ?

My apologies for the long email,
PS I placed some screenshots of the PDE setup:

On Sat, Sep 12, 2009 at 9:41 AM, Hugues Malphettes <hmalphettes@xxxxxxxxxxx> wrote:
Thanks Jan, I am following your advice and will keep you updated.

On Fri, Sep 11, 2009 at 8:12 PM, Jan Bartel <janb@xxxxxxxxxxx> wrote:
> Hugues,
> Will take a look at the demo project to see the issue (thanks
> for providing that, makes things much easier).
> Meanwhile, from the org.mortbay.* packaging, I guess you're using jetty-6.
>  I recommend that you target the jetty-7 releases from eclipse (which are
> under the org.eclipse package) as jetty-7 has
> been refactored to be (even more) componentized.
> Jetty has been used successfully in osgi containers, so I'll be
> interested to see why your use case has a problem. Our goal is to
> make jetty as osgi-friendly as possible, so we're interested in
> feedback to help improve it.
> thanks
> Jan
> Hugues Malphettes wrote:
>> Hi there,
>> I am having difficulties using org.mortbay.jetty,
>> org.mortbay.jetty.util, and org.mortbay.naming
>> together in an osgi container.
>> the issue is that when I start the jetty server and configure it with
>> jetty.xml and jetty-plus.xml from the osgi container, equinox fails.
>> The classloader of the org.mortbay.jetty.server bundle is not able to
>> locate the jetty-plus classes:
>> when jetty tries to load
>>  <Item></Item>
>>  <Item></Item>
>> it fails.
>> The best workaround I am using consists of modifying the manifests of
>> org.mortbay.jetty.server, and
>> org.mortbay.naming to resolve this.
>> I added to org.mortbay.jetty.server:
>>     Eclipse-BuddyPolicy: registered
>> And to the manifests of and org.mortbay.naming:
>>     Eclipse-RegisterBuddy: org.mortbay.jetty.server
>> We could also consider making org.mortbay.jetty.server,
>> and org.mortbay.naming fragments that target
>> org.mortbay.jetty.server. A bit more osgi compliant. But not many osgi
>> container support fragments yet.
>> Here is a small project to reproduce the issue:
>> (licensed
>> under the EPL)
>> The first bundle bootstraps jetty.
>> The second one is a bundle that contains a web-application.
>> It works fine because it depends only on jetty, not jetty-plus.
>> Adding jetty-plus's bundle and using jetty-plus in the config will
>> reproduce the issue described above.
>> Let me know if I am missing something or if there is a different way
>> to install jetty' plus bundles in an osgi container.
>> Cheers,
>> Hugues
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
> --
> Jan Bartel, Webtide LLC | janb@xxxxxxxxxxx |
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx

Back to the top