# How do I pack my game LWJGL game into a single executable JAR with Maven?

I am trying to use Maven to manage building my LWJGL projects. The entire project needs to be packed into a single executable jar, dependencies, natives and resources included, so that can be easily distributed. I have been using JarSplice to do this until now.

Is it possible to do the same with Maven?

My attempts thus far have failed: either the main class/natives could not be located or OpenAL would crash when I tried to execute the jar file.

My current pom.xml is below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>Sidian</groupId>
<artifactId>LWJake2</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>LWJake2</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<mainClass>Main</mainClass>

<lwjgl.version>2.9.3</lwjgl.version>
</properties>

<dependencies>
<dependency>
<groupId>org.lwjgl.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>\${lwjgl.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>


• Van you add you pom.xml to the question? – Verhagen Oct 19 '15 at 17:25
• This has nothing to do with GameDevelopment at all (You could replace LWJGL with any other lib and still have the same problem). But something to google for: maven uber jar – tkausl Oct 20 '15 at 13:45
• Thank you for answering my game related question, I will be sure to check it out – Blunderchips Oct 22 '15 at 7:40

## 1 Answer

This is the plugin you need

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>your.main.class.Here</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

• This answer would be even better if it explained why this answer works, or how the user can follow the strategy you used to determine the right markup to use. – DMGregory Jan 13 '19 at 13:45