Java代理开发框架 - Eclipse和Maven集成 [英] Java Agent Development Framework - Eclipse and Maven integration

查看:238
本文介绍了Java代理开发框架 - Eclipse和Maven集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用 JADE 框架作为依赖关系的maven项目,但是该框架需要不同的命令才能执行jar普通的java应用程序。

I created a maven project with JADE framework as a dependency but this framework requires different commands to execute the jar than ordinary java applications.

构建:

javac –classpath <JADE-classes> Class_name.java

运行:

java –classpath <JADE-classes> jade.Boot <agent-local-name>:<fully-qualified-agent-class>

其中< full-qualified-agent-class> package_name.Class_name

java –cp lib\jade.jar jade.Boot [options] [AgentSpecifierlist]






可以使用maven插件构建一个 runnable jar ,所以我只需输入 java -jar myjar.jar 而不是上面的命令?


Is it possible to build a runnable jar using maven plugins so I just type java -jar myjar.jar instead of the command above?

mvn eclipse:eclipse 命令在编辑 pom.xml 文件后更改eclipse项目的构建参数?

Would mvn eclipse:eclipse command change build parameters of the eclipse project after editing the pom.xml file?

推荐答案

没有任何这样的插件可用于JADE,因为它不是广泛使用的框架,任何人都没有打扰开发一个插件。但是有一种解决方法来以常规方式运行它,但是只有当您已经知道您的< full-qualified-agent-class> 名称时,这才有效。你可以做的是编写一个扩展 Thread 的类,并从线程运行()方法通过传递< fully-qualified-agent-class> 作为参数来调用JADE框架代理。请参阅下面的示例。

There isn't any such plugin available for JADE because it is not widely used framework and anyone hasn't bothered to develop a plugin for it. But there is a workaround to run it the conventional way, but this would only work if you already know your <fully-qualified-agent-class> names. what you can do is write a class that extends Thread and from that Thread's run() method invoke the JADE framework agent by passing the <fully-qualified-agent-class> as arguments. Refer to an example below.

jadeBootThread.java

public class jadeBootThread extends Thread {

private final String jadeBoot_CLASS_NAME = "jade.Boot";

private final String MAIN_METHOD_NAME = "main";

//add the <agent-local-name>:<fully-qualified-agent-class> name here;
// you can add more than one by semicolon separated values.
private final String ACTOR_NAMES_args = "Agent1:com.myagents.agent1";

private final String GUI_args = "-gui";

private final Class<?> secondClass;

private final Method main;

private final String[] params;

public jadeBootThread() throws ClassNotFoundException, SecurityException, NoSuchMethodException {
    secondClass = Class.forName(jadeBoot_CLASS_NAME);
    main = secondClass.getMethod(MAIN_METHOD_NAME, String[].class);
    params = new String[]{GUI_args, ACTOR_NAMES_args};
}

@Override
public void run() {
    try {
        main.invoke(null, new Object[]{params});
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
       ex.printStacktrace();
    }

}
}

现在你可以通过使用eclipse插件等创建runnable jar文件,从主方法或任何其他方式调用此线程。

Now you can invoke this thread from your main method or any other way by creating runnable jar file with eclipse plugin etc.

这篇关于Java代理开发框架 - Eclipse和Maven集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