java - 在 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());
}
}
我创建代理的步骤:
/Applications/jade/src/examples/hello $ javac *.java
/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 中找不到我的代理。
我错过了什么?
解决方案
您没有正确设置类路径。正如“什么是类路径以及如何设置它?”的已接受答案中所述 ,您的类路径可以包含两种条目类型:
因此,类路径包含:
- 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
,但要确保类路径设置正确。
推荐阅读
- docker - Docker - 无法在卷内的容器之间共享数据(docker-compose 3)
- javascript - 语义 ui 弹出窗口以显示未正确显示的 div 内容。还需要显示表格行数据
- .net - .net 核心 CORS 设置不会阻止来自 Postman 的调用
- regex - 连续 2 个相同字符串的正则表达式
- laravel - PayPal 被重定向到成功页面,但它没有进行货币交易(并且没有 webhook 或 IPN 通知)
- php - 根据 Woocommerce 中选择的付款方式禁用运输方式
- reactjs - 使用小组件的 React-Native 性能
- r - dplyr ggplot 中的交互式绘图 R plotly
- vagrant-provision - 如何将 PHPadmin 添加到我的 bootstrap.sh 命令?
- angular - 将 rxjs 升级到 6 后,类型“Observable”上不存在属性“地图”