请注意,虽然其他帖子提出了类似的问题,但我已经用尽了这些帖子中的所有答案。问题如下:
我在 NetBeans Ver中开发了一个Java应用程序。 8.1 在 MacOS Sierra 上。该应用程序从NetBeans IDE和MacOS终端命令行成功运行。在获得Raspberry Pi B +之后,我创建了一个NetBeans项目配置,该配置与运行 Raspbian OS 的 Raspberry Pi B + 连接。因此,我现在可以从NetBeans IDE构建和部署到MacOS或Raspberry Pi。 但是,当我尝试通过IDE或通过SSH通过终端命令行运行它时,应用程序在Pi上失败。
Kenwood_520S.jar 是应用程序jar文件的名称, Kenwood_520S 是包的名称,收发器< / strong>是带有public static main()方法的类的名称。
从终端命令行执行的命令是:
java -cp Kenwood_520S.jar Kenwood_520S.Transceiver
尝试在Pi上运行应用程序时,在IDE的调试窗口和SSH终端中发布的错误消息是相同的,即:
错误:无法找到或加载主要类 Kenwood_520S.Transceiver
我比较了dist目录和子目录的内容以及在MacOS(默认配置)和Raspberry Pi B +(Pi配置)上创建的jar文件。两个平台上的目录,子目录和jar文件内容是相同的。我发布以下详细信息:
ls dist
Kenwood_520S.jar
README.TXT
lib
ls lib
AbsoluteLayout.jar
commons-lang3-3.5.jar
HawkBridgeFactory.jar
JTransforms-3.1-with-dependencies.jar
swing-layout-1.0.4.jar
jar -tf Kenwood_520S.jar
META-INF/
META-INF/MANIFEST.MF
Kenwood_520S/
Kenwood_520S/AudioConversion$Range.class
Kenwood_520S/AudioConversion.class
Kenwood_520S/Cryptography.class
Kenwood_520S/DateInputVerifier.class
Kenwood_520S/DialogStringEditor.class
Kenwood_520S/DoubleInputVerifier.class
Kenwood_520S/ExceptionWriter.class
Kenwood_520S/FrequencyInputVerifier.class
Kenwood_520S/IntegerInputVerifier.class
Kenwood_520S/Internationalization.class
Kenwood_520S/ModeInputVerifier.class
Kenwood_520S/PowerInputVerifier.class
Kenwood_520S/QRZSearchWebService.class
Kenwood_520S/QSOXML.class
Kenwood_520S/RSTInputVerifier.class
Kenwood_520S/SampleProcessor.class
Kenwood_520S/TimeInputVerifier.class
Kenwood_520S/Transceiver$1.class
Kenwood_520S/Transceiver$10.class
Kenwood_520S/Transceiver$11.class
Kenwood_520S/Transceiver$12.class
Kenwood_520S/Transceiver$13.class
Kenwood_520S/Transceiver$14.class
Kenwood_520S/Transceiver$15.class
Kenwood_520S/Transceiver$16.class
Kenwood_520S/Transceiver$17.class
Kenwood_520S/Transceiver$18.class
Kenwood_520S/Transceiver$19.class
Kenwood_520S/Transceiver$2.class
Kenwood_520S/Transceiver$20.class
Kenwood_520S/Transceiver$21.class
Kenwood_520S/Transceiver$22.class
Kenwood_520S/Transceiver$23.class
Kenwood_520S/Transceiver$24.class
Kenwood_520S/Transceiver$25.class
Kenwood_520S/Transceiver$26.class
Kenwood_520S/Transceiver$27.class
Kenwood_520S/Transceiver$28.class
Kenwood_520S/Transceiver$29.class
Kenwood_520S/Transceiver$3.class
Kenwood_520S/Transceiver$30.class
Kenwood_520S/Transceiver$31.class
Kenwood_520S/Transceiver$32.class
Kenwood_520S/Transceiver$33.class
Kenwood_520S/Transceiver$34.class
Kenwood_520S/Transceiver$35.class
Kenwood_520S/Transceiver$4.class
Kenwood_520S/Transceiver$5.class
Kenwood_520S/Transceiver$6.class
Kenwood_520S/Transceiver$7.class
Kenwood_520S/Transceiver$8.class
Kenwood_520S/Transceiver$9.class
Kenwood_520S/Transceiver.class
Kenwood_520S/WavAudioPulse$PulseLevel.class
Kenwood_520S/WavAudioPulse.class
Kenwood_520S/WavAudioRecorder.class
Kenwood_520S/WavAudioSample.class
Kenwood_520S/WebServiceListener.class
Kenwood_520S/strings.properties
Kenwood_520S/strings_ar_SA.properties
Kenwood_520S/strings_el_GR.properties
Kenwood_520S/strings_en_US.properties
Kenwood_520S/strings_es_ES.properties
Kenwood_520S/strings_it_IT.properties
jar xf Kenwood_520S.jar
cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_73-b02 (Oracle Corporation)
Class-Path: lib/swing-layout-1.0.4.jar lib/AbsoluteLayout.jar lib/Hawk
BridgeFactory.jar lib/JTransforms-3.1-with-dependencies.jar lib/commo
ns-lang3-3.5.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: Kenwood_520S.Transceiver
The version of Java on the MacOS is:
java -version
java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
The version of Java on the Raspberry Pi is:
java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)
我怀疑行为上的差异可归因于环境差异。 Java版本的差异更具有远程可能性,但可能存在影响行为的其他环境变量。 (我怀疑CLASSPATH的区别是因为我在-cp命令行参数中明确指出它。)
请注意:我成功创建了几个&#34; Hello World&#34;键入在两个平台上以及IDE和命令行上运行的应用程序。作为我对此问题的调查的一部分,我这样做了。我是一名经验丰富的开发人员,但Java是一个相对较新的开发人员。
非常感谢您的时间和耐心。
答案 0 :(得分:0)
我在这里回答了我自己的问题,但不幸的是,没有立即解决这个问题的原因。此外,尽管我在问题中提供了所有细节,但我没有包含一个重要事实:此应用程序使用swing并导入javax。
有问题的Java应用程序为swing导入javax。 ARM处理器没有javax导入。因此,这个Java swing应用程序在Mac上运行,但在Pi上运行。
理解手头真正问题的关键在于使用 -verbose 开关执行java命令。
从MacOS终端命令行成功运行应用程序时,请观察该命令结果的片段。有许多对javax的引用以及成功的加载语句。
java -verbose -cp Kenwood_520S.jar Kenwood_520S.Transceiver
[来自/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar的加载java.io.FilePermission]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.io.FilePermission $ 1]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.io.FilePermissionCollection]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.security.AllPermission]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.security.UnresolvedPermission]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.security.BasicPermissionCollection]
[从文件中加载Kenwood_520S.WebServiceListener:/Users/steffen/Desktop/dist/Kenwood_520S.jar]
[从/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar加载java.util.EventListener]
[从文件加载gnu.io.SerialPortEventListener:/Library/Java/Extensions/RXTXcomm.jar]
[来自/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar的
现在,当应用程序在Pi上失败时,查看该命令结果的片段:
java -verbose -cp Kenwood_520S.jar Kenwood_520S.Transceiver
[从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.io.FilePermission] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.io.FilePermission $ 1] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.io.FilePermissionCollection] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.security.AllPermission] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.security.UnresolvedPermission] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.security.BasicPermissionCollection] [从文件中加载Kenwood_520S.WebServiceListener:/home/pi/NetBeansProjects/Kenwood_520S/dist/Kenwood_520S.jar] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.util.zip.Inflater] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.util.zip.ZStreamRef] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.util.zip.InflaterInputStream] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.util.zip.ZipFile $ ZipFileInflaterInputStream] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.io.IOException] ... [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.text.Format $ Field] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.text.MessageFormat $字段] 错误:找不到或加载主类Kenwood_520S.Transceiver [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.lang.Shutdown] [从/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/rt.jar加载java.lang.Shutdown $ Lock]
Pi的整个详细输出没有对javax的引用,因为遇到 Kenwood_520S.Transceiver 中的导入时,加载失败!问题不在于该文件无法找到,而是无法加载。
我的下一步是找到javax的ARM等价物 - 如果存在类似的东西。