0

I'm currently writing a program dependent on 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.

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. 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.


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. I'm sure there is a very easy solution I am just overlooking. Thank you in advance.

2mac
  • 1,609
  • 5
  • 20
  • 35

3 Answers3

1

I was able to get around the issue by using JarSplice to make a Windows EXE that includes the natives within.

2mac
  • 1,609
  • 5
  • 20
  • 35
1

I also use IntelliJ, and I've had a similar issue. 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:

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.

ADDENDUM: You said you'd like any additional files to automatically be created with your jar? Check out IntelliJ's Artifacts. 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). 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).

DeadlyFugu
  • 152
  • 5
0

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.

LWJGL depends on native libraries, and the operating system depends on loading those from real native files. 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.

Then you have to remove/comment out the normal library loading code from org.lwjgl.Sys (the functions doLoadLibrary and loadLibrary). That should do it.

Edit: A similar question is here: How to make a JAR file that includes DLL files?

Community
  • 1
  • 1
Boann
  • 48,794
  • 16
  • 117
  • 146