Search code examples
javaintellij-ideajarnativelwjgl

Distribute a Java LWJGL program


I'm currently learning LWJGL on Intellij Idea. I can run the official HelloWorld code with my IDE's built-in run tool but I would love to compress my code into a jar file.

I followed this wiki with my files I downloaded from here (bundle zip).

I created a jar build system via Intellij Idea's "Artifacts" and can run a simple program but still not a LWJGL one.

I'm a bit lost with native jars which I need to include.

Do I need to include native jars as a library, do I need to copy them next to my jar?

Please explain me, a beginner, to build this jar. The less tools such as gradle I use, the better, I want to learn.


Solution

  • I managed to build my jar with a terminal.
    Everything I will explain works in a single folder, no subfolder for packages etc.. (for simplicity)

    You will need a minimal ZIP bundle from here, including the natives corresponding to the OS(s) you want to distribute for.

    • Compile with javac -cp ".;./lwjgl.jar;./lwjgl-opengl.jar;./lwjgl-glfw.jar" Main.java (replace ; by : if you are on unix system)

    • Create a manifest file myManifest.txt containing:

    Manifest-Version: 1.0
    Class-Path: ./lwjgl.jar ./lwjgl-glfw.jar ./lwjgl-opengl.jar ./lwjgl-natives-windows.jar
    Main-Class: Main
    
    

    Do not forget the blank line at the end.

    • Jar it with jar -cvfm MyJar.jar .\myManifest.txt .\Main.class

    You can now run your jar by double clicking it, you will need all .jar files in this folder, .java, .class and manifest files can be removed.