I am attempting to make a game using java, and I need a plugin system for the server…
How might I make it so that there is a folder named plugins that the users can simply drop jar files in there and I can call functions within those jar files all at once?
This is implying that a community would make plugins that I don’t know about (so i need to have it run all plugins even if I don’t know the plugins name)
(I would appreciate it if I didn’t need to use someone else’s framework like jspf)
Writing your own plug-in infrastructure is fun, but totally unneccesary. It’s a solved problem and you’re not going to write a higher quality one than one that already exists and is proven in the field. I’d say choose your battles.
I’ve tried out JSPF before and found it incredibly easy to use. And this coming from someone who has done exactly what you’re trying to do: I’ve made my own plug-in infrastructure (for basically the same purpose: to load mini-games dynamically) from scratch, writing the classloading and framework myself. And if I were to do it again, I would use a framework like JSPF without hesitation.
To load all classes from jars in a directory that adhere to a certain interface (say
Game), it’s as easy as:IIRC the only requirement on implementers of
Gameis that it be tagged with the@PluginImplementationannotation.Edit
And then: