Eclipse:使用本机打包JAR [英] Eclipse: Packaging a JAR with natives

查看:113
本文介绍了Eclipse:使用本机打包JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LWJGL创建了一个Java游戏,它需要一些原生文件。它在Eclipse中运行良好。我想将.dll文件包含在JAR文件中,但每次尝试时,LWJGL都找不到本机。我已经尝试过使用jarsplice或fatjar,但无济于事。我知道我的Minecraft也是使用LWJGL编程的,它以某种方式设法从另一个文件夹加载本机。

I have made a Java game using LWJGL, which requires some native files. It all works fine in Eclipse. I want to include the .dll files inside a JAR file, but everytime I try, LWJGL can't find the natives. I have already tried using jarsplice or fatjar, but to no avail. I know minecraft is also programmed using LWJGL, and it somehow manages to load the natives from another folder.

有没有办法将本机文件打包成JAR文件并让第三方图书馆,如LWJGL访问它们?如果没有,我将如何处理从外部文件夹加载它们?

Is there a way to package native files into a JAR file and let a 3rd party library, like LWJGL access them? If not, how would I approach loading them from an external folder?

编辑:它在某种程度上与JAR文件所在目录中的本机一起使用。不过,我仍然会想要一些解释,也许还有其他一些方法。

Somehow it worked with the natives in the same directory as the JAR file. I would still like some explanation and perhaps some other methods, though.

推荐答案

几周前我刚刚遇到这个问题。唉,我没有链接,但我发现你不能引用存储在jar文件中的本机文件。你必须在引用它们之前以编程方式提取它们,或者你必须将它们与jar文件一起安装。

I just ran into this a few weeks ago. Alas, I do not have links, but I found that you cannot reference native files stored inside of a jar file. You have to either programatically extract them before you reference them, or you have to install them alongside your jar file.

我选择了第二个选项并让Eclipse打包整个集合到一个zip文件中进行分发。

I went with the second option and just have Eclipse pack the whole collection into a zip file for distribution.

对于第一个选项,一个要查看的地方将是JNA的源代码。他们在他们的jar文件中发送dll的/二进制文件,然后根据需要提取。

For the first option, one place to look would be the source code for JNA. They ship dll's/binaries inside their jar file and extract then on demand.

这篇关于Eclipse:使用本机打包JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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