地铁 +码头 + OSGi = 痛苦
我正在尝试将 Sun 的 HTTPServer 替换为更好的 Jetty 服务器,该服务器位于 OSGi 捆绑包中,在 Equinox 上运行。
我已经尝试过这个:
System.setProperty("com.sun.net.httpserver.HttpServerProvider","org.mortbay.jetty.j2se6.JettyHttpServerProvider");
但是当调用endpoint.publish(url)并且生成服务器时,它会抱怨org.mortbay.jetty.j2se6.JettyHttpServerProvider的ClassNotFoundException。
但是,正确的 jar 位于捆绑包中,并且实际上在 Activator 中我可以实例化 org.mortbay.jetty.j2se6.JettyHttpServerProvider。
我认为这是某种类路径问题 - 生成的服务器可能位于不同的类路径中?我尝试过在 JDK 级别添加 JAR,但这没有任何区别。
任何人都可以阐明到底如何使其发挥作用吗?
PS 也许有一天,可怕的 System.setProperty 调用将从世界上消失。希望:)
I am trying to swap out Sun's HTTPServer for the much better Jetty server, within an OSGi bundle, running on Equinox.
I have tried this:
System.setProperty("com.sun.net.httpserver.HttpServerProvider","org.mortbay.jetty.j2se6.JettyHttpServerProvider");
but when endpoint.publish(url) is called, and the server is spawned, it complains of a ClassNotFoundException for org.mortbay.jetty.j2se6.JettyHttpServerProvider.
However, the correct jars are in the bundle, and indeed in the Activator I can instantiate a org.mortbay.jetty.j2se6.JettyHttpServerProvider.
I think that this is a some kind of classpath issue - the spawned server is in a different classpath maybe? I have tried adding the JARs in at the JDK level, but this doesn't make any difference.
Can oanyone shed any light how on earth to get this working?
P.S. Maybe hideous System.setProperty calls will vanish from the world one day. Hopefully :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Equinox 具有由 Jetty 6.x 支持的 OSGi 标准 HttpService 的实现。只需包含正确的捆绑包即可,您可以相当轻松地在 Equinox 中运行 Jetty。然而,我发现a)Jetty对你来说是完全隐藏的,你看到的只是HttpService接口,b)HttpService接口相当简单。只能添加servlet+mappings和一些静态资源
Equinox has an implementation of the OSGi standard HttpService backed by Jetty 6.x. It just a matter of including the correct bundles and you have Jetty running within Equinox fairly easily. However, I found that a) Jetty is completely hidden from you, all you see is the HttpService interface, and b) the HttpService interface is rather simplistic. You can only add servlets+mappings and some static resources
我似乎无法回复 omerkudat,所以我不得不将回复放在这里...
如果您包含 osgi jar,Metro 似乎不会使用 Jetty。您似乎需要这个:
http://docs.codehaus.org/display/JETTY/J2se6HttpServerSPI< /a>
我手动编译,并按上面设置系统属性,但不成功。
I can't seem to reply to omerkudat, so I've had to put the reply here...
Metro doesn't seem to use Jetty if you include the osgi jar. You seem to need this:
http://docs.codehaus.org/display/JETTY/J2se6HttpServerSPI
Which I manually compiled, and set the System Property as above, unsuccessfylly.
问题是工厂不支持 OSGi,并且加载工厂的类没有引用 Jetty 实现。问题不在于它是否在您的捆绑包中(您似乎已将其合并在一个捆绑包中),而在于工厂方法位于某些核心代码中,并且无法解析 Jetty。
实例化 HttpServer 的调用不是 Java6 API 的一部分,而是 Sun 的内部类之一 - 因此在非 Sun JVM 上运行时此调用将失败。最好了解如何使用 Metro 做其他事情,而不是使用此工厂方法来将类组合在一起。
The problem is that the factory is not OSGi aware, and the class that loads the factory has no reference to the Jetty implementation. It's not whether it's in your bundle (which you seem to have combined in one bundle) but rather that the factory method is in some core code, and that fails to be able to resolve Jetty.
The call to instantiate an HttpServer is not part of the Java6 API, bur rather one of Sun's internal classes - so this call will fail when running on non-Sun JVMs. It would be better to find out how to use Metro to do something other than use this factory method in order to get the class together.