Build from source
We highly recommend running a *nix system to build OpenNMS from source code. You do not need to run it physically; a virtual machine is sufficient. Our community uses the following environments to develop our software:
-
Debian-based operating system
-
RPM-based operating system
-
Mac OS X
This section describes how to build OpenNMS Meridian with an Ubuntu Desktop system. Follow these instructions to accomplish the following:
-
Download the source code and create a build environment
-
A compiled and assembled version from the latest develop branch
-
An OpenNMS Meridian core server instance running locally from a development directory
You should be familiar with deploying OpenNMS Meridian, especially setting up package repositories and configuring and initializing the PostgreSQL database. Basic knowledge of git is highly recommended.
Before you begin
We publish and maintain the project on GitHub.
Make sure you have access to GitHub to fetch the source with SSH or HTTPS.
Once you have built the software, you need to install packages.
Ensure your user account has administrative permissions with sudo
.
To build and run Meridian from source, you must install the following components on your system:
-
OpenJDK 11 development kit; verify the correct
javac
andjava
executables are in your search path -
JICMP and JICMP6 packages to allow sending ICMP messages with Java
-
git-scm to check out the source code from the OpenNMS GitHub repository
-
PostgreSQL server (installed and initialized)
-
Perl to run the convenient compile and assemble helper scripts
-
Python (some helper scripts require it)
-
Docker to run smoke tests or start services as container
Optional packages:
-
IPLIKE which is a stored procedure in PostgreSQL for complex IP queries. The iplike package is specific to the PostgreSQL major version. For example, for PostgreSQL 13.x you need the package
iplike-pgsql13
. -
JRRD2 if you want to use RRDtool instead of the default Java-based RRD implementation JRobin
-
RRDtool from the official package repositories
You can set the environment JAVA_HOME in /etc/environment if you want additional control about the Java JDK used during builds.
Changes are applied immediately with source /etc/environment .
|
Within the source tree we ship a Maven version which is used by default.
The environment variable MVN allows you to use your own installed Maven version.
|
Get the source code
First, you need the source code from the GitHub repository.
The default branch is develop
which is the release candidate for the major release.
You can check out a specific version tag if you want or switch to a branch you want to build from.
The command git tag -l
or git branch -r
gives you available branches or version tags.
git clone https://github.com/OpenNMS/opennms.git ~/dev/opennms
cd ~/dev/opennms
Compile and assemble from source
The build is divided into two steps. The first step compiles the source code and the second step assembles the compiled artefacts so you can run OpenNMS Meridian locally. To speed up the build steps, we explicitly disable tests and don’t create a source tarball file.
./compile.pl -DskipTests
./assemble.pl -p dir -DskipTests
The profile argument -p dir
allows you to run OpenNMS Meridian directly from the target directory.
If you build from source the first time, it takes some time.
During the first build, the Maven dependencies download is about ~4GB.
The Maven repository is by default located in the ${HOME}/.m2 directory.
|
Run your build locally
The following instructions require the release version.
The release version is defined in the root pom.xml
in the source tree and changes with every major release.
This release version depends on which version tag or branch you have checked out and try to build.
It is helpful to extract the release version in an environment variable and allows you to repeat the following instructions more easily.
Instead of maintaining a local PostgreSQL installation, you can also run an ephemeral PostgreSQL instance as a container.
The command sudo docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres:13 starts an instance which allows connections without authentication for development.
If you want to persist the database on your host for later use, you can add -v $(pwd)/data:/var/lib/postgresql/data .
|
export ONMS_RELEASE=$(./.circleci/scripts/pom2version.sh pom.xml)
echo "RUNAS=$(id -u -n)" > "target/opennms-${ONMS_RELEASE}/etc/opennms.conf"
The next step is configuring PostgreSQL to initialise the database.
Follow Set up the core instance from the deployment guide; the procedure is the same.
The configuration file is located in target/opennms-${ONMS_RELEASE}/etc/opennms-datasources.xml
.
./target/opennms-"${ONMS_RELEASE}"/bin/runjava -s
./target/opennms-"${ONMS_RELEASE}"/bin/install -dis
./target/opennms-"${ONMS_RELEASE}"/bin/opennms -vt start
./target/opennms-"${ONMS_RELEASE}"/bin/opennms stop