Using OR-Tools Maven for Java

  • This guide provides instructions for setting up and running OR-Tools in Java on various Linux distributions.

  • Users must have Java JDK 8.0 or higher and Maven 3.3 or higher installed as prerequisites.

  • OR-Tools can be easily integrated into Maven projects by adding a dependency to the project's pom.xml file.

  • The guide includes steps to download, build, and run a simple OR-Tools example application.

  • Upon successful completion, users can proceed to further explore and utilize OR-Tools functionalities.

 Introduction

This guide gets you started with OR-Tools in Java with a simple working example.

Although these instructions might also work on other Linux variants, we have only tested them on machines meeting the following requirements:

  • Alpine Edge 64-bit (x86_64)
  • Centos 7 LTS 64-bit (x86_64)
  • Debian SID 64-bit (x86_64)
  • Debian 11 (bullseye) 64-bit (x86_64)
  • Fedora 38 64-bit (x86_64)
  • Fedora 37 64-bit (x86_64)
  • OpenSuse Leap 64-bit (x86_64)
  • Ubuntu 24.10 64-bit (x86_64)
  • Ubuntu 22.04 LTS 64-bit (x86_64)
  • Ubuntu 20.04 LTS 64-bit (x86_64)

Prerequisites

The following sections describe the prerequisites for installing OR-Tools.

Java JDK >= 8.0

To install the Java JDK version 8.0 or higher, open a terminal window and enter:

Alpine

sudo apk add openjdk8
export JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk

Centos

sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

Debian

sudo apt install -y default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java

Fedora

sudo dnf install -y java-openjdk java-openjdk-devel

Fedora

sudo dnf install -y java-openjdk java-openjdk-devel

OpenSUSE

sudo zypper install -y java-1_8_0-openjdk java-1_8_0-openjdk-devel

Ubuntu

sudo apt install -y default-jdk

Ubuntu

sudo apt install -y default-jdk

Ubuntu

sudo apt install -y default-jdk

Maven >= 3.3

To install Maven version 3.3 or higher, open a terminal window and enter:

Alpine

sudo apk add maven

Centos

sudo yum install -y maven

Debian

sudo apt install -y maven

Fedora

sudo dnf install -y maven

Fedora

sudo dnf install -y maven

OpenSUSE

sudo zypper install -y maven

Ubuntu

sudo apt install -y maven

Ubuntu

sudo apt install -y maven

Ubuntu

sudo apt install -y maven

You can test Maven is correctly installed and can find java using the following command:

mvn -v

Installing with Maven

To include OR-Tools in your Maven application, add a dependency on its artifacts to your project's pom.xml file. For example,

<!-- https://mvnrepository.com/artifact/com.google.ortools/ortools-java -->
<dependency>
    <groupId>com.google.ortools</groupId>
    <artifactId>ortools-java</artifactId>
    <version>9.12.4544</version>
</dependency>

Get the Java example code

The example code is located in the java_or-tools repository.

  1. Download the repository as a zip file and extract it, or clone the repository:

    git clone -b v9.12 --depth 1 https://github.com/or-tools/java_or-tools
    
  2. Change to the examples directory:

    cd java_or-tools
    

Build the example

From the java_or-tools directory:

Build the project using:

mvn compile -B

Run the example

From the java_or-tools directory:

Run the binary using:

mvn exec:java

Congratulations! You've just run an application with OR-Tools, you are ready to get started with OR-Tools.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-03-18 UTC.