Search code examples
javaeclipsemavenagents-jade

Java Agent Development Framework - Eclipse and Maven integration


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.

Build:

javac –classpath <JADE-classes> Class_name.java

Run:

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

Where <fully-qualified-agent-class> is package_name.Class_name

or

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

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

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


Solution

  • 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();
        }
    
    }
    }
    

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