Create an agent in JADE

I’m having trouble creating an agent with JADE.

My structure

/
  Applications
    jade
      lib
        jade.jar
        jadeExamples.jar
      src
        examples
          hello
            HelloWorldAgent.class
            HelloWorldAgent.java

My file HelloWorldAgent.java

package examples.hello;

import jade.core.Agent;

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

The steps I follow to create an agent :

  1. /Applications/jade/src/examples/hello $ javac *.java

  2. /Applications/jade/src/examples/hello $ java jade.Boot -gui -agents fred:examples.hello.HelloWorldAgent

Myclasspath

/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home:/Applications/jade/lib/jade.jar:/Applications/jade/lib/jadeExamples.jar:/Applications/jade/src/

The output

Sep 21, 2019 5:28:05 PM jade.core.Runtime beginContainer
INFO: ----------------------------------
    This is JADE 4.5.0 - revision 6825 of 23-05-2017 10:06:04
    downloaded in Open Source, under LGPL restrictions,
    at http://jade.tilab.com/
----------------------------------------
Sep 21, 2019 5:28:05 PM jade.imtp.leap.LEAPIMTPManager initialize
INFO: Listening for intra-platform commands on address:
- jicp://192.168.1.104:1099

Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.management.AgentManagement initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.messaging.Messaging initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.resource.ResourceManagement initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.mobility.AgentMobility initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.event.Notification initialized
Sep 21, 2019 5:28:11 PM jade.mtp.http.HTTPServer <init>
INFO: HTTP-MTP Using XML parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Sep 21, 2019 5:28:11 PM jade.core.messaging.MessagingService boot
INFO: MTP addresses:
http://192.168.1.104:7778/acc
Hello World! My name is fred
Sep 21, 2019 5:28:11 PM jade.core.AgentContainerImpl joinPlatform
INFO: --------------------------------------
Agent container [email protected] is ready.
--------------------------------------------

My problem

If I change the message in the HelloWorldAgent (e.g. System.out.println("Hello ! My name is "+getLocalName());), it doesn’t update when I run my agent (the console says Hello World! My name is fred). And when I create a new class in the hello folder, I can’t find my agent in the GUI.

What have I missed?

Answer

You have not set the classpath correctly. As mentioned in the accepted answer to ‘What is a classpath and how do I set it?’, your classpath can contain two entry types:

So, classpaths contain:

  • JAR files, and
  • Paths to the top of package hierarchies.

In your case you have reference ONLY the following .jar files :

  • /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
  • /Applications/jade/lib/jade.jar
  • /Applications/jade/lib/jadeExamples.jar

Notice that your working path /Applications/jade/src/examples/hello/ is not in the classpath. This means that your custom jade classes are not visible/accessable.

To solve your problem you have to add the additional paths you want to use in your classpaths. Usually you use the directory . to indicate that you want the “current directory” in your classpath.

Keep in mind that you have the JAR file jadeExamples.jar in your classpath. When you have a .class file for your changed HelloWorldAgent class it might not be clear which class the JVM is loading, the one from the JAR file or the .class file from the file system. Do not provide the same class with the same package in your classpath twice or even change the jadeExamples.jar file with a new changed JAR file (this might be even more confusing). Instead, create a new agent in YOUR package/namespace/directory and load it -agents foobar:your.package.and.ClassName, but ensure that the classpath is set correctly .

Leave a Reply

Your email address will not be published. Required fields are marked *