Skip to content

1.2. Install

Ioannis Tsakpinis edited this page Dec 11, 2016 · 8 revisions

LWJGL is organized in modules. Each module is packaged as a collection of artifacts, where each artifact has the same name but a different classifier.

  • The artifact name for the LWJGL core module is just lwjgl.
  • The artifact name for a binding module is lwjgl-<binding>, for example lwjgl-opengl for the OpenGL module.

The artifacts based on classifier are:

  • No classifier: the compiled Java classes
  • sources: the Java sources
  • javadoc: the API documentation
  • natives-<platform>: the native shared libraries for the corresponding platform

Not all artifacts have natives and not all artifacts with natives are available on all platforms.

This design means that you only need to download the modules that are needed for your project.

Additional modules can be downloaded and added later on, if your needs change.

Downloading LWJGL - Using the build configurator

The LWJGL website provides a handy configurator for choosing which parts of the library you want to download. This section will contain a brief explanation of what the separate parts of this configurator do.

There are three separate release channels to choose from: Release, Stable and Nightly. Unless you know what you are doing, you should use Release, as it will be more stable.

The Mode selector allows you to choose how you want to download the library. If you plan on using an IDE or need the actual .jar files, choose ZIP Bundle. If you are going to use maven or gradle, choose the respective option to generate a build script.

Maven/Gradle is recommended during development. The zip bundle is recommended when creating a production build or installer for your application.

Natives are not required for compiling your project, but are needed for running it. Thus, you need to get natives for all the platforms you want to run your application on. Remember that you don't need to download natives for all platforms at once. You can download additional natives when you are ready to distribute your project.

If it is your first time using LWJGL, the Getting Started or Minimal OpenGL presets should be sufficient to get started with most tutorials. Alternatively, you can create a custom configuration and choose exactly which modules you want. Keep in mind that you can view the description of the different modules by ticking Show descriptions under Settings.

Extracting the natives (optional)

The LWJGL native shared libraries do NOT need to be extracted from their .jar files. The SharedLibraryLoader that is included with LWJGL does it automatically at runtime.

The SharedLibraryLoader extracts the natives once and reuses them from run to run. The natives are overridden only if a different LWJGL version is detected.

The extract directory can be customized with Configuration.SHARED_LIBRARY_EXTRACT_DIRECTORY and Configuration.SHARED_LIBRARY_EXTRACT_PATH.

Using the SharedLibraryLoader is optional. For example a custom installer for an application may extract the natives to a specific location. In such cases, the familiar options -Djava.library.path and -Dorg.lwjgl.librarypath (or Configuration.LIBRARY_PATH) are still fully supported.

Setting up your build tool or IDE

Gradle or maven

When using either gradle or maven you can simply copy the build script generated by the generator and use it to build your project. Note that when using gradle you probably want to prepend apply plugin: 'java' and apply plugin: 'application' to build.gradle.

IntelliJ IDEA

IDEA supports Gradle/Maven projects and makes it trivial to use them. For a custom configuration, follow these instructions:

  1. Go to our download page, select channel, select zip bundle, review the options and choose the bindings you're interested in, then click on Generate Bundle.
  2. When the download is complete, extract its contents in your project.
  3. In IntelliJ, go to Project Structure > Libraries > New Project Library. Add all LWJGL .jar files (classes+natives) to the library and add the library as a dependency to your project module(s). You do not need to extract the native libraries.
  4. If you also downloaded the sources, add the corresponding .jar files as sources to the LWJGL library. You do not need to download and attach the javadoc .jar files, IntelliJ generates javadoc directly from sources.

If you want to match the Maven/Gradle behavior exactly, you could create 2 separate libraries:

  • One with the class+source .jar files, make it a compile dependency of your module(s).
  • One with the natives .jar files, make it a runtime dependency of your module(s).

You can do this in the Project Structure > Modules > select a module > Dependencies tab, by changing the Scope of each dependency.

NetBeans

  1. Download LWJGL as a ZIP Bundle using the build configurator and extract the archive to somewhere you will be able to find it later.
  2. Inside Netbeans, under Tools > Libraries press New Library... in the bottom left corner.
  3. Name the library something sensible, such as "LWJGL 3.1.0" and press OK
  4. The center of the Library window should now contain options to configure the library.
  5. In the Classpath tab add all .jar files from the previously downloaded .zip file, excluding those containing sources or javadoc in their name
  6. (Optional) In the Sources tab add all .jar files with sources in their name. This will give you access to both documentation and the source code directly from NetBeans. Source can be viewed in the editor with Ctrl-Left click while hovering over a function or class that belongs to LWJGL.
  7. Create a new project by choosing File > New Project.... Choose Java | Java Application as the project type.
  8. Find your project in the project window (Can be opened with Ctrl-1). Right click on Libraries, choose Import, find the previously created library and select Import Library and then Add Library.
  9. Check if everything worked as intended by adding the following line to your main class and running the project: System.out.println(org.lwjgl.Version.getVersion());. This should print the version of LWJGL which you are using.

Other tools

If you are familiar with other tools or IDEs, feel free to add information about setting up LWJGL in them to this section. If you want to contribute, please make a post on the forum.