Java java.lang.ClassNotFoundException:jade.core.migration.InterPlatformMobilityService

cyb*_*101 5 java maven

I\xe2\x80\x99m 尝试解析java.lang.ClassNotFoundException:jade.core.migration.InterPlatformMobilityService,当我为 \xe2\x80\x9cInter\xe2\x80\x9d 平台移动性安装添加包时,该问题发生在JADE(Java 代理开发框架)中,其中有一个名为 \xe2 的 JAR \x80\x9cmigration.jar\xe2\x80\x9d 其中包含InterPlatformMobilityService类。我需要这个额外的 JAR,以便在不同的计算机之间发送代理(代码和数据)。

\n

这是我的输出,显示了错误:

\n
INFO: Service jade.core.mobility.AgentMobility initialized\nSep 03, 2021 3:38:48 PM jade.core.AgentContainerImpl initAdditionalServices\nWARNING: Exception initializing service jade.core.migration.InterPlatformMobilityService\njade.core.ServiceException: An error occurred during service activation - Caused by:  jade.core.migration.InterPlatformMobilityService\n        at jade.core.AgentContainerImpl.startService(AgentContainerImpl.java:1169)\n        at jade.core.AgentContainerImpl.initAdditionalServices(AgentContainerImpl.java:450)\n        at jade.core.AgentContainerImpl.startNode(AgentContainerImpl.java:389)\n        at jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:502)\n        at jade.core.Runtime.createMainContainer(Runtime.java:159)\n        at abc.def.hgi.Setup.start(Setup.java:47)\n        at abc.def.hgi.App.main(App.java:51)\nNested Exception:\njava.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService\n        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)\n        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)\n        at java.lang.Class.forName0(Native Method)\n        at java.lang.Class.forName(Class.java:264)\n        at jade.core.AgentContainerImpl.startService(AgentContainerImpl.java:1153)\n        at jade.core.AgentContainerImpl.initAdditionalServices(AgentContainerImpl.java:450)\n        at jade.core.AgentContainerImpl.startNode(AgentContainerImpl.java:389)\n        at jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:502)\n        at jade.core.Runtime.createMainContainer(Runtime.java:159)\n        at abc.def.hgi.Setup.start(Setup.java:47)\n        at abc.def.hgi.App.main(App.java:51)\n
Run Code Online (Sandbox Code Playgroud)\n

我的代码是纯 Java 并通过 Maven 构建,这是我的 pom

\n
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\n      <modelVersion>4.0.0</modelVersion>\n      <groupId>abc.def.ghi</groupId>\n      <artifactId>my_edge_ai</artifactId>\n      <packaging>jar</packaging>\n      <version>1.0-SNAPSHOT</version>\n      <name>my_edge_ai</name>\n      <url>http://maven.apache.org</url>\n     <properties>\n            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n        </properties>\n        <repositories>\n            <repository> \n                <id>tilab</id> \n                <url>https://jade.tilab.com/maven/</url> \n            </repository>\n                <repository>\n                    <id>jade-ipms</id>\n                    <url>file:${basedir}/add-ons/ipms/lib/migration.jar</url>\n                </repository>\n                <repository>\n                    <id>jade-ipms-harcoded</id>\n                    <url></url>\n                </repository>\n        </repositories>\n        <dependencies>\n            <dependency>  \n                <groupId>com.tilab.jade</groupId> \n                <artifactId>jade</artifactId> \n                <version>4.5.0</version>  \n            </dependency>\n            <dependency>  \n                <groupId>com.tilab.jade</groupId> \n                <artifactId>jade-misc</artifactId> \n                <version>2.8.0</version>  \n            </dependency>\n            <dependency>  \n                <groupId>com.tilab.jade</groupId> \n                <artifactId>jade-test-suite</artifactId> \n                <version>1.13.0</version>  \n            </dependency>\n            <dependency>  \n                <groupId>com.tilab.jade</groupId> \n                <artifactId>jade-wsdc</artifactId> \n                <version>2.7.0</version>  \n            </dependency>\n    \n            <dependency>  \n                <groupId>com.tilab.jade</groupId> \n                <artifactId>jade-xml-codec</artifactId> \n                <version>1.11.0</version>  \n            </dependency>\n        </dependencies>\n        <build>\n            <plugins>\n                <plugin>\n                    <artifactId>maven-dependency-plugin</artifactId>\n                    <version>3.1.1</version>\n                </plugin>\n    <plugin>\n        <groupId>org.apache.maven.plugins</groupId>\n        <artifactId>maven-dependency-plugin</artifactId>\n        <executions>\n            <execution>\n                <id>copy-dependencies</id>\n                <phase>prepare-package</phase>\n                <goals>\n                    <goal>copy-dependencies</goal>\n                </goals>\n                <configuration>\n                    <outputDirectory>\n                        ${project.build.directory}/libs\n                    </outputDirectory>\n                </configuration>\n            </execution>\n        </executions>\n    </plugin>\n    <plugin>\n        <groupId>org.apache.maven.plugins</groupId>\n        <artifactId>maven-jar-plugin</artifactId>\n        <configuration>\n            <archive>\n                <manifest>\n                    <addClasspath>true</addClasspath>\n                    <classpathPrefix>libs/</classpathPrefix>\n                    <mainClass>\n                        abc.def.ghi.App\n                    </mainClass>\n                </manifest>\n            </archive>\n        </configuration>\n    </plugin>\n            </plugins>\n        </build>\n    </project>\n
Run Code Online (Sandbox Code Playgroud)\n

