Java WebアプリケーションからOSGiバンドルのメソッドを呼び出そうとしています。どちらもTomcat 7で実行することになっています。
このサイト(http://drupal.osgibook.org/node/37)で説明されているように、OSGiバンドルからメソッドを呼び出す通常のJavaアプリケーションをすでに作成しました。
Equinox環境のコンテキストを取得するために、アプリケーションから起動し、バンドルを内部からインストールしました。さらに、コンテキストは、実行中のバンドルのサービス参照を取得し、そのサービスを取得するために使用されました。
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;
}
今、Eclipseブリッジを使用するTomcatでは、Equinox環境の正しいコンテキストを取得する方法がわかりません。Equinoxを使用してTomcatで実行しようとすると、NoClassDefFound例外が発生します。この問題を解決する方法についてのアドバイスをいただければ幸いです。
よろしくお願いします。乾杯、ニック
このようなOSGiフレームワークを組み込み、外部環境からOSGiサービスにアクセスする場合、サービスインターフェースがOSGiの内部と外部で同じであることを確認する必要があります。
そのため、サービスインターフェースのパッケージをTomcatからOSGiにエクスポートするようにOSGiコンテナーを構成します。これを実現するには、 'FRAMEWORK_SYSTEMPACKAGES_EXTRA'プロパティを使用してOSGiフレームワークを構成します。
http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html#ApacheFelixFrameworkLaunchingandEmbedding-hostservicesの詳細(Apache Felixの場合でも、埋め込みAPIは標準化されています)。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加