简体   繁体   English

用项目导出LWJGL原生代码? (IntelliJ IDEA)

[英]Export LWJGL natives with project? (IntelliJ IDEA)

I'm currently writing a program dependent on LWJGL. 我目前正在编写一个依赖于LWJGL的程序。 Adding the library to my project was easy enough, but I'm having trouble exporting my project as a standalone JAR that the user can simply double-click for a finished product. 将库添加到我的项目中很简单,但是我将项目导出为独立的JAR,用户只需双击完成的产品即可。

WHAT I HAVE TRIED: 我做了什么:

  • File -> Project Structure... -> Modules -> Dependencies tab -> Add -> Jars or directories -> (insert path to natives here) -> Option "classes" in the dialog. 文件 - >项目结构... - >模块 - >依赖项选项卡 - >添加 - >罐子或目录 - >(在此处插入本地路径) - >对话框中的选项“类”。 -> Check the box under "Export" - >选中“导出”下的框

DESIRED RESULT: A runnable JAR with no dependency on the command line to open properly. 渴望的结果:一个可运行的JAR,不依赖于命令行来正常打开。 Other JARs and directories being included with my project are fine, but I'd like IntelliJ to export them WITH my project automatically if possible, so that I don't have to manually drag the needed files into the output directory and make a script to run the JAR with the correct natives. 我的项目中包含的其他JAR和目录都很好,但是我希望IntelliJ尽可能自动地将它们导出到我的项目中,这样我就不必手动将所需的文件拖到输出目录中并创建一个脚本使用正确的本机运行JAR。


I'm very new to IntelliJ, coming from Eclipse (although I never had to do this in Eclipse, either), and am still coming to grips with the new (to me) terminology used by the program. 我是IntelliJ的新手,来自Eclipse(尽管我从来没有在Eclipse中这么做过),而且我仍然在掌握程序使用的新(对我而来)术语。 I'm sure there is a very easy solution I am just overlooking. 我确信有一个非常简单的解决方案,我只是忽略了。 Thank you in advance. 先感谢您。

我能够通过使用JarSplice制作包含其中的本机的Windows EXE来解决这个问题。

I also use IntelliJ, and I've had a similar issue. 我也使用IntelliJ,我也有类似的问题。 If you put your natives into a folder somewhere near you, use something like the following at the start of your public static void main method: 如果您将本机放入您附近的文件夹中,请在public static void main方法的开头使用以下内容:

System.setProperty("org.lwjgl.librarypath", PATH_TO_LIBS);

Note that you may have to prepend System.getProperty("user.dir") to the front of PATH_TO_LIBS , I'm not certain. 请注意,您可能必须将System.getProperty("user.dir")PATH_TO_LIBS的前面,我不确定。

ADDENDUM: You said you'd like any additional files to automatically be created with your jar? ADDENDUM:你说你想要用你的jar自动创建任何其他文件吗? Check out IntelliJ's Artifacts. 查看IntelliJ的工件。 Go to project settings, select artifacts, and add one with the plus button. 转到项目设置,选择工件,然后使用加号按钮添加工件。 Once you get an artifact added you can mess around with the file structure on the side, adding in other folders (such as the natives folder, or a resources folders). 一旦你获得了一个工件,你就可以在一边乱用文件结构,添加其他文件夹(例如natives文件夹或资源文件夹)。 Once you're done there, you can click Build>Artifacts and it automatically packages them for you, and puts them in a directory (which you can specify on the Artifact window). 完成后,您可以单击Build> Artifacts并自动为它们打包,并将它们放在一个目录中(您可以在Artifact窗口中指定)。

I don't know what IntelliJ is so I'm not sure how helpful this will be, but I did do something like this with LWJGL a couple of years ago. 我不知道IntelliJ是什么,所以我不确定它会有多大帮助,但几年前我用LWJGL做了类似的事情。

LWJGL depends on native libraries, and the operating system depends on loading those from real native files. LWJGL依赖于本机库,操作系统依赖于从真实本机文件加载。 You can't load them from inside a jar. 你无法从罐子里装载它们。 So, you can put them in the jar, but you'll have to write some code (which runs before you try to call any LWJGL stuff) which will extract the needed native(s) from the jar at run time and save them in the system temporary directory (or wherever) then load them with System.load . 所以,你可以将它们放在jar中,但是你必须编写一些代码(在你尝试调用任何LWJGL之前运行它们),这些代码将在运行时从jar中提取所需的native(s)并将它们保存在系统临时目录(或任何地方)然后使用System.load加载它们。

Then you have to remove/comment out the normal library loading code from org.lwjgl.Sys (the functions doLoadLibrary and loadLibrary ). 然后你必须从org.lwjgl.Sys (函数doLoadLibraryloadLibrary )中删除/注释掉正常的库加载代码。 That should do it. 应该这样做。

Edit: A similar question is here: How to make a JAR file that includes DLL files? 编辑:类似的问题在这里: 如何制作包含DLL文件的JAR文件?

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

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