Jade jar in java + code

2.1k views Asked by At

I am a beginner in JADE programming and I'm having problems running the JADE code in Java. Can someone help me in this??

I am using eclipse and I've added the jade jars, but when I try to run the JADE code it's not working.

import jade.core.Agent;

  public class HelloAgent extends Agent 
  { 
      protected void setup() 
      { 
          System.out.println("Hello World. ");
          System.out.println("My name is "+ getLocalName()); 
      }
  }
2

There are 2 answers

0
Purushottam On BEST ANSWER
  1. Check whether you have the right version: JADE 4.0+ supports getLocalName(); command
  2. The code looks fine, you can have problem with Eclipse interfacing, check that.
  3. Anyways, you can manually (and recommended) to compile and execute to test:

    java jade.Boot -agents Agent1:HelloAgent // to exexute

If this doesn't work then there is a problem with JADE installation

0
daniel kullmann On

If you want to start JADE agents from Java code, this piece of code can give you an idea of how it's done:

jade.core.Runtime runtime = jade.core.Runtime.instance();
Profile profile = new ProfileImpl();
// profile.setParameter( ... );
AgentContainer container = runtime.createMainContainer( profile );
Agent agent = new HelloAgent();
// agent.addBehaviour( ... );
AgentController ac = container.acceptNewAgent( "hello-agent", agent);
ac.start();