根据 JADE\xe2\x80\x99s ipms (InterPlatformMobilityService) 下载指南,我在我的<my_path>/jade/<extract_here>下提取了 \xe2\x80\x9cipmsAddOn-1.5.zp\xe2\x80\x9d ,同一级别<my_path>/jade/lib所在的位置 ,请参阅 \xe2\x80\x9cipms\xe2\x80\x9d 自述文件:\n https://jade.tilab.com/doc/tutorials/ipms/README

\n

最后,我通过 \xe2\x80\x9cmvn clean install\xe2\x80\x9d 构建了我的项目,成功了,输出片段:

\n
[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  13.753 s\n[INFO] Finished at: 2021-09-03T15:22:24-07:00\n[INFO] ------------------------------------------------------------------------\n
Run Code Online (Sandbox Code Playgroud)\n

我通过以下方式运行了 \xe2\x80\x9cjar\xe2\x80\x9d:

\n
java -jar ./target/my_edge_ai-1.0-SNAPSHOT.jar 1 main\n
Run Code Online (Sandbox Code Playgroud)\n

java 代码尝试使用InterPlatformMobilityServicevia 初始化 JADE(参考代码片段):\n启动 JADE,但有以下例外:

\n

这引用自(Fabio Belllifemine 等人的 JADE Mobility Services 的使用):

\n

\xe2\x80\x9c6.4.2 平台间移动服务 IPMS 未内置于平台中,必须作为附加组件安装。要安装该附加组件,必须将包分发文件解压缩到 JADE 文件夹中,在该文件夹中使用 ant lib 命令创建包含所有已编译类文件的 Jar 文件。要使用该服务,必须在命令行上显式指定,不要忘记首先包含平台内移动服务:\xe2\x80\x9d

\n
java jade.Boot -services jade.core.mobility.AgentMobilityService;jade.core.migration. InterPlatformMobilityService\n
Run Code Online (Sandbox Code Playgroud)\n

我也得到了同样的结果java.lang.ClassNotFoundException当我尝试通过 Java 或命令行方法启动平台内移动服务时,

\n

尝试 1(migration.jar 作为 pom.xml 的存储库):

\n
<repositories>\n        <repository> \n            <id>tilab</id> \n            <url>https://jade.tilab.com/maven/</url> \n        </repository>\n            <repository>\n                <id>jade-ipms</id>\n                <url>file:${basedir}/add-ons/ipms/lib/migration.jar</url>\n            </repository>\n            <repository>\n                <id>jade-ipms-harcoded</id>\n                <url>/root/my/my/jade/jade/add-ons/ipms/lib/migration.jar</url>\n            </repository>\n    </repositories>\n
Run Code Online (Sandbox Code Playgroud)\n

构建的项目没有错误,但是得到了与运行时相同的异常:java.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService.

\n

尝试2(我将migration.jar手动复制到我的项目/lib):

\n
root@pc-064067:~/my/my/jade/jade/my_edge_ai/my_edge_ai/libs# ls\ncommons-codec-1.3.jar  jade.jar  migration.jar\n
Run Code Online (Sandbox Code Playgroud)\n

再次,构建的项目没有错误,但是得到了与运行时相同的异常:java.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService

\n

尝试#3,我将migration.jar添加到我的系统类路径中:

\n
export CLASSPATH=/root/my/my/jade/jade/my_edge_ai/my_edge_ai/libs/jade.jar:$CLASSPATH\nexport CLASSPATH=/root/my/my/jade/jade/my_edge_ai/my_edge_ai/libs/commons-codec-1.3.jar:$CLASSPATH\nexport CLASSPATH=/root/my/my /jade/jade/my_edge_ai/my_edge_ai/libs/migration.jar:$CLASSPATH\n\njava -jar ./target/my-1.0-SNAPSHOT.jar 1 main\n
Run Code Online (Sandbox Code Playgroud)\n

再次,构建的项目没有错误,但是得到了与运行时相同的异常:java.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService.

\n

我使用 Java -cp 或 -classpath 标志也遇到了同样的错误。

\n

最后,我打开了 migration.jar,以检查jade.core.migration.InterPlatformMobilityService 是否确实存在。

\n

尝试#4)我做了一些令人讨厌的事情,我将migration.jar中的类直接复制到我的src/main/java下,但是再次出现同样的错误!

\n

java.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService.

\n

尝试5:

\n
    \n
  1. 根据 StackOverflow 的反馈,我在本地安装了 JAR,如下所示:

    \n

    mvn install:install-file -Dfile=/home/azureuser/cyz/my/multi_agents/my_edge_ai/JadeDownload/jade/add-ons/ipms/lib/migration.jar -DgroupId=jade.core.migration -DartifactId=InterPlatformMobilityService - Dversion=1.5 -Dpackaging=jar -DJadeAddOnsPath=/home/azureuser/xyz/my/multi_agents/my_edge_ai/JadeDownload/jade/add-ons/ipms/lib/

    \n
  2. \n
\n

输出片段:

\n
[INFO] ---------------------< abc.def.hgi:my_edge_ai >---------------------\n[INFO] Building my_edge_ai 1.0-SNAPSHOT\n[INFO] --------------------------------[ jar ]---------------------------------\n[INFO]\n[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ my_edge_ai ---\n[INFO] Installing /home/azureuser/xyz/my/multi_agents/my_edge_ai/JadeDownload/jade/add-ons/ipms/lib/migration.jar to /home/azureuser/.m2/repository/jade/core/migration/InterPlatformMobilityService/1.5/InterPlatformMobilityService-1.5.jar\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  0.893 s\n[INFO] Finished at: 2021-09-07T23:50:50Z\n[INFO] ------------------------------------------------------------------------\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 将此依赖项块添加到依赖项部分:
  2. \n
\n\n jade.core.migration\n 迁移\n 1.5\n 系统\n ${JadeAddOnsPath}/migration.jar\n \n
    \n
  1. 构建项目:

    \n

    sudo mvn clean install -DJadeAddOnsPath=/home/azureuser/xyz/my/multi_agents/my_edge_ai/JadeDownload/jade/add-ons/ipms/lib/

    \n
  2. \n
\n

输出片段:

\n
[INFO] --- maven-jar-plugin:3.1.1:jar (default-jar) @ my_edge_ai ---\n[INFO] Building jar: /home/azureuser/xyz/my/multi_agents/my_edge_ai/my_edge_ai/target/my_edge_ai-1.0-SNAPSHOT.jar\n[INFO]\n[INFO] --- maven-install-plugin:2.4:install (default-install) @ my_edge_ai ---\n[INFO] Installing /home/azureuser/xyz/my/multi_agents/my_edge_ai/my_edge_ai/target/my_edge_ai-1.0-SNAPSHOT.jar to /root/.m2/repository/abc/def/hgi/my_edge_ai/1.0-SNAPSHOT/my_edge_ai-1.0-SNAPSHOT.jar\n[INFO] Installing /home/azureuser/xyz/my/multi_agents/my_edge_ai/my_edge_ai/pom.xml to /root/.m2/repository/abc/def/hgi/my_edge_ai/1.0-SNAPSHOT/my_edge_ai-1.0-SNAPSHOT.pom\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  1.609 s\n[INFO] Finished at: 2021-09-07T23:51:57Z\n[INFO] ------------------------------------------------------------------------\n
Run Code Online (Sandbox Code Playgroud)\n

但是同样的错误:

\n
WARNING: Exception initializing service jade.core.migration.InterPlatformMobilityService\njade.core.ServiceException: An error occurred during service activation - Caused by:  jade.core.migration.InterPlatformMobilityService\n        at jade.core.AgentContainerImpl.startService(AgentContainerImpl.java:1169)\n        at jade.core.AgentContainerImpl.initAdditionalServices(AgentContainerImpl.java:450)\n        at jade.core.AgentContainerImpl.startNode(AgentContainerImpl.java:389)\n        at jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:502)\n        at jade.core.Runtime.createMainContainer(Runtime.java:159)\n        at abc.def.hgi.Setup.start(Setup.java:68)\n        at abc.def.hgi.App.main(App.java:55)\nNested Exception:\njava.lang.ClassNotFoundException: jade.core.migration.InterPlatformMobilityService\n        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)\n        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)\n        at java.lang.Class.forName0(Native Method)\n        at java.lang.Class.forName(Class.java:264)\n        at jade.core.AgentContainerImpl.startService(AgentContainerImpl.java:1153)\n        at jade.core.AgentContainerImpl.initAdditionalServices(AgentContainerImpl.java:450)\n        at jade.core.AgentContainerImpl.startNode(AgentContainerImpl.java:389)\n        at jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:502)\n        at jade.core.Runtime.createMainContainer(Runtime.java:159)\n        at abc.def.hgi.Setup.start(Setup.java:68)\n        at abc.def.hgi.App.main(App.java:55)\n
Run Code Online (Sandbox Code Playgroud)\n

