Answer the question
In order to leave comments, you need to log in
How to create a simple pluggable Java + Maven application?
I decided to make my Java desktop application expandable with plugins. The essence of loading plugins is as follows: the application searches in a certain directory for the jar file of the plugin and its descriptor describing the name, version, main class, etc., using the URLClassLoader, this plugin is loaded into the application. At the same time, the plugin and the application must have an API connected, which is used for interaction between the plugin and the application.
I implemented it and started testing. At the same time, the application, the plugin to it, the API use the Maven
API to connect to the application and the plugin in this way:
<dependency>
<groupId>название</groupId>
<artifactId>название api</artifactId>
<version>версия api</version>
<scope>system</scope>
<systemPath>${basedir}/api.jar</systemPath>
</dependency>
loader = new URLClassLoader(new URL[] {info.getPluginJar().toURI().toURL()}, ClassLoader.getSystemClassLoader());
plugin = (Plugin) loader.loadClass(info.getMainClass()).newInstance();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question