Openfire: Building the Source

# Building the Source

## Introduction

This document provides detailed information for developers that wish to compile and make changes to the Openfire source code.

For additional developer resources, please visit: https://www.igniterealtime.org.

The Openfire build process is based on Apache Maven. Visit the Maven website for more information.

This documentation is divided into three sections:

## Get the Openfire Source

You can get the Openfire source code by downloading a source distribution or by checking out the source code from the Openfire Github repository. Instructions for both options can be found on the source page.

## Setup Your Environment

Getting your machine ready for development requires a few steps. Wherever possible, instructions are provided for both Unix/Linux and Windows users.

### Configure Java for Openfire

Java 17 (JDK 17) must be installed and setup on your machine. To test the installation, open a shell in a Unix or a command prompt in Windows. Check your version of Java with "java -version" -- it must version 17 or greater.

Important! -- the Openfire build tool needs to know where Java is installed on your system. You must configure the "JAVA_HOME" environment variable to point to the correct directory. Instructions on how to set this variable for various platforms are as follows:

#### Unix/Linux

1. Edit the ".profile" file in your home directory (or corresponding file for your shell).
2. Set the JAVA_HOME environment variable by adding the following line to the file:

       export JAVA_HOME=/usr/local/jdk17

   The value "/usr/local/jdk17" should be replaced with your actual Java directory. Be sure there are no spaces after the end of the directory name. Do not add an extra slash after the directory name.
3. Save changes to the file and then "source" it:

       source .profile

   The JAVA_HOME variable should now be configured correctly.

#### Microsoft Windows

1. Navigate to your desktop and right click on "My Computer"; choose properties.
2. Select the "Advanced" tab and click on the "Environment Variables" button.
3. Click the "New..." button in the System variables section. Enter the variable name "JAVA_HOME" and set the variable value to the full path of your Java installation. For example, "c:\jdk17". Be sure to not add an extra slash to the end of the directory name.
4. Click "OK" in all the menus to accept the changes.
5. Close any open command prompt windows. The next time you open a command prompt, the "JAVA_HOME" variable will be set correctly.

### Install the Maven Build Tool

The Openfire build process uses Maven, so that tool must be installed and configured on your computer. First download Maven from: https://maven.apache.org. Next, follow the usage instructions.

#### Test building with Maven

Navigate into the root directory of this distribution named via the command-line. In that directory, invoke the build tool to compile the Openfire source code:

    ./mvnw compile

If the build tool is invoked correctly and Openfire compiles, you've correctly configured Maven and your copy of the Openfire source distribution.

## Build Phases

Openfire conforms to the standard Maven build process. For a full list of the commands please review the Apache Maven documentation. For more complete help on several commands, read the documentation below.

To execute a build phase, type `./mvnw "phase"` where "phase" is one of the keywords listed below:

- clean
- compile
- test
- package

Note that you can combine several phases, for example: `./mvnw clean package`. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. For example, when the 'package' phase is executed, the 'compile' and 'test' phases are also executed (but the 'clean' phase is not, unless specified explicitly). Please refer to the Maven documentation for more details.

### clean

Cleans all artifacts of the build process.

Syntax

    ./mvnw clean

### compile

Builds Openfire components into the `target` directory of each module.

Syntax

    ./mvnw compile

### test

Builds Openfire components, and runs all unit tests.

Syntax

    ./mvnw test

### package

Builds Openfire components, runs all unit tests, and creates a distributable package in the `distribution` module. You can then launch Openfire using the scripts in `distribution/target/distribution-base/bin`.

Syntax

    ./mvnw package