java.lang.UnsatisfiedLinkError: Can't find dependent libraries only during debugging

java.lang.UnsatisfiedLinkError: Can't find dependent libraries only during debugging

我正在研究学生项目,该项目需要通过 USB(使用虚拟串行端口)读取从 AtMega 发送的数据。要访问串行端口,我使用 NeuronRobotics 的 nrjavaserial (https://github.com/NeuronRobotics/nrjavaserial),它是 RXTX 的一个分支。为了管理我的依赖项,我正在使用 maven。这是我 运行 CommPortIdentifier.getPortIdentifiers(); (或任何静态 CommPortIdentifier 函数)得到的结果:

java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at gnu.io.NativeResource.loadResource(NativeResource.java:142)
    at gnu.io.NativeResource.inJarLoad(NativeResource.java:40)
    at gnu.io.NativeResource.loadLib(NativeResource.java:60)
    at gnu.io.NativeResource.load(NativeResource.java:28)
    at gnu.io.SerialManager.<init>(SerialManager.java:10)
    at gnu.io.SerialManager.getInstance(SerialManager.java:16)
    at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:87)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
    at pl.edu.pwr.aerospace.enginebench.serial.SerialCommunicator.getAvaliablePorts(SerialCommunicator.java:34)
    at pl.edu.pwr.aerospace.enginebench.cli.Main.connectCommunicator(Main.java:35)
    at pl.edu.pwr.aerospace.enginebench.cli.Main.main(Main.java:21)
java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at gnu.io.NativeResource.loadResource(NativeResource.java:142)
    at gnu.io.NativeResource.inJarLoad(NativeResource.java:40)
    at gnu.io.NativeResource.loadLib(NativeResource.java:60)
    at gnu.io.NativeResource.load(NativeResource.java:28)
    at gnu.io.SerialManager.<init>(SerialManager.java:10)
    at gnu.io.SerialManager.getInstance(SerialManager.java:16)
    at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:87)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
    at pl.edu.pwr.aerospace.enginebench.serial.SerialCommunicator.getAvaliablePorts(SerialCommunicator.java:34)
    at pl.edu.pwr.aerospace.enginebench.cli.Main.connectCommunicator(Main.java:35)
    at pl.edu.pwr.aerospace.enginebench.cli.Main.main(Main.java:21)
java.lang.ExceptionInInitializerError thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver

这是我的依赖项:

<dependencies>

        <dependency>
            <groupId>com.neuronrobotics</groupId>
            <artifactId>nrjavaserial</artifactId>
            <version>3.12.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

</dependencies>

奇怪的是,这只发生在调试期间,当我 运行 正常编程时它就像魅力一样。有什么想法吗?

我发现人们对其他库也有类似的问题,但是所有这些库的解决方案都是移动 DLL 或更新类路径,但由于我使用的是 Maven,我怀疑在这种情况下解决方案会有所不同。

我设法解决了我的问题。这个问题的根本原因是我的用户名 - "Grześ",其中包含非标准字符“ś”。正如您在异常信息的第一行中看到的那样:

java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries

路径包含问号来代替这个字符。在 Windows 属性中更改我的用户名修复了这个问题