尝试#6(使用 jar -,基于 stackoverflow 反馈):

\n

在实际 JAR 中搜索jade.core.migration.InterPlatformMobilityService,因此必须在jade/core/migration/InterPlatformMobilityService 下,即它所在的位置,请参见粗体部分。

\n
jar -tvf ./add-ons/ipms/lib/migration.jar \n
Run Code Online (Sandbox Code Playgroud)\n

输出片段:

\n
0 Tue May 23 16:26:46 PDT 2017 META-INF/\n   103 Tue May 23 16:26:44 PDT 2017 META-INF/MANIFEST.MF\n     0 Tue May 23 16:26:44 PDT 2017 jade/\n     0 Tue May 23 16:26:44 PDT 2017 jade/core/\n     0 Tue May 23 16:26:46 PDT 2017 jade/core/migration/\n     0 Tue May 23 16:26:46 PDT 2017 jade/core/migration/analysis/\n     0 Tue May 23 16:26:46 PDT 2017 jade/core/migration/code/\n     0 Tue May 23 16:26:46 PDT 2017 jade/core/migration/ontology/\n     0 Tue May 23 16:26:46 PDT 2017 samples/\n     0 Tue May 23 16:26:46 PDT 2017 samples/mobilegui/\n  2739 Tue May 23 16:26:44 PDT 2017 jade/core/migration/AMSInitiator$PowerupRequest.class\n  8881 Tue May 23 16:26:44 PDT 2017 jade/core/migration/AMSInitiator.class\n 10918 Tue May 23 16:26:46 PDT 2017 jade/core/migration/AMSResponder.class\n  1003 Tue May 23 16:26:46 PDT 2017 jade/core/migration/InterPlatformMobilityHelper.class\n  2526 Tue May 23 16:26:46 PDT 2017 jade/core/migration/InterPlatformMobilityProxy.class\n   272 Tue May 23 16:26:46 PDT 2017 **jade/core/migration/InterPlatformMobilityService$1.class**\n  1687 Tue May 23 16:26:46 PDT 2017 jade/core/migration/InterPlatformMobilityService$CodeLocatorMonitor.class\n  6816 Tue May 23 16:26:46 PDT 2017 jade/core/migration/InterPlatformMobilityService$CommandOutgoingFilter.class\n\nI also checked the JAR manually by changing it to zip & jade.core.migration.InterPlatformMobilityService is where its suppose to be:\n
Run Code Online (Sandbox Code Playgroud)\n

