简体   繁体   中英

My Java Slick game Jar file will not open

I have made a simple GUI using slick and lwjgl, I am using eclipse and have imported my jars, natives and images to my Java build path, I export my code as a jar file and get a jar file on my desktop, I try open it with SE Binary and it loads for a little while then nothing happens.

It may have something to do with how I have imported them into my build path, I will try explain, I have inside my Java project two additional folders that I have created, they are lib and res, res holds all of my images and lib holds two other folders called jars and natives, jars holds two jar files (slick and lwjgl) and natives holds 4 other folders (windows, linux, mac, solaris natives), I imported my 2 jar files into the build path using the add jars option, I then imported my res file using the add class folder option and after that using the same option I imported the lib folder, I then exported it and now it doesn't open.

It may be worth mentioning that before I export my jar files from eclipse I get the following pop up message: The operation repacks referenced libraries.

It seems that lwjgl can't use the native libraries when they are inside a jar archive.

The solution is to unpack your natives folder either into some install directory or a temporary directory. Then, before you use any lwjgl function, you need to set the new path to the natives. For example with the files unpacked in "lib/native" I use

System.setProperty("org.lwjgl.librarypath", (new File("lib/native")).getAbsolutePath());
System.setProperty("java.librarypath", (new File("lib/native")).getAbsolutePath());
System.setProperty("net.java.games.input.librarypath", (new File("lib/native")).getAbsolutePath());

This seems to be the easiest solution. For example minecraft (which uses lwjgl) unpacks the natives to "%appdata%.minecraft\\bin\\natives" (on windows, ~ instead of %appdata% on linux).

Edit: a very related wiki page: http://lwjgl.com/wiki/index.php?title=Distributing_Your_LWJGL_Application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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