1

実行中にJARモジュールを登録するモジュラーアプリケーションが必要です。そのために、NetbeansLookupAPIを使用しています。

問題は、実行中のインスタンスがJARファイルを認識しないため、JARファイルをライブラリフォルダーに直接コピーできないことです。META-INF.servicesモジュールでは、インターフェイスのパッケージ名とモジュールパッケージ名を使用してを構成しました。

これが私のコードの例です:

while(true){  
    Lookup lkp;
    Collection<TestInterface> tests = null;
    Template tmpl;
    final Lookup.Result rslt;

    lkp= Lookup.getDefault();
    //lkp=Lookups.forPath("modules-path");
    tmpl= new Template(TestInterface.class);
    rslt= lkp.lookup(testTemplate);
    tests = rslt.allItems();

    Lookup.getDefault().lookup(TestInterface.class);
        rslt.addLookupListener(new LookupListener() {
            @Override
            public void resultChanged(LookupEvent le) {
                reaction(rslt);
            }
        });

        reaction(rslt);
    }
}

private static void reaction(Lookup.Result r) {
    for (Iterator i = r.allInstances().iterator(); i.hasNext();) {
        TestInterface s = (TestInterface) i.next();
        System.out.println(s.somemethod());
    }
}

それを解決するための提案/ヒントはありますか?

4

1 に答える 1

1

Netbeans Lookup の代わりに、OSGi を目的に使用できます。明らかに、ロードする必要がある jar ファイルを制御できるので、問題なく動作するはずです。

OSGi バンドルを取得するには、jar 構成を変更する必要があります。これを行うには、ここで説明されているように、MANIFEST.MF ファイルを変更する必要があります。

http://www.vogella.de/articles/OSGi/article.html#osgiarch_manifest http://www.javaworld.com/javaworld/jw-03-2008/jw-03-osgi1.html?page=2

次に、ここで説明するように、マニフェストで定義した BundleActivator を使用して jar ファイルをアクティブ化できます。

http://www.vogella.de/articles/OSGi/article.html#codebundle

次に、バンドルをサービスとして公開し、アプリケーションで使用できます。

http://www.eclipsezone.com/eclipse/forums/t90796.html

于 2012-04-03T10:01:15.637 に答える