0

I have a simple maven project with the Code below.

import jade.core.Agent;
public class HelloAgent extends Agent 
{ 
    protected void setup() 
    { 
        System.out.println(getLocalName()); 
    }
}

How do I run this program?. When i right click to run it, I dont see a run as Java Application. I am following the tutorial here

http://www.iro.umontreal.ca/~vaucher/Agents/Jade/primer2.html

% javac HelloAgent.java 
% java jade.Boot fred:HelloAgent

Output

fred
DwB
  • 37,124
  • 11
  • 56
  • 82
Krishna Kalyan
  • 1,672
  • 2
  • 20
  • 43
  • A runnable java class needs a method with the signature ``public static void main(String[])``. – f1sh Feb 03 '16 at 16:12

2 Answers2

0

You should add main method like this:

   public class HelloAgent extends Agent 
   { 
     public static void main (String[] args) 
     {
          HelloAgent helloAgent = new HelloAgent();
          helloAgent.setup();
     }

     protected void setup() 
     { 
          System.out.println(getLocalName()); 
     }
   }

To run class java as Java Application you needs a method with main like above.

Abdelhak
  • 8,299
  • 4
  • 22
  • 36
  • I get that. Can i run this without a main method? – Krishna Kalyan Feb 03 '16 at 16:22
  • I've not used JADE so does this work for JADE? If so it would me my preference. The other post for this is much larger: http://stackoverflow.com/questions/27620218/java-agent-development-framework-eclipse-and-maven-integration – Michael Lloyd Lee mlk Feb 03 '16 at 16:57
  • This code is incorrect, you can't create an agent, without an agent platform what allows agents to stablish communication in an appropiated way, this is all done by jade.boot. I suggest follow the link posted by @mlk – kato2 Feb 03 '17 at 12:55
0

You need to set maven up to have a run task that executes jade.Boot. You have a few different ways to do this. Here is a complete example for Jade using 'profiles'.

For your example above, it would look somewhat like:

    <profile>
      <id>jade-fred</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
              <mainClass>jade.Boot</mainClass>
              <arguments>
                <argument>fred:HelloAgent</argument>
              </arguments>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

and would be executed with:

mvn -Pjade-fred exec:java
Michael Lloyd Lee mlk
  • 14,561
  • 3
  • 44
  • 81