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

ArticlesTechnical guides7 min read

Building an L2 Server with Apache Ant (build.xml)

Many L2J-family packs are still built with Ant. This guide covers installing JDK 17/21 and Ant, running build.xml targets, how a build file is structured and the most common errors.

If the source root contains a build.xml file, the project is built with Apache Ant. Many L2J packs and their derivatives work this way, especially datapacks and projects that have been developed for years. You set up the environment once, and after that a build is a single command.

What you need

ComponentVersionNotes
JDK17 or 21, 64-bitthe required version is set in build.xml: the release or source/target attributes of the javac task
Apache Ant1.10.xold versions 1.7–1.9 do not work well with current JDKs
Gitcurrentto get the sources

Step 1. JDK and JAVA_HOME

  1. Install JDK 17 or 21 (64-bit).
  2. Create a system variable JAVA_HOME (Win+R > sysdm.cpl > Advanced > Environment Variables) pointing to the JDK root folder, for example C:\Program Files\Java\jdk-21. No \bin at the end!
  3. Add %JAVA_HOME%\bin as a separate entry to the Path variable.
No need to copy tools.jarOld guides told you to copy tools.jar from the JDK into the JRE folder. Since Java 9 that file no longer exists and a separate JRE is not needed: Ant finds the compiler by itself as long as JAVA_HOME points to a JDK.

Step 2. Install Ant

  1. Download the binary archive apache-ant-1.10.x-bin.zip from the official Apache Ant website.
  2. Unpack it to a folder without spaces or non-Latin characters, for example C:\tools\ant (it should contain the bin and lib folders).
  3. Create a system variable ANT_HOME set to C:\tools\ant and add %ANT_HOME%\bin to Path.
  4. Check the installation in a new terminal window:
ant -version
Apache Ant(TM) version 1.10.x compiled on ...

On Ubuntu a single command is enough: sudo apt install ant openjdk-21-jdk. To build from an IDE you do not even need a separate installation, since Ant is built into IntelliJ IDEA and Eclipse.

Step 3. Get the sources

Clone the pack repository with Git (details in the IDE and Git guide). The core and the datapack are often separate projects, each with its own build.xml:

cd D:\l2
git clone CORE_REPOSITORY_URL gameserver
git clone DATAPACK_REPOSITORY_URL datapack

If the project is still kept in SVN, the command is similar: svn checkout URL folder.

Step 4. See which targets build.xml has

A target is a named set of actions: clean, compile, package. ant -p lists the targets with their descriptions:

cd D:\l2\gameserver
ant -p

Buildfile: D:\l2\gameserver\build.xml
Main targets:

 clean    Remove build output
 compile  Compile sources
 dist     Build the server into build/dist
Default target: dist

Step 5. Build

CommandWhat it does
antruns the default target (the default attribute of the project tag)
ant distruns a specific target
ant clean distruns several targets in order: clean, then a full build
ant -f D:\l2\datapack\build.xmlbuilds using a file from another folder
ant -v distverbose output for troubleshooting
ant -logfile build.log distsaves the build output to a file

A successful build ends with BUILD SUCCESSFUL and Total time. The output usually appears in the build/ folder: compiled classes, the core jar, a ready distribution and/or a zip archive. The exact paths are defined by the properties at the top of build.xml and by the distribution target.

Build orderDatapack scripts are often compiled against the core jar. So build the core (login and gameserver) first, then the datapack, if its build.xml refers to the core.

How build.xml works: an example

A simplified but working build file for a game server:

