# CosmicSDK Java Language Bindings (Reference)

This folder contains a reference Java integration over the CosmicSDK C shared library.
It is example code and not an official Java SDK package.

## Prerequisites

- Java 17+
- Maven 3.8+
- `COSMICSDK_LIB_PATH` environment variable pointing to:
  - a folder containing the shared library, or
  - the full path to the shared library file

Library file names by platform:
- Windows: `cosmicsdk.dll`
- macOS: `libcosmicsdk.dylib`
- Linux: `libcosmicsdk.so`

Tested JDK on Windows:
- Eclipse Temurin JDK `17.0.18+8` (Adoptium)

## Troubleshooting

If examples start and connect, but the process exits silently during native API calls:
- Use a tested JDK build (recommended: Eclipse Temurin 17.0.18+8).
- Ensure the same terminal has `COSMICSDK_LIB_PATH` set to the intended library location.
- Run with JNA debug load enabled to confirm which DLL is loaded:

```bash
set MAVEN_OPTS=-Djna.debug_load=true -Djna.debug_load.jna=true
mvn -e exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.system.SystemExample
```

## Build

```bash
cd /path/to/CosmicSDK/examples/language_bindings/java
mvn compile
```

## Run examples

```bash
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.system.SystemExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i2c.I2cExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.spi.SpiExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.uart.UartExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.gpio.GpioExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i3c.basic.I3cBasicExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i3c.ccc.I3cCccExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i3c.daa.I3cDaaExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i3c.hdrddr.I3cHdrDdrExample
mvn -q exec:java -Dexec.mainClass=com.binho.cosmicsdk.examples.i3c.hjibi.I3cHjIbiExample
```

On Linux, if loading fails with missing native dependencies (for example
`libhidapi-libusb.so.0`), export:

```bash
export LD_LIBRARY_PATH=$COSMICSDK_LIB_PATH:$LD_LIBRARY_PATH
```

On macOS, the equivalent fallback is:

```bash
export DYLD_LIBRARY_PATH=$COSMICSDK_LIB_PATH:$DYLD_LIBRARY_PATH
```
