I have a multimodule Spring Boot project with Maven. I am using spring-boot-maven-plugin to package this application into an executable JAR. This JAR is deployed to PCF (Pivotal Cloud Foundry).
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>my.AppMain</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Now I would like to use PDFTron library - they provided me with a JAR ,.so and .dylib files (.dll too but I dont need those). They said that the JAR has to be in the same directory as the so and dylib files in order to work properly.
I tried to use this library in the project but I cant make it work. I am running out of ideas, I believe I have read almost all possible posts to this topic.
I have tried:
load each of this files to maven repo, include each one as (dylib, so and pdfnet.jar), but it resulted in error message: Caused by: java.lang.UnsatisfiedLinkError: no PDFNetC in java.library.path:
put all the files (dylib, so and pdfnet.jar) into the src/main/resources, include just provided PDFNet.jar as but it resulted in error message: Caused by: java.lang.UnsatisfiedLinkError: no PDFNetC in java.library.path:
Only way that worked was when I used maven-dependency-plugin
to unpack the PDFTron dependencies into the target directory and update the -Djava.library.path to point at this created directory - but this can be done only at my local machine, because PDFTron dependencies were unpacked at "package" phase. To the PCF we are depolying only the executable JAR, so there is no target directory at PCF, so this was not an "production ready" option.
My question is, how can I include these files into this "executable JAR" so it will work properly ? Is there a way to unpack them at runtime ? Or do I have to use other plugin than spring-boot-maven-plugin
?
I can modify the -Djava.library.path at PCF, but I would like to avoid deploying another zip/jar/folder along with this JAR (basically I want to avoid changing the CI/CD deploy script as it is not under my control - and right now we are deploying only the executable JAR)
I am using java version "11.0.8" and spring-boot version "2.2.8.RELEASE"
question from:
https://stackoverflow.com/questions/65935083/include-and-use-native-lib-files-so-dylib-in-executable-jar 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…