問題タブ [serviceloader]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
1 に答える
80 参照

java - 別の JAR で使用するために JAR アプリケーション内からクラスを動的にロードする方法は?

動的に記述およびロードされる拡張機能をサポートする JAR アプリケーション M.jar があります。アプリケーションでは、クラスがインターフェイス E を実装し、NE と呼ばれることが必要です。

今、私がやろうとしていることは次のとおりです。

  1. 拡張 API1 を作成し、M にロードします。
  2. 別の拡張 APIUser を作成し、それを M にロードして、API1 を使用します。

私がここでやろうとしていることについては、下の図を参照してください。

ここに画像の説明を入力

M.jar はカスタム ClassLoader を使用することを知っています。これは、拡張子を AE のみにする必要があるためです。

I tried the ServiceProvider, ServiceProviderInterface method as described here but that did not work. I believe this is because API's classes are not in M's classpath and hence APIUser cannot find it.

I want to know,

  1. If it is feasible to use APIUser's ClassLoader to load API's class and initialize it for use in APIUser.
  2. Is it possible for M to block/isolate API's ClassLoader from any other extensions? I think it can be based off of this answer.
  3. What other means are there to load API's class in APIUser1 or APIUSer2 ... and maintain only one instance of API's class? (i.e singleton)