制作一个可扩展的java程序

时间:2016-08-02 18:53:21

标签: java jar

我正在创建一个java命令提示符(如Windows CMD)。

但我希望其他开发人员可以通过将自己的 * .jar 文件放在名为“extensions”的文件夹中来为程序添加一些命令。

我知道这是可能的,因为Minecraft可以像MC Forge一样用修改(通过将你的mod罐放在名为“mods”的文件夹中)

示例:

public class myExtension extends Extension {

    //A method called by my program
    @Override
    public void onLoad() {
        //Register a command in the main class...
        Command cmd = Commands.registerCommand("hello");

        //Add an event listener...
        cmd.addEventListener(new CommandEventListener() {
            public void onCommandExecute() {
                //Print "Hello World !" to console when the command is executed...
                Console.getConsole().print("Hello World !");
            }
        });
    }
}

所以现在做这个的人应该能够将这个程序导出为jar文件并将其放在“extensions”文件夹中。但是,如何让我的程序将此jar注册为扩展名?

我知道答案,请写下来!谢谢!

0 个答案:

没有答案