scripts lineage2  :::  Server Packs lineage 2 — best scripts for admin servers   :::  Projects lineage Turnkey
l2-scripts.com  Freelance Studio

ArticlesTechnical guides6 min read

Building an L2 Server with Maven

Step by step: installing JDK 17/21 and Maven, checking the environment, running mvn clean package, finding the built server and fixing typical build errors.

Maven is used by packs that have a pom.xml file in the root folder. If there is a build.xml instead, the project is built with ANT (see the ANT guide); if there are build.gradle and gradlew, it is a Gradle project and you build it with gradlew build.

What you need

ComponentVersionNotes
JDK17 or 21, 64-bitcheck pom.xml for the required version: maven.compiler.release or source/target
Maven3.9 or newernot needed if the project ships the mvnw wrapper
Internet accessfor the first buildMaven downloads dependencies into the local repository

Step 1. Install the JDK and set JAVA_HOME

  1. Install JDK 17 or 21 (64-bit). You need a full JDK with the compiler, not just a runtime.
  2. Open Win+R > sysdm.cpl > Advanced > Environment Variables. Under System variables create JAVA_HOME pointing to the JDK root folder without \bin, for example C:\Program Files\Java\jdk-21.
  3. Add %JAVA_HOME%\bin as a separate entry to Path (many JDK installers do this for you).
  4. Open a new terminal window (windows that are already open do not see new variables) and check: java -version and javac -version.

Step 2. Install Maven

  1. Download the binary archive apache-maven-3.9.x-bin.zip from the official Apache Maven website.
  2. Unpack it to a folder without spaces or non-Latin characters, for example C:\tools\maven.
  3. Add C:\tools\maven\bin to Path.
  4. In a new terminal window run mvn -v. Look at the Java version line: Maven must run on the JDK your pack needs.

Sample output:

mvn -v
Apache Maven 3.9.9
Maven home: C:\tools\maven
Java version: 21.0.5, runtime: C:\Program Files\Java\jdk-21
Maven wrapper and LinuxIf the project contains mvnw and mvnw.cmd, you do not have to install Maven at all: the wrapper downloads the right version itself. Run mvnw.cmd clean package on Windows or ./mvnw clean package on Linux. On Ubuntu the JDK and Maven come from the standard repositories: sudo apt install openjdk-21-jdk maven.

Step 3. Build

  1. Open a terminal in the project folder, where the root pom.xml is. In File Explorer you can type cmd into the address bar or choose Open in Terminal from the folder's context menu.
  2. Start the build with the command below: clean removes the output of the previous build, package compiles the code and packs it into a jar/zip.
  3. The first build downloads dependencies into %USERPROFILE%\.m2\repository and may take several minutes; later builds are faster.
  4. Wait for BUILD SUCCESS. On failure Maven prints BUILD FAILURE with the cause above it: read the first error, not the last one.
cd D:\l2\source
mvn clean package

# skip running the tests
mvn clean package -DskipTests

# build only the gameserver module and the modules it depends on
mvn clean package -pl gameserver -am
Command or optionWhat it does
mvn cleandeletes the target/ folder
mvn compilecompiles the code only
mvn packagecompiles and packs into a jar/zip
mvn installthe same plus a copy in the local repository; needed when modules depend on each other and are built separately
-DskipTeststests are compiled but not run
-Dmaven.test.skip=truetests are neither compiled nor run
-ooffline mode: only dependencies from the local repository
-Uforce a re-check of dependencies in remote repositories
mvn dependency:treeprints the dependency tree
PowerShell and options with dotsIn PowerShell, wrap options like -Dname.with.dots=value in quotes: mvn clean package "-Dmaven.test.skip=true". Otherwise PowerShell splits them at the dot and Maven fails. In cmd no quotes are needed.
About mvn assembly:assemblyOld instructions use mvn assembly:assembly. That goal has been removed from current versions of the assembly plugin: if the distribution is configured in pom.xml, the archive is created automatically during the package phase.

Where the output goes

  • Each module's target/ folder holds the compiled jar (for example, the game server or login server core).
  • If the assembly plugin is configured in pom.xml, you will also find a ready *.zip archive or a distribution folder with libraries, configs and startup scripts.
  • In multi-module projects the final distribution is often built by a separate module, so look in that module's target/. The file name is set in pom.xml (finalName and the assembly settings).
A jar is not a server yetTo run the server you also need the libraries, configs and datapack. If the build produces only a jar, use it to replace the old jar in your existing server folder, after making a backup.

Memory for the build

The default memory settings are usually enough. If a large project fails with OutOfMemoryError, give Maven more memory through the MAVEN_OPTS variable (old guides misspelled it as MAVEN_OPT):

  • cmd: set MAVEN_OPTS=-Xmx2g;
  • PowerShell: $env:MAVEN_OPTS = "-Xmx2g";
  • permanently for the project: a line -Xmx2g in the .mvn/jvm.config file in the project root.

Building from the IDE

  • IntelliJ IDEA: Maven tool window (on the right) > your project > Lifecycle, double-click clean, then package. The Skip Tests button on the tool window toolbar turns tests off. The JDK used by Maven is set in Settings > Build, Execution, Deployment > Build Tools > Maven > Runner > JRE.
  • Eclipse: right-click the project > Run As > Maven build..., enter clean package in Goals and tick Skip Tests if needed. Pick the right JDK on the JRE tab.

More about working with the project in an IDE is in the IntelliJ IDEA, Eclipse and Git guide.

Common errors

MessageCause and fix
'mvn' is not recognized as an internal or external commandthe Maven bin folder is not in Path, or the terminal was opened before the change; open a new window
The JAVA_HOME environment variable is not defined correctlyJAVA_HOME points to the bin folder, to a JRE or to a path that does not exist; it must be the JDK root folder
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?Maven runs on a JRE: install a JDK and fix JAVA_HOME
release version 21 not supported, invalid target release: 17the JDK is older than the project requires; check the Java version line in mvn -v
Could not resolve dependencies, Could not transfer artifactno access to the dependency repository (internet, proxy) or the library is not in any public repository; see the next section
was cached in the local repository, resolution will not be reattempteda failed download was cached: build with -U or delete that library's folder in .m2\repository
unmappable character for encoding UTF-8the sources are not UTF-8: set their real encoding in the project.build.sourceEncoding property or convert the files to UTF-8
OutOfMemoryError: Java heap spaceincrease MAVEN_OPTS (see above)
There are test failurestests failed: fix them or build with -DskipTests

Building offline and local libraries

An offline build (mvn -o) works only if every dependency is already in the local repository. You can download them in advance with mvn dependency:go-offline on a machine with internet access. If the project uses a jar that is not published in any repository, install it into the local repository by hand:

mvn install:install-file -Dfile=lib\some-lib.jar -DgroupId=local.libs -DartifactId=some-lib -Dversion=1.0 -Dpackaging=jar

After that pom.xml can reference the library with the same groupId, artifactId and version. How to run the built server on Windows is covered in the Windows setup guide. Ready-made packs with source code are in the server packs section.

Published 23 October 2026

Read also

Need help with your server?

We help with the server pack, setup, protection and launch — one-off or on an ongoing basis.

L2‑Scripts newsletter

Get L2‑Scripts news by email

And 5% off all studio services while you stay subscribed.

The discount is valid while you are subscribed: when ordering, tell the manager your subscription address on Telegram.