首页 > 解决方案 > 在 JADE 中创建代理

问题描述

我无法使用 JADE 创建代理。

我的结构

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

我的档案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());
    }
}

我创建代理的步骤:

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

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

我的类路径

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

输出

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.
--------------------------------------------

我的问题

如果我更改 HelloWorldAgent 中的消息(例如System.out.println("Hello ! My name is "+getLocalName());),则在我运行代理时它不会更新(控制台显示Hello World! My name is fred)。当我在 hello 文件夹中创建一个新类时,我在 GUI 中找不到我的代理。

我错过了什么?

标签: javaagents-jade

解决方案


您没有正确设置类路径。正如“什么是类路径以及如何设置它?”的已接受答案中所述 ,您的类路径可以包含两种条目类型:

因此,类路径包含:

  • JAR 文件,以及
  • 包层次结构顶部的路径。

在您的情况下,您只能参考以下.jar文件:

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

请注意,您的工作路径/Applications/jade/src/examples/hello/不在类路径中。这意味着您的自定义翡翠类不可见/不可访问。

要解决您的问题,您必须添加要在类路径中使用的其他路径。通常你使用目录.来表明你想要在你的类路径中的“当前目录”。

请记住,您jadeExamples.jar的类路径中有 JAR 文件。当您有一个.class文件用于更改的HelloWorldAgent类时,可能不清楚 JVM 正在加载哪个类,是来自 JAR 文件还是.class来自文件系统的文件。不要在你的类路径中两次提供同一个类和同一个包,甚至jadeExamples.jar用一个新的更改过的 JAR 文件来更改文件(这可能会更加混乱)。相反,在您的包/命名空间/目录中创建一个新代理并加载它-agents foobar:your.package.and.ClassName,但要确保类路径设置正确。


推荐阅读