白季飞龙的个人主页

Java之JNA示例

依赖

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.5.2</version>
</dependency>

示例代码

package bj;


import com.sun.jna.Library;
import com.sun.jna.Native;

import java.lang.management.ManagementFactory;

class App {
    public static void main(String[] var0) {
        System.out.println(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
        System.out.println(Native.loadLibrary("c", TheCLibrary.class).getpid());
        Native.loadLibrary("c", TheCLibrary.class).printf("%016x", 4095);
    }
}

interface TheCLibrary extends Library {
    int getpid();

    void printf(String format, Object... args);
}

输出

18724
18724
0000000000000fff

漫漫路,莫论逍遥;潜心修,只为悟道