[Solved] Loading LWJGL natives - (Running a .jar in linux)

Hello, I just wondered if anyone could help me with this :clue:. I usually develop on Win 8 but want to make sure my jar files run on Linux also.

I can make a Display using LWJGL and run it on eclipse and export a .jar to run on windows and everything runs as expected. If I take the same project and run it in eclipse on Linux Mint it runs just the same, but it will not run as a .jar file. (I can even export the jar file in Linux Mint and then run it on Windows)

I have the natives in a folder called “natives” (for each OS in the same folder) in the same directory as the game.jar.

I use

System.setProperty("org.lwjgl.librarypath",new File("natives").getAbsolutePath());

Or

System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/natives/");

to load the natives. I give the permissions to the Jar file to run and use the OpenJDK 7.
Does anyone know what I can do to get it working on both windows and Linux?

Cheers :wink:

I just fired up a Linux Mint VM and using both ways worked. Are you sure the Linux natives are included?

I just re-downloaded to be sure. But as it works in eclipse in Linux mint I thought that probably couldn’t be the problem. Also libGdx works fine as well, which is really confusing.

Well I don’t know why it wont work, but for now I just keep coding in Windows and worry about running on linux later, my priority is running on Windows/Android first anyway so I’m not too worried. :clue:

Could you send me a test example that doesn’t work on Linux?

Ok I sent you the file but in the meantime I found out that I can run it if I open a terminal and type

java -jar Game.jar

::slight_smile:
I didn’t know this is how to open jar files on linux as I’m a complete linux noob. I was expecting to be able to write click and ask to open with the OpenJDK7 as I can for other Jar files.
So the thing is, it does work but I don’t think it is really easy to do for beginners(to linux), such as myself and I want my programs to open in a very user friendly way. Is there a way of making a single click file that would open the program for a non developer?

Two answers here:

  1. This answer is only for your own usage. It makes using .jar files easier:
    [this guide is for KDE]
    [x] Right-click on any jar file in the file explorer (dolphin for me)
    [x] Click on the ‘File type options’-button
    [x] Click ‘Add’
    [x] Type in ‘java -jar’, Check ‘Run in terminal’ if you want it to run in terminal… (obviously)
    Hope this helps for you, I’ve seen this techneque fail somehow… :frowning:

  2. How to distribute .jar files, to make them available to other linux users:
    [x] create a new file named ‘run.sh’ in the same directory as your .jar file
    [x] open it with a text editor
    [x] write this into the file:


#!/bin/bash
java -jar YourJarName.jar

[x] close the editor, right-click the file and click ‘Properties’. You might search a little on GNome / Unity, but on KDE it’s like this: Under the tab ‘Permissions’ check ‘is executable’

If you now double-click the .sh file, the jar starts.

I’m sorry. There no other way. It’s pretty ugly in linux atm.

Too many environments fail to set up the associations for .jar, or change them capriciously (read: Windows) to rely on an executable .jar as your sole distribution mechanism. At the very least, you need to ship a wrapper script, and if you want it to be polished, make it a genuine clickable installer.

Yeah I can confirm that it doesn’t work when double clicked. Apparently neither did my test jar. It only works from the command line. Either way, it’s best not to distribute a JAR file and do like the others said :slight_smile:

You could also use JarSplice, will wrap your jar and natives into a single shellscript (.sh) for linux, exe for windows and an .app for OS X.

@matheus23 Thanks your suggestions. I can’t do the first one as the options aren’t there in linux mint. The second one is just what I need 8). When I double click the script I get the options to ‘Run in Terminal’ ‘Display’ Cancel’ or ‘Run’ which is actually better then just running the jar.
I hadn’t considered that actually having the terminal would be a useful, now I can have some useful feed back at run time from the final program and not just in the IDE. ;D