linux java调用动态库

apt-get install openjdk-11-jre

apt-get install openjdk-11-jdk

查看 JDK 和 JRE 的安装路径

sudo update-alternatives –config java

sudo update-alternatives –config javac

下载jna-5.8.0.jar

动态库libtest.so

编辑test.java

1 import com.sun.jna.Library;
2 import com.sun.jna.Native;
3
4 public class test{
5
6 public interface CtlACSS extends Library {
7 CtlACSS INSTANTCE = (CtlACSS) Native.loadLibrary(“test”, CtlACSS.class);
8 public int tlACS_init(ports);
9 }
10
11 public static void main(String[] args){
12 Clibrary.INSTANTCE.test();
13 System.out.println(“Hello”);
14 }
15 }

javac -cp jna-5.8.0.jar test.java

java -cp jna-5.8.0.jar: test

打包成jar包:

编辑manifest.mf

解压jar xvf jna-5.8.0.jar

jar cvfm test.jar manifest.mf ‘test$Clibrary.class’ libtest.so test.class com