Eclipse:使用本机打包 JAR
我使用LWJGL制作了一个Java游戏,这需要一些本机文件。在 Eclipse 中一切都运行良好。我想将 .dll 文件包含在 JAR 文件中,但每次我尝试时,LWJGL 都无法找到本机。我已经尝试过使用 jarsplice 或 fatjar,但没有成功。我知道我的世界也是使用 LWJGL 编程的,并且它以某种方式设法从另一个文件夹加载本机。
有没有办法将本机文件打包成 JAR 文件并让 3rd 方库(例如 LWJGL)访问它们?如果没有,我将如何从外部文件夹加载它们?
编辑:不知何故,它与 JAR 文件位于同一目录中的本机一起工作。不过,我仍然想要一些解释,也许还有其他一些方法。
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.
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?
EDIT: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我几周前才遇到这个问题。唉,我没有链接,但我发现您无法引用存储在 jar 文件内的本机文件。您必须在引用它们之前以编程方式提取它们,或者必须将它们与 jar 文件一起安装。
我选择了第二个选项,让 Eclipse 将整个集合打包到一个 zip 文件中进行分发。
对于第一个选项,可以查看 JNA 的源代码。他们将 dll/二进制文件放入其 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.
I went with the second option and just have Eclipse pack the whole collection into a zip file for distribution.
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.