我已经编写了一个普通的Java应用程序,按照这个网站描述的方式调用OSGi bundle的方法:http://drupal.osgibook.org/node/37。
为了获取Equinox环境的上下文,我从应用程序中启动它并从内部安装bundles。此外,上下文被用来检索正在运行的bundle的服务引用并获取其服务。
EquinoxRunner类的runEquinox方法:
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
public BundleContext runEquinox([...]) throws Exception {
[...]
BundleContext bundleContext = EclipseStarter.startup(new String[]{"-console"}, null);
bundleContext.installBundle("file:C:/.../plugins/myosgiclass.interface_1.0.0.201108301327.jar");
Bundle bundleTranslationImpl = bundleContext.installBundle("file:C:/.../plugins/myosgiclass.impl_1.0.0.201108301327.jar");
bundleTranslationImpl.start();
[...]
return bundleContext;
}
同时还需要使用ServiceRunner类的invokeMethod方法:
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
[...]
public Object invokeMethod(BundleContext bundleContext, Object value, [...]){
ServiceReference serviceReference = bundleContext.getServiceReference(MyOSGiClass.class.getName());
Object result = null;
if (serviceReference != null) {
MyOSGiClass myOSGiClass = (MyOSGiClass) bundleContext.getService(serviceReference);
if (myOSGiClass != null) result = myOSGiClass.method(value);
bundleContext.ungetService(serviceReference);
}
return result;
}
现在,在Tomcat上使用eclipse bridge时,我不知道如何检索Equinox环境的正确上下文。当我尝试在带有Equinox的Tomcat上运行它时,会出现NoClassDefFound异常。我将非常感谢任何关于如何解决这个问题的建议。
提前感谢您。 谢谢,Nic
org.eclipse.equinox.servletbridge
项目开始呢? - forty-two