简体   繁体   English

Eclipse:使用本地人打包JAR

[英]Eclipse: Packaging a JAR with natives

I have made a Java game using LWJGL, which requires some native files. 我使用LWJGL制作了Java游戏,该游戏需要一些本机文件。 It all works fine in Eclipse. 在Eclipse中一切正常。 I want to include the .dll files inside a JAR file, but everytime I try, LWJGL can't find the natives. 我想将.dll文件包含在JAR文件中,但是每次尝试时,LWJGL都找不到本机。 I have already tried using jarsplice or fatjar, but to no avail. 我已经尝试过使用jarsplice或fatjar,但无济于事。 I know minecraft is also programmed using LWJGL, and it somehow manages to load the natives from another folder. 我知道我的世界也是使用LWJGL编程的,它以某种方式设法从另一个文件夹中加载本机。

Is there a way to package native files into a JAR file and let a 3rd party library, like LWJGL access them? 有没有一种方法可以将本机文件打包到JAR文件中,并让第3方库(例如LWJGL)访问它们? If not, how would I approach loading them from an external folder? 如果没有,我将如何从外部文件夹加载它们?

EDIT: Somehow it worked with the natives in the same directory as the JAR file. 编辑:以某种方式与JAR文件所在目录中的本机一起工作。 I would still like some explanation and perhaps some other methods, though. 不过,我仍然想要一些解释,也许还有其他方法。

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. las,我没有链接,但是我发现您无法引用jar文件中存储的本机文件。 You have to either programatically extract them before you reference them, or you have to install them alongside your jar file. 您必须以编程方式提取它们,然后再引用它们,或者必须将它们与jar文件一起安装。

I went with the second option and just have Eclipse pack the whole collection into a zip file for distribution. 我选择了第二个选项,只是让Eclipse将整个集合打包到一个zip文件中以进行分发。

For the first option, one place to look would be the source code for JNA. 对于第一种选择,一个要看的地方就是JNA的源代码。 They ship dll's/binaries inside their jar file and extract then on demand. 他们将dll /二进制文件运送到其jar文件中,然后按需提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM