Eclipse:使用本机打包 JAR

发布于 2024-12-11 21:37:50 字数 317 浏览 0 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃扇骨 2024-12-18 21:37:50

我几周前才遇到这个问题。唉,我没有链接,但我发现您无法引用存储在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文