実行中に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());
}
}
それを解決するための提案/ヒントはありますか?