<?xml version="1.0" encoding="UTF-8"?>
<project name="L2GameServer" default="dist" basedir=".">
    <description>Game server build</description>

    <property name="src" location="java"/>
    <property name="lib" location="lib"/>
    <property name="build" location="build"/>
    <property name="build.classes" location="${build}/classes"/>
    <property name="build.dist" location="${build}/dist"/>

    <path id="classpath">
        <fileset dir="${lib}" includes="*.jar"/>
    </path>

    <target name="clean" description="Remove build output">
        <delete dir="${build}"/>
    </target>

    <target name="init">
        <mkdir dir="${build.classes}"/>
        <mkdir dir="${build.dist}/libs"/>
    </target>

    <target name="compile" depends="init" description="Compile sources">
        <javac srcdir="${src}" destdir="${build.classes}" classpathref="classpath"
               release="21" encoding="UTF-8" debug="true" includeantruntime="false"/>
    </target>

    <target name="jar" depends="compile">
        <jar destfile="${build.dist}/libs/gameserver.jar" basedir="${build.classes}"/>
    </target>

    <target name="dist" depends="jar" description="Build the server into build/dist">
        <copy todir="${build.dist}/libs">
            <fileset dir="${lib}" includes="*.jar"/>
        </copy>
        <copy todir="${build.dist}">
            <fileset dir="dist"/>
        </copy>
        <zip destfile="${build}/gameserver.zip" basedir="${build.dist}"/>
    </target>
</project>
  • project default="dist": the target that runs when you type ant without arguments;
  • property: variables holding paths, referenced as ${build};
  • path id="classpath": the libraries from lib/ needed for compilation;
  • depends: target dependencies; dist calls jar, jar calls compile, compile calls init;
  • javac: release is the Java version the code is compiled for, encoding is the source encoding, includeantruntime="false" keeps the libraries of Ant itself out of the classpath;
  • jar, copy, zip: packaging the code and assembling the distribution from the libraries and the dist folder with configs and startup scripts.

Common errors

MessageCause and fix
'ant' is not recognized as an internal or external command%ANT_HOME%\bin is not in Path, or the terminal was opened before the variables were changed
Unable to find a javac compiler, Perhaps JAVA_HOME does not point to the JDKJAVA_HOME points to a JRE or to the bin folder; set it to the JDK root folder
unmappable character (0xC2) for encoding UTF-8, garbled stringsthe sources are in windows-1251 but the compiler reads them as UTF-8 (the default since JDK 18). Set encoding="windows-1251" on javac or convert the files to UTF-8
package ... does not exist, cannot find symbola library is missing from lib/, or the core the datapack depends on has not been built
release version 21 not supported, invalid target releasethe JDK is older than the project requires; check java -version and JAVA_HOME
Source option 7 is no longer supported. Use 8 or later.an old build.xml with source/target 1.6 or 1.7: raise them to 8 or higher or replace them with the release attribute. Very old code may need fixes or JDK 8
class file has wrong version 65.0, should be 61.0a library was built for Java 21 (65) but you are building on Java 17 (61): use JDK 21
Target "dist" does not exist in the projectthere is no such target; list the targets with ant -p
java.lang.OutOfMemoryError during compilationgive it more memory: set ANT_OPTS=-Xmx1g or the fork="true" memorymaximumsize="1g" attributes on javac

A BUILD FAILED message always includes the path to build.xml and a line number. Start with the first compiler error printed above it.

Building from the IDE

  • IntelliJ IDEA: View > Tool Windows > Ant, click + and choose build.xml, then double-click a target. The JDK for the build is set via the Properties button in the Ant window > Execution tab > Run under JDK.
  • Eclipse: right-click build.xml > Run As > Ant Build..., tick the targets on the Targets tab and choose Separate JRE with the right JDK on the JRE tab.

Modern alternatives: Maven and Gradle

New projects usually use Maven (a pom.xml file, see the Maven guide) or Gradle (build.gradle or build.gradle.kts). Both download dependencies automatically, so libraries do not have to be stored in a lib/ folder. A Gradle project builds with its bundled wrapper, no installation required: gradlew build on Windows or ./gradlew build on Linux, with the output in build/libs/. There is no need to migrate a working ANT build: if it builds reliably, Ant is still a perfectly good choice.

Need a pack that is ready to build, or a complete project set up for you? See our server packs and turnkey projects.

Published 15 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.