Issue with DLL Loading After Migrating from Eclipse to Maven Project
Posted: Wed 2. Apr 2025, 16:05
Hello, I am facing an issue after converting my java project from Eclipse based to a Maven-based project(still within eclipse environment).
Context:
The project was initially built using Eclipse, and everything worked fine. The PcanBasic_JINI.DLL was loaded correctly, and the application ran as expected.
After migrating to Maven, I placed the DLL in the src/main/resources directory. However, I am now encountering the following error:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
Caused by: java.lang.UnsatisfiedLinkError: 'boolean com.tec.peak.can.basic.PCANBasic.initializeAPI()'
What Works:
The application is able to find and load the DLL, but when trying to access the DLL's native method (initializeAPI), it throws the UnsatisfiedLinkError.
What I've Tried:
- I ensured that the DLL is placed in src/main/resources as a resource.
- I tried setting the library path programmatically by using System.setProperty("java.library.path", <path to dll>), but the issue persists.
- I created a JAR and ran it with the -D option, specifying the library path.
- I also tried passing the library path as a VM argument using -Djava.library.path=<path_to_dll>, but the issue still persists.
Target OS: Windows 11
Used Java Runtime: openjdk 21.0.2 2024-01-16 LTS
Pcan Details
API version: PCAN_USB 4.4.2.16701
Firmware version: 8.6.1
Programming language: Java (JDK 21)
Using PCAN jars
Questions:
1) How should I properly configure Maven to ensure that the DLL is correctly loaded during the application runtime?
2) Should I be placing the DLL somewhere else?
3) Is there a specific Maven plugin or configuration I need to add to copy the DLL to the correct location?
4) Does OpenJDK 21 pose any specific compatibility issues with the PCAN API that could be causing the DLL loading problem?
Context:
The project was initially built using Eclipse, and everything worked fine. The PcanBasic_JINI.DLL was loaded correctly, and the application ran as expected.
After migrating to Maven, I placed the DLL in the src/main/resources directory. However, I am now encountering the following error:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
Caused by: java.lang.UnsatisfiedLinkError: 'boolean com.tec.peak.can.basic.PCANBasic.initializeAPI()'
What Works:
The application is able to find and load the DLL, but when trying to access the DLL's native method (initializeAPI), it throws the UnsatisfiedLinkError.
What I've Tried:
- I ensured that the DLL is placed in src/main/resources as a resource.
- I tried setting the library path programmatically by using System.setProperty("java.library.path", <path to dll>), but the issue persists.
- I created a JAR and ran it with the -D option, specifying the library path.
- I also tried passing the library path as a VM argument using -Djava.library.path=<path_to_dll>, but the issue still persists.
Target OS: Windows 11
Used Java Runtime: openjdk 21.0.2 2024-01-16 LTS
Pcan Details
API version: PCAN_USB 4.4.2.16701
Firmware version: 8.6.1
Programming language: Java (JDK 21)
Using PCAN jars
Questions:
1) How should I properly configure Maven to ensure that the DLL is correctly loaded during the application runtime?
2) Should I be placing the DLL somewhere else?
3) Is there a specific Maven plugin or configuration I need to add to copy the DLL to the correct location?
4) Does OpenJDK 21 pose any specific compatibility issues with the PCAN API that could be causing the DLL loading problem?