M
M
MaxLich2017-10-19 13:52:47
Java
MaxLich, 2017-10-19 13:52:47

How can I connect plugins to a java application?

Hello. They gave me a test task. You need to write a GUI application with the ability to connect modules (that is, plugins). Moreover, the program should not be restarted when they are connected (everything should be applied immediately). I don't know yet how to implement it.
In addition, I'm also interested in the following. When the plugin is connected, the main form of the program will change, that is, some buttons, fields, and so on will appear. And I still don't know how to do it. There are thoughts of digging towards repaint(), but I'm not sure yet (didn't work with it).

Threat No third-party frameworks can be used, only what is in Java itself.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fat Lorrie, 2017-10-19
@Free_ze

You need to write a GUI application with the ability to connect modules (that is, plugins). Moreover, the program should not be restarted when they are connected (everything should be applied immediately).

Java, by a happy coincidence, can load classes dynamically:
// Где-то там, где реализуется плагин 
class MyClass implements MyPluginInterface {}

// У нас тут, в модульной софтинке
try { 
    Class c = Class.forName("com.vasyapupkin.MyClass"); 
} catch (ClassNotFoundException e) {
    // log error
}

Then, through reflection, you can instantiate your type:
Your softinka should somehow track the appearance of files. In the simplest case - to wait for the appearance of files somewhere along the classpath in order to try to fish out new classes. In the simplest case, classes can be inheritors of GUI components (that is, be able to draw themselves) and you can simply insert their instances into a known container.
Threat You can make your own bike, but such a technology in Java already exists out of the box - JavaBeans , and if you want to bring the teacher to ecstasy, then you should dig in this direction.

I
ivan19631224, 2017-10-19
@ivan19631224

Use reflection .

P
protven, 2017-10-19
@protven

In general, the comrades got a little crazy with such test tasks. Look towards OSGI, we use this technology and, in general, yes, as it was declared, dynamic loading of new code works. But it's all done in one place...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question