在此输入图像描述

\n
root:~/my/my/jade/jade/my_edge_ai/my_edge_ai# jar -tvf ./target/my_edge_ai-1.0-SNAPSHOT.jar   \n
Run Code Online (Sandbox Code Playgroud)\n

输出:

\n
401 Wed Sep 08 12:40:46 PDT 2021 META-INF/MANIFEST.MF\n     0 Wed Sep 08 12:40:46 PDT 2021 META-INF/\n     0 Wed Sep 08 12:40:40 PDT 2021 abc/\n     0 Wed Sep 08 12:40:40 PDT 2021 abc/def/\n     0 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/\n     0 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/\n     0 Wed Sep 08 12:40:46 PDT 2021 META-INF/maven/\n     0 Wed Sep 08 12:40:46 PDT 2021 META-INF/maven/abc.def.hgi/\n     0 Wed Sep 08 12:40:46 PDT 2021 META-INF/maven/abc.def.hgi/my_edge_ai/\n  1045 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/App.class\n  3438 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/ManagerAgent.class\n  2164 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForAudioAgent$1.class\n  3993 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForAudioAgent.class\n  2228 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForBiometricAgent$1.class\n  3024 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForBiometricAgent.class\n  3316 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForImageAnalysisAgent.class\n  1094 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/TestAgent$1.class\n  3555 Tue Sep 07 15:44:40 PDT 2021 META-INF/maven/abc.def.hgi/my_edge_ai/pom.xml\n  2703 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/AudioAnalysisRegisterAgent$InaCyclicBehavior.class\n  2264 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/SearchForImageAnalysisAgent$1.class\n  2669 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/Setup.class\n  1406 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/TestAgent.class\n    98 Wed Sep 08 12:40:46 PDT 2021 META-INF/maven/abc.def.hgi/my_edge_ai/pom.properties\n  4507 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/AudioAnalysisRegisterAgent.class\n  2313 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/DFRegisterAgent.class\n  2667 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/DFSubscribeAgent$1.class\n  2827 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/BiometricsRegisterAgent.class\n  2755 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/DFSearchAgent.class\n  1870 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/DFSubscribeAgent.class\n   284 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/HelloAgent.class\n   275 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/HiAgent.class\n  1891 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/ManagerAgent$1.class\n  2481 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/yellowpages/SubDF.class\n  2836 Wed Sep 08 12:40:40 PDT 2021 abc/def/hgi/ImageAnalyisRegisterAgent.class\n
Run Code Online (Sandbox Code Playgroud)\n

