A gradle.build
script demonstrating the packaging of an LWJGL-dependent project as either a standalone jar or a Windows executable.
The "Space Invaders" demo LWJGL program is included so as to provide a full-fledged sample.
The following Gradle tasks are available:
run
: build an application jar and run it. Mostly useful to ensure everything is in place.myCapsule
: build a standalone jar:build/libs/[ProjectName]-capsule.jar
.launch4j
: build a Windows executable:build/launch4j/[ProjectName].exe
.
Both the jar and executable can be launched "as is". In particular, the Capsule framework takes care of setting up java.library.path
so as to link to the native LWJGL libraries.
- Copy
build.gradle
at the root of your project. - Ensure that your project layout follow maven/gradle conventions (code in
src/main/java
, resources insrc/main/resources
). - If under Eclipse, convert your project to a Gradle one (see "Eclipse setup" below).
- At least adjust the value of
mainClass
, have a look at other variables. - Use
myCapsule
orlaunch4j
task to package your code.
I did not add the MIT license at the beginning of the script to keep things simple, but if you use it please consider making a reference to this project page if at all reasonable.
To test this under Eclipse:
- Install Eclipse Gradle tooling.
- "
Import as general project
" fromGit Repositories
view. - Right click on project, "
Configure > Convert to Gradle Project
". - Try "
Ctrl+Alt+Shift+R
>run
" to ensure that the project is properly set up.
This script builds upon the Capsule, gradle-capsule-plugin, gradle-natives and launch4j tools.
It ships with the "Space Invader" LWJGL example game, on which I do not claim any right.
The following articles were used as starting points: Going Native with Gradle, An Opinionated Guide to Modern Java, Part 2.