Вопрос

I am making a program for computer surveillance at the moment. It's for a competition in my country Croatia(InfoKup). I have several options for sending command to another PC, but I want to make the possibility for the command extension for people who know Java. So I want to make the user be able to add some of his custom commands for the program. For example something like Minecraft mods. I know it is possible, but how would I go about doing that.

Any help would be greatly appreciated. My code on GitHub:GitHub Don't mind the stream thing.
It's something my friend is experimenting with.

Currently I have the possibility to send popups to another PC. What if the extension maker knew the code to send cmd commands and wants to add that function. He makes an extension and puts it in the extension folder. Voila we have a new possibility.

Basically what I want to have possible is the user to drop the "mod/extension/whatever" in the "mod/extension/whatever" folder, and the program would load it and put all of the buttons declared in the class in to the GUI, and with them the function.

e.g.

    package sth.sth;

    import blah.blah.*;

    public class ClassSTH extends SchoolarButton{
     public ClassSTH(String params){
      super(params);
     }

     @Override
     public void OnClick(){
      doStuff();
     }
    }

This is a duplicate of a deleted question. (I deleted it). It was closed but now I improved it.

Это было полезно?

Решение

As on your request I'll post something about my little plugin framework. As I continue on the result of a university lab just for fun, there are currently some changes to expect. It supports some basic injection mechanism and code manipulation using javassist byte manipulation framework. I currently use this plugin-framework to learn and test class-loading behaviors (delegation-loading, usage of strategies to load classes, manipulate singletons to weak-singletons, ...). Next, I want to adventure into unloading of enums as they currently produce memory-leaks.

The plugin-mechanism is based on a simple interface IPlugin found in PluginFramework/PluginInterfacewhich only defines a single execute() method. Implementations of the interface can either be placed directly into the plugin-subdirectory of the base-directory or within a jar (preferred one) which has to be placed also into the plugin-subdirectory. The plugin is loaded automatically on startup of the application or on drag&dropping the jar into the plugin-directory, or on using a simplified OSGi-like load command.

The framework itself provides a couple of actions, like list which lists all currently loaded plugins, exec which executes a certain plugin, load and unload which hopefully are self explanatory. For test-reasons there is also a gc command to somehow force a garbage-collection (as I'm taking heapdumps to identify possible memory leaks).

Moreover, you can define a class to export or classes the plugin depends on within the MANIFEST.MF of a plugin-jar. It will only load the plugin if all dependent classes got loaded before (though it shows up in the list of available plugins if not all classes are available and the plugin therefore waits for the dependent classes). Exported classes can be further used by other plugins which require them (as described above).

What the plugin actually does, is left to the programmer of the plugin-implementation. So no security-policies yet installed. So, it is not as complex as the accepted answer of your linked post. Moreover, I'm still in a re-work (that's why I linked the unstable branch). Though, due to limited time it is not yet perfect and I'm not sure if it is already ready to be used safely within other projects - but maybe you find something you can re-use or at least find some ideas.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top