1

Is there a way to implement plugins in a Java application that is uncomplicated, can be started up when required and is well documented?

What I am looking for is something similar to OSGI, JPF and JSPF. However, OSGI is complicated, JPF isn't well documented and JSPF does not allow you to start up a plugin only when you need it.

For example, there is a plugins folder. Anyone can create a plugin by implementing an interface I supply. After the plugin is created, anyone who wants to use it can simply put it into the plugins folder of my application and the application will load it.

Or maybe, a better word for this is "Add-on".

There are some similar questions to my question, but I would like to know more. These questions have vague answers.

http://stackoverflow.com/questions/2369499/how-to-make-java-plugins?rq=1 http://stackoverflow.com/questions/7587318/how-can-i-write-my-own-plugin-in-java 

If you have no idea, please tell me how to use JPF for my applications. Thanks a lot for taking your time to reading this.

EDIT: I have resolved my problem. I'm using JSPF now - it works very well for my purposes. Thank you to everyone who has tried to help and I apologize for not creating a "real question".

3
  • 1
    Plugin for NetBeans, Eclipse or what? You must specify what you're trying to do. Commented Jul 15, 2012 at 7:07
  • Reclarified. Thanks for telling me. Commented Jul 15, 2012 at 7:10
  • "It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical"... to me (and obviously others) it's perfectly clear and precise, would probably have had other interesting answers had it not been closed. A shame. Is there a bonus for closing questions? Commented Jul 7, 2014 at 18:28

3 Answers 3

5

If you start a ClassLoader for your Jar you can load or unload code at any time.

http://viralpatel.net/blogs/java-dynamic-class-loading-java-reflection-api/

http://www.javalobby.org/java/forums/t18345.html

http://zeroturnaround.com/blog/reloading-objects-classes-classloaders/

Sign up to request clarification or add additional context in comments.

3 Comments

Yup, that's what I want. I'll take a look at your links and try to code something up. Thanks. However, just a note - it seems that I have to specify the class directly, which I cannot do, or else how would it detect other plugins?
When you make a JAR executable, you add the name of the class to the Manifest file. You could have a file which has the class name. Before you have loaded a class you have to get its name some how.
You can just go by convention: Jar file name equals package name equals class name (or similar scheme).
2

Yes you can implement them. Just for semantics sake, plugins in java are called libraries (this should make it easier for you to search on google). Normally libraries in java when built show up as .jar file

Here are some links to help you:

http://www.digilife.be/quickreferences/PT/Build%20your%20own%20Java%20library.pdf https://stackoverflow.com/questions/3612567/how-to-create-my-own-java-libraryapi 

Reply to the edit and to the comment to this post:

Then you should read this: How to design extensible software (plugin architecture)?

2 Comments

Nope, that is not what I mean. I mean something like: I have a plugins folder. I can put in plugins from any source and the program will run them on a specific event. Meanwhile, thank you for taking your time to write this.
The link you posted has good answers, but they're a bit complicated for a Java newbie like me. Thanks a lot.
1

This tutorial shows you how you can easily implemented plugin approach for your application but this requires you app to be Eclipse RCP powered. You will find everything you need including "plugin directory" where then will be loaded from on demand. RCP is not the only one of OSGI implementation there're others but I'd suggest you to use it because of wider community support.

I see a lot of updates to your question since the moment I started to write the answer. Seems to me you shouldn't be afraid to get deep into on of framework suggested and please choose one that looks to you complicated but proven rather than getting stacked or reinvent the bike just because you are new-joiner.

1 Comment

Thank you for your encouragement. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.