Spring Boot 在Linux環境中 使用System.loadLibrary("XXX") 加載so文件


場景, 在Spring Boot加載so文件, 在此記錄配置的過程和幫助過我的鏈接文檔


System.loadLibrary("hello"); // Load native library at runtime
hello.dll (Windows) or libhello.so
注意: window環境中文件名為hello.dll 或 libhello.so

 

步驟1: 把so文件存放在一個目錄中

 

 

步驟2: Linux 運行jar文件配置lib庫地址

nohup java -Dfile.encoding=utf-8 -Djava.library.path=/root/baller/lib -jar picture-server.jar >nohup.log 2>&1 &

 此時運行會提示錯誤: cannot open shared object file: No such file or directory

 

 

步驟3: 把非lib目錄 加入到共享庫配置文件/etc/ld.so.conf 中

參考地址: https://blog.csdn.net/chen495810242/article/details/89314570

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/root/baller/lib" >> /etc/ld.so.conf
# ldconfig  刷新的作用

 

步驟4: 再次執行jar 啟動,成功無錯誤

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM