stepfunc / rodbus

Rust implementation of Modbus with idiomatic bindings for C, C++, .NET, and Java
https://stepfunc.io/products/libraries/modbus/
Other
80 stars 22 forks source link

Java 17 Rodbus Setup Question: Unable to load any of the included native libraries #129

Open ejrfisher opened 6 months ago

ejrfisher commented 6 months ago

I have a project that I am trying to setup. Its a spring boot app using Java 17 When I attempt to create the Runtime object similarly to the example files I run into an issue regarding some native libraries.

I have hopefully formatted the structure below into somewhat orderly manner so that it can be easy to follow my setup and identify any glaring issues.

Thanks!

Exception Stack Trace

  2023-12-14 13:47:14.877 [http-nio-591-exec-1] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for                    servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
  java.lang.Exception: Unable to load any of the included native libraries
      at io.stepfunc.rodbus.NativeFunctions.<clinit>(NativeFunctions.java:53)
      at io.stepfunc.rodbus.NativeFunctions$Wrapped.runtime_create(NativeFunctions.java:193)
      at io.stepfunc.rodbus.Runtime.<init>(Runtime.java:37)

Method Throwing Error (specifically the second line here is the culprit)

        RuntimeConfig runtimeConfig = new RuntimeConfig().withNumCoreThreads(ushort(4));
        Runtime runtime = new Runtime(runtimeConfig);

Java Version

  java 17.0.6 2023-01-17 LTS
  Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
  Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)

pom.xml snippet

        <dependency>
            <groupId>io.stepfunc</groupId>
            <artifactId>rodbus</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>joou</artifactId>
            <version>0.9.4</version>
        </dependency>

class imports

  import static org.joou.Unsigned.ubyte;
  import static org.joou.Unsigned.ushort;
  import io.stepfunc.rodbus.*;
  import io.stepfunc.rodbus.Runtime;

Let me know if I am overlooking something in my setup here or if there is any additional information that you need to help me with this issue! Thanks

jadamcrain commented 6 months ago

What's your OS and CPU architecture?

On Thu, Dec 14, 2023, 1:40 PM ejrfisher @.***> wrote:

I have a project that I am trying to setup. Its a spring boot app using Java 17 When I attempt to create the Runtime object similarly to the example files I run into an issue regarding some native libraries.

I have hopefully formatted the structure below into somewhat orderly manner so that it can be easy to follow my setup and identify any glaring issues.

Thanks!

Exception Stack Trace

2023-12-14 13:47:14.877 [http-nio-591-exec-1] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause java.lang.Exception: Unable to load any of the included native libraries at io.stepfunc.rodbus.NativeFunctions.(NativeFunctions.java:53) at io.stepfunc.rodbus.NativeFunctions$Wrapped.runtime_create(NativeFunctions.java:193) at io.stepfunc.rodbus.Runtime.(Runtime.java:37)

Method Throwing Error (specifically the second line here is the culprit)

    RuntimeConfig runtimeConfig = new RuntimeConfig().withNumCoreThreads(ushort(4));
    Runtime runtime = new Runtime(runtimeConfig);

Java Version

java 17.0.6 2023-01-17 LTS Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190) Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)

pom.xml snippet

    <dependency>
        <groupId>io.stepfunc</groupId>
        <artifactId>rodbus</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.jooq</groupId>
        <artifactId>joou</artifactId>
        <version>0.9.4</version>
    </dependency>

class imports

import static org.joou.Unsigned.ubyte; import static org.joou.Unsigned.ushort; import io.stepfunc.rodbus.*; import io.stepfunc.rodbus.Runtime;

Let me know if I am overlooking something in my setup here or if there is any additional information that you need to help me with this issue! Thanks

— Reply to this email directly, view it on GitHub https://github.com/stepfunc/rodbus/issues/129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKVFL6XGLLCMNV2DB26F3YJNW3FAVCNFSM6AAAAABAVQISZ6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DENJUG4YDANA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ejrfisher commented 6 months ago

MacOs - 14.2 ARM - Apple M1 Max

If it at all matters: I have also tried running the application in a docker container, and although the error output is different the culprit seems to be the same Runtime object

jadamcrain commented 6 months ago

There is no MacOS ARM binary in the JAR, so that's the error I'd expect there.

Until recently GitHub didn't have a ARM runner for MAC. I think it would be possible to add this to the CI now.

How does docker work on Mac? There is a linux aarch64 native library in the JAR.

On Thu, Dec 14, 2023, 1:52 PM ejrfisher @.***> wrote:

MacOs ARM - Apple M1 Max

If it at all matters: I have also tried running the application in a docker container, and although the error output is different the culprit seems to be the same Runtime object

— Reply to this email directly, view it on GitHub https://github.com/stepfunc/rodbus/issues/129#issuecomment-1856712949, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKVFIQ7YDG5MFP73DCEILYJNYLPAVCNFSM6AAAAABAVQISZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJWG4YTEOJUHE . You are receiving this because you commented.Message ID: @.***>

ejrfisher commented 6 months ago

From my understanding the docker daemon manages the "architecture" of the built image. I can try to set a target platform/architecture otherwise its just based off the base image which for this specific example was eclipse-temurin:17-alpine

which was AMD64 not ARM64/aarch64...

Ill try and find an image to build off of that is actually aarch64 and go from there

ejrfisher commented 6 months ago

I now have a linux based image running with aarch64 architecture for the same app in docker container but I am still running into an error when creating the Runtime Object .

Error Message

2023-12-15 11:13:43 thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: JavaException', /target/aarch64-unknown-linux-gnu/release/build/rodbus-ffi-java-1095f2a2549debe7/out/jni.rs:3439:187
2023-12-15 11:13:43 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2023-12-15 11:13:43 fatal runtime error: failed to initiate panic, error 4164302448

os info

 cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"

Architecture info

# lscpu
Architecture:           aarch64
  CPU op-mode(s):       64-bit
  Byte Order:           Little Endian

Let me know if theres any more info I can provide

ejrfisher commented 6 months ago

Moved my project up to java 21 to see if that changed anything locally or in docker. No change Read through the mentioned issue, but not sure if it relates to the errors I am seeing or if there is a new release for the rodbus library?

jadamcrain commented 6 months ago

No new release for the Rodbus library yet.

I plan to do a maintenance release soon that will incorporate some more debug info into the Java library loading process. Maybe that will shed some light on what's going on in your app.

ejrfisher commented 6 months ago

Sounds great! Thanks for the update

edit: seems like the Runtime Object is no longer the culprit for this error but instead its moved down to either DeviceMap or ClientChannel.createTcp I'll update the issue if I can find a better description of the issue.

jadamcrain commented 1 week ago

@ejrfisher 1.4.0 release now includes a bundled native library for aarch64-apple-darwin