0

我编写了一个程序来使用 RXTXcomm.jar 与 arduino 进行通信。它在 Eclipse 中有效,因为我在编辑类路径选项中“添加了外部罐子”。

我从这个网站上得到了教程:http ://www.drdobbs.com/jvm/control-an-arduino-from-java/240163864 。我最初尝试在该网站上运行命令以使 RXTXcomm.jar 工作而不必使用 eclipse 工作,但我无法让它工作(经过大量时间和研究)。但是,现在我想从我的程序中制作一个 .exe。我使用 Launch4J 制作了一个 .exe,它可以工作,但是,就像在 eclipse 工作之前一样,串行通信方面不起作用。

我已经想到了两个修复,但是我不知道其中任何一个的合理性:

1) 一些如何将我的 java gui 导出到一个 jar 文件中,该文件包含使用 eclipse 工作时添加的 RXTXcomm.jar

2) 编写一个我运行一次的脚本来设置计算机,这将允许我使用 RXTXcomm.jar

主要目标是创建此 .exe 并将所有支持文件与它一起放在一个文件夹中,可能还有一个安装程序/自述文件以使其在任何 PC 上运行。

这是我只运行 [myprogram].jar 文件时的叠加:

java.exe -jar [myprogram].jar

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while
loading gnu.io.RXTXCommDriver
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no rxtxSe
rial in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        (AND MORE)

我对java幕后发生的事情知之甚少,我大多只了解代码。我认为这就是为什么我在这方面遇到麻烦。

4

1 回答 1

0

Thank you @hoijui,

I ended up just copying the rxtxSerial.dll to the same directory that the exe is run from and now it works. This directory also includes the RXTXcomm.jar as well. When making the exe in Launch4J I made a custom class path: The "Main Class" I selected the jar I made from eclipse, then for the class path I added:

echo %CD%\RXTXcomm.jar 

and

echo %CD%\rxtxSerial.dll.

I am not sure if this is needed to work but its there and it work so I am not messing with it.

Thanks for the help @hoijui

于 2015-07-25T14:03:54.040 回答