Implementing dynamic plugins in Java

后端 未结 5 1826
心在旅途
心在旅途 2021-01-31 10:45

I\'d like to implement a dynamic plugin feature in a Java application. Ideally:

  • The application would define an interface Plugin with a method like
5条回答
  •  既然无缘
    2021-01-31 11:20

    Apologize if you know this, but check out the forName method of Class. It is used at least in JDBC to dynamically load the DBMS-specific driver classes runtime by class name.

    Then I guess it would not be difficult to enumerate all class/jar files in a directory, load each of them, and define an interface for a static method getCapabilities() (or any name you choose) that returns their capabilities/description in whatever terms and format that makes sense for your system.

提交回复
热议问题