Question

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.

EDIT: e.g.

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.

EDIT 2:

Don't be so harsh on me pls :). Thx for the dynamic class loading tip. I have been looking into that, and it looks promising.

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. I think I'm getting the hang of this, but any tips would be helpful.

e.g.

    package sth.sth;

    import blah.blah.*;

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

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

EDIT: The problem is easily solvable using Java Reflection! I wish someone posted that as an answer befpre blatanty downvoting a question because pf a GitHub link that was there to prpve that I've actually done something.

Was it helpful?

Solution

This kind of thing can be accomplished by using Java Reflection!

How to load and invoke a method on an external jar:

File f = new File("plugin.jar");
URLClassLoader cl = new URLClassLoader(new URL[]{f.toURI().toURL(), null});
Class<?> clazz = cl.loadClass("epicurus.Client");
Method main = clazz.getMethod("main", String[].class);
main.invoke(null, new Object[]{new String[]{}});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top