[Solved] Distributing runnable files

Ello JGO,

I want to throw my code into a runnable file, I’ve tried Launch4j, which looks fine. But I don’t understand half of what I should be filling in. And I figure it wouldn’t be a bad thing to know how to make an executable file myself. Is there any place I can find a detailed description of why and what things are/do and where to find this info on my project?

Some specifics:
Project in eclipse.
Build path libs: JRE 7, lwjgl.jar, lwjgl_util.jar
My OS: windows 8 64bit

Excuses if this is a redundant post, just point out to me the search terms you used so I can wallow in self-shame and be better at searching next time. Because I haven’t found anything that seems like what I’m looking for using the search.

[Edit:] Eclipse’s export as executable jar & correcting directory hierarchy got the job done. The result for the curious: http://149.210.136.93/~ramus/shared/varelseExecJar.rar

Eclipse has the Function to make a runnable .jar file no? and for LWJGL you could just put the .dlls beside the .jar for beginning

Hmm, yes, that seems to work. (Again I was overcomplicating things) Only now it can’t find files (shaders, images) because they’re not in the same directories anymore. Do you know an export-proof way of loading files?

Maybe give JarSplice a try, might be easier to use :slight_smile: it also lets you handle natives by including them in the jar/executable.

Another option is to create a .bat file or something similar that they can use to run the game (So that if there’s anything else you might need to do to set it up you can do so in the .bat). That’s the route I turned to when there were issues with getting anything I ran to actually work.

Ok, I got my proverbial “shit” straightened out.

I had no real concept of the term classpath and thus my directory structure in eclipse was like this;

-name of project-
--src
---package
----foo.java
----bar.java
--lib
--res
---images
----image.png
----pic.png
---shaders
----fragment.glsl
----vertex.glsl

using this line to load the resources when testing the code in eclipse.

BufferedReader reader = new BufferedReader(new FileReader("res/shaders/fragment.glsl"));

When it should have been like this:

-name of project-
--src
---package
----foo.java
----bar.java
---res.images
----image.png
----pic.png
---res.shaders
----vertex.glsl
----fragment.glsl
--lib

And use this to load the resources.

InputStream input = Renderer.class.getClass().getResourceAsStream("/res/shaders/fragment.glsl");
BufferedReader reader = new BufferedReader(new InputStreamReader(input));

As for distributing everything, this should fix my issues and un-complicate things for me. Thanks for the answers everyone! They should get me on my way just fine.

Okay, here’s how I do it:
loading stuff with ("./texture/img1.png") as url for example i locate a folder called “texture” next to the jar and put the files inside it, works for me but they aren’t in the jar anymore :slight_smile:

That’s also an alternative :stuck_out_tongue:

Your file give me this error. I’m using Linux Xubuntu 12.04 (xfce 4.8 ).

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
ricardo@RicardoPc:~/Desktop/varelseExecJar$ java -jar /home/ricardo/Desktop/varelseExecJar/varelse.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1874)
	at java.lang.Runtime.loadLibrary0(Runtime.java:849)
	at java.lang.System.loadLibrary(System.java:1087)
	at org.lwjgl.Sys$1.run(Sys.java:73)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
	at org.lwjgl.Sys.loadLibrary(Sys.java:95)
	at org.lwjgl.Sys.<clinit>(Sys.java:112)
	at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
	at varelse.Renderer.setupOpenGL(Renderer.java:179)
	at varelse.Renderer.<init>(Renderer.java:65)
	at varelse.Main.<init>(Main.java:24)
	at varelse.Main.main(Main.java:19)
	... 5 more

Also, you should always use your resources folder (anything external you will use) as source folder. With this enabled, eclipse can include all your stuff when compiling and create the right folders.
Right click on your folder >> build path >> Use as source folder.

Sorry, I only put in the natives for windows. I tried it out on mac with mac natives but the error log wasn’t very helpful (should read through it again, huge thing, hope to find a stacktrace). I don’t have a linux machine to test on, and thus no linux version D:

Thanks for the eclipse tip! I’ll try that too :wink:

Go [icode]File -> Export -> Runnable Jar File[/icode]

Then Use JarSplice and add all the natives.

Linux is free. You can install a small distro on a virtual machine or maybe boot with your pen.
Also, I forget to mention.
If you use your folder as recourse folder, you can access all your files just typing /foldername/your_file and you don’t need to change all files path after compiling. Eclipse should create all correct folders and files.