私があなたを正しく読んでいるなら、あなたはまだサーバー側の OSGi 環境にいて、同じコンテナー (Karaf など) で実行されているサービスを使用する必要があります。アクティベーターを使用すると、コンテキストでそれを取得できます。それを試しましたか?
Bnd アノテーションを使用する別のアプローチでは、宣言型サービスもコンテナーにインストールする必要があります。次に、Bnd アノテーションを使用して、「@Reference」がコンテナーから必要なサービスを取得する、次のようなクラスにアノテーションを付けることができます。
import java.util.Map;
import org.osgi.framework.BundleContext;
import aQute.bnd.annotation.component.Activate;
import aQute.bnd.annotation.component.Component;
import aQute.bnd.annotation.component.Deactivate;
import aQute.bnd.annotation.component.Reference;
//Doesn't have to be called Activator
@Component
public class Activator {
private BundleContext context;
private TheServiceINeed theServiceINeed;
@Activate
public void Activate(BundleContext context, Map<String, Object> props) {
this.context = context;
}
@Deactivate
public void Deactivate() {
this.context = null;
}
public TheServiceINeed getTheServiceINeed() {
return theServiceINeed;
}
//The Service to process my String
@Reference
public void setTheServiceINeed(TheServiceINeed theServiceINeed) {
this.theServiceINeed = theServiceINeed;
}
}
BndToolsを使用して作業を行っていますか? あなたが私に尋ねれば、OSGi開発にはかなり便利です。