0

I have a simpe Swing application for drawing different shapes (circle, triangle, square and etc.). It works like that: you have to choose shape type, click somewhere in the apllication window and get the chosen shape drawn where you clicked. And I have to add a functionality that allows to add new shapes (classes) on the runtime via plugin.

Plugin is a file that somehow describes a new shape (class) and its functionality and exists somewhere in the system (in some folder).

My question: what is the best way to implement this? What approaches, libraries and sources can you recommend?

I have found some information about JPF (Java Plug-in Framework), but I'm not sure that this is what I need becaust it looks quite enormous and seems to be used for other purposes (maybe I'm wrong).

Thank you.

Coffemanz
  • 863
  • 2
  • 8
  • 17
  • I would put the custom shape classes in a jar, and implement functionality in your main app to select and load the jar (see URLClassLoader). You can also inspect the classes in the jar using the example given here: https://stackoverflow.com/questions/3429275/listing-classes-in-a-jar-file – ControlAltDel Mar 27 '19 at 17:43
  • You could use ServiceLoader as described in the docs for [Creating Extensible Applications ](https://docs.oracle.com/javase/tutorial/ext/basics/spi.html). – dnault Mar 27 '19 at 19:22

1 Answers1

0

Java can have a feature called reflection API. By using this, you can create objects dynamically at run time. We can call their methods at runtime

  • Yeah, I know about reflection. But what if a plugin not just a java class. Let's say it has some custom format. – Coffemanz Mar 27 '19 at 17:50