英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论