[
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
|
Hugues,
That makes sense. Please do let us know of anything (else) you come across
that may improve jetty and osgi integration.
thanks
Jan
Hugues Malphettes wrote:
I Jan,
I have found a workaround to that issue:
- Have the bundle that bootstraps Jetty depend on all the jetty's bundles.
- When configuring jetty, set the bootstrapper bundle's classloader as
the context class loader.
It has access to all of the jetty's packages and resolves the problem
for the basic jetty.xml file.
Many thanks for your attention.
Cheers,
Hugues
On Sat, Sep 12, 2009 at 3:13 PM, Hugues Malphettes
<hmalphettes@xxxxxxxxxxx <mailto:hmalphettes@xxxxxxxxxxx>> wrote:
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")) {
};
config.configure(_server);
_server.start();
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 java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at
org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:129)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:90)
at
org.eclipse.jetty.xml.XmlConfiguration.nodeClass(XmlConfiguration.java:224)
at
org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:187)
at
org.intalio.osgi.jetty.server.JettyBootstrapActivator.start(JettyBootstrapActivator.java:70)
at
org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:782)
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,
Cheers,
Hugues
PS I placed some screenshots of the PDE setup:
http://github.com/hmalphettes/osgi-webapp-simple/tree/cfe791f2b395930c0de95248b69f3f1bff4aab4c/setup-screenshots
On Sat, Sep 12, 2009 at 9:41 AM, Hugues Malphettes
<hmalphettes@xxxxxxxxxxx <mailto:hmalphettes@xxxxxxxxxxx>> wrote:
Thanks Jan, I am following your advice and will keep you updated.
Hugues
On Fri, Sep 11, 2009 at 8:12 PM, Jan Bartel <janb@xxxxxxxxxxx
<mailto: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, org.mortbay.jetty.plus 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>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
>> <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
>> it fails.
>>
>> The best workaround I am using consists of modifying the
manifests of
>> org.mortbay.jetty.server, org.mortbay.jetty.plus and
>> org.mortbay.naming to resolve this.
>> I added to org.mortbay.jetty.server:
>> Eclipse-BuddyPolicy: registered
>> And to the manifests of org.mortbay.jetty.plus and
org.mortbay.naming:
>> Eclipse-RegisterBuddy: org.mortbay.jetty.server
>>
>> We could also consider making org.mortbay.jetty.server,
>> org.mortbay.jetty.plus 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:
>> http://github.com/hmalphettes/osgi-webapp-simple/tree/master
(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 <mailto:jetty-users@xxxxxxxxxxx>
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
> --
> Jan Bartel, Webtide LLC | janb@xxxxxxxxxxx
<mailto:janb@xxxxxxxxxxx> | http://www.webtide.com
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx <mailto:jetty-users@xxxxxxxxxxx>
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
------------------------------------------------------------------------
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users
--
Jan Bartel, Webtide LLC | janb@xxxxxxxxxxx | http://www.webtide.com