进一步调查:

\n

构建Jar项目的MANIFEST.MF(./target/my-1.0-SNAPSHOT.jar):

\n
Manifest-Version: 1.0\nBuilt-By: root\nClass-Path: libs/jade-4.5.0.jar libs/commons-codec-1.3.jar libs/jade-m\n isc-2.8.0.jar libs/jade-test-suite-1.13.0.jar libs/jade-wsdc-2.7.0.ja\n r libs/axis-plus-1.4.0.jar libs/addressing-1.1.1.jar libs/wss4j-1.5.1\n .jar libs/xmlsec-1.3.0.jar libs/jade-xml-codec-1.11.0.jar\nCreated-By: Apache Maven 3.6.3\nBuild-Jdk: 1.8.0_292\nMain-Class: abc.def.ghi.App\n
Run Code Online (Sandbox Code Playgroud)\n

尝试#7(问题仅​​在本地计算机上解决):

\n
    \n
  1. 我决定构建一个“fat JAR”,其中包含JAR 本身内的所有库(

cyb*_*101 1

解决了:

在远程 pom.xml 中,我更改了 InterPlatformMobilityService 依赖项以使用 maven 本地存储库,而不是指向实际文件:

jade.core.migration InterPlatformMobilityService 1.5 系统 ${JadeAddOnsPath}/migration.jar --> 感谢社区的支持和反馈!