你可以在运行时以编程方式获取正在使用的JNA版本吗?

huangapple go评论59阅读模式
英文:

How can I programmatically get the JNA version being used at runtime?

问题

I'm trying to print the JNA version being used to my logs, at runtime.

How do I get the version of JNA through code at runtime?

英文:

I'm trying to print the JNA version being used to my logs, at runtime.

How do I get the version of JNA through code at runtime?

答案1

得分: 1

当前的JNA版本在构建时被写入到名为Version的接口中的常量VERSION中。该接口是包私有的,但由Native类实现,因此可以从Native中公开访问该常量。(代码检查工具可能会提出警告。)所以你可以简单地这样做:

import com.sun.jna.Native;

public class Test {
    public static void main(String[] args) {
        System.out.println("JNA版本:" + Native.VERSION);
    }
}

输出:

JNA版本:5.6.0

你还可以获取本机部分的版本,本机部分的版本遵循与整个项目版本不同的编号方案(对于不更改已编译的本机部分的新映射进行递增),但在某些情况下可能相关:

System.out.println("JNA本机版本:" + Native.VERSION_NATIVE);

Native类还公开了一个boolean类型的isCompatibleVersion()方法,你可以使用它来检查JNA是否至少是指定版本或更高版本。

英文:

The current JNA version is written at build time to a constant VERSION in the appropriately-named Version interface. That interface is package private, but is implemented by the Native class, making the constant publicly available from Native. (Linters may complain.) So you can simply do:

import com.sun.jna.Native;

public class Test {
    public static void main(String[] args) {
        System.out.println("JNA Version: " + Native.VERSION);
    }
}

Output:

JNA Version: 5.6.0

You can also get the version of the native bits, which follow a different numbering scheme than the overall project version (which is incremented with new mappings that don't change the compiled native portions), but may be relevant in some contexts:

System.out.println("JNA Native Version: " + Native.VERSION_NATIVE);

The Native class also exposes a boolean isCompatibleVersion() method which you can use to check whether JNA is at least the specified version or higher.

huangapple
  • 本文由 发表于 2020年7月23日 00:22:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63038820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定