在Mac OS X上加载JNI lib? [英] Loading JNI lib on Mac OS X?

查看:168
本文介绍了在Mac OS X上加载JNI lib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

所以我试图加载一个jnilib(特别是 JOGL )在运行时在Mac OS X上运行到Java。我一直关注相关的Stack Overflow问题:

So I am attempting to load a jnilib (specifically JOGL) into Java on Mac OS X at runtime. I have been following along the relevant Stack Overflow questions:

  • Maven and the JOGL Library
  • Loading DLL in Java - Eclipse - JNI
  • How to make a jar file that include all jar files

我的最终目标是将特定于平台的JOGL文件打包到JAR中并将它们解压缩到临时目录中并在启动时加载它们。我回过头来尝试使用硬编码路径加载JOGL:

The end goal for me is to package platform specific JOGL files into a JAR and unzip them into a temp directory and load them at start-up. I worked my problem back to simply attempting to load JOGL using hard-coded paths:

    File f = new File("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl.jnilib");
    System.load(f.toString());
    f = new File ("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl_awt.jnilib");
    System.load(f.toString());

尝试使用JOGL API时出现以下异常:

I get the following exception when attempting to use the JOGL API:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path

但是当我通过添加以下JVM选项指定 java.library.path 时:

But when I specify java.library.path by adding the following JVM option:

    -Djava.library.path="/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/" 

一切正常。

问题

是否可以使用 System.load (或在Mac OS X上作为-Djava.library.path的替代品在运行时被调用?

Is it possible use System.load (or some other variant) on Mac OS X as a replacement for -Djava.library.path that is invoked at runtime?

推荐答案

Jogl总是尝试自动加载所有依赖库。
为避免这种情况,应该有一个NativeLibLoader类,您可以在通过System.load()

Jogl always tries to auto-load all dependent libraries. To avoid this, there should be a NativeLibLoader class where you can call disableLoading() before you load the libraries yourself via the System.load()

这篇关于在Mac OS X上加载JNI lib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