0

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 Main-Container@192.168.1.104 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?

ghosttie
  • 588
  • 2
  • 8
  • 18
Nelly Barret
  • 144
  • 1
  • 17
  • Please check https://stackoverflow.com/questions/2396493/what-is-a-classpath-and-how-do-i-set-it for valid classpath settings you can use. You do not add individual `.class` files to the classpath, but instead directory paths to the root package hierarchies you are using. In your case it might be `/Applications/jade/src/`. – Progman Sep 20 '19 at 16:50
  • @Progman thanks for the link, I have modified my classpath with what you said but it seems not to work – Nelly Barret Sep 20 '19 at 17:10
  • Please [edit] your question to include the content of the directories you have (not sure if the command `find .` is available on your system), the files you have in the directory, how you start the application and the current classpath setting you are using. Depending on your system you might need to reboot your system or start a new terminal when you change environment variables. Also try to use the `-cp` parameter. Include the full complete error message you get from java. – Progman Sep 20 '19 at 17:40
  • Please [edit] your question to include a detailed, complete listing of all the directories you are using, the sub directories you have in them, the files each directory have, the content of the `.java` files, the statements you used to compile the `.java` files into `.class` files, the location where you executed the `javac` application, the current content of your CLASSPATH, the complete statement on how you started the jade application and the full complete error message you get. – Progman Sep 21 '19 at 15:32
  • You have a file called "HelloWorldAgent.java" but it contains a class called `AgentHello`. You cannot compile such a class, you will get an error message. How did you compiled the class? Also, you try to use the package "examples.hello", but the source code of your "HelloWorldAgent.java" file does not contain a `package` line to place it in that package. Why is the "package" line missing or shouldn't it be in a package at all? Also, you have the "jadeExamples.jar" file inside your CLASSPATH, which will most likely result in naming conflicts with your "examples.hello" package. – Progman Sep 21 '19 at 15:51
  • You might want to look at https://docs.oracle.com/javase/tutorial/java/package/index.html for an introduction about packages in java. – Progman Sep 21 '19 at 15:53
  • I have edited the post, I forgot the line of the package (but it's really in my code on my machine), and I have miss-typed the name of the class but in my code it's okay too. I will take a look at the package documentation, for the moment I'm trying some solutions but I don't really know how packages are working. Thanks a lot for your help, I will continue to search solutions for my problem, I don't want to waste your time ! – Nelly Barret Sep 21 '19 at 15:57
  • 1
    You should remove the "jadeExamples.jar" file from your CLASSPATH (if you don't need them) and/or move your agent to a different package, so there is no confusion for the JVM which class to load (it looks like it always use the `HelloWorldAgent` agent from the JAR file). – Progman Sep 21 '19 at 15:59
  • IT WORKS ! I have created a new folder in the src folder. You're right about the fact that JVM seems to use HelloWorldAgent. THANK YOU VERY MUCH for all the time and explanations. – Nelly Barret Sep 21 '19 at 16:04

1 Answers1

1

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 .

Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
Progman
  • 16,827
  • 6
  • 33
  • 48
  • Thanks a lot for you detailed answer ! I have added `/Applications/jade/src/examples/hello/` to my classpath (and of course restarted my computer) but it doesn't work either. – Nelly Barret Sep 21 '19 at 15:11
  • @NellyBarret If you have a package `examples.hello` then you shouldn't add `/Applications/jade/src/examples/hello/` to your classpath but instead the directory `/Applications/jade/src/` as that will be the "root" of your package hierarchy. – Progman Sep 21 '19 at 15:14
  • I have modified my classpath with `/Applications/jade/src` but it doesn't work either :( – Nelly Barret Sep 21 '19 at 15:29