Using OR-Tools Maven for Java

  • This guide provides step-by-step instructions for installing and running OR-Tools in Java on MacOS.

  • Before starting, ensure you have Xcode Command Line Tools, Homebrew, Java JDK 8.0 or higher, and Maven installed.

  • You can integrate OR-Tools into your Maven project by adding a dependency to your project's pom.xml file.

  • A working example code is available in the java_or-tools repository for download and execution.

  • After setup, you can build and run the example application using Maven commands to get started with OR-Tools.

 Introduction

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

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

  • MacOS 13.0.1 (Ventura) Intel 64-bit (x86_64)
  • MacOS 13.0.1 (Ventura) M1 (arm64)

Prerequisites

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

Xcode Command Line Tools

You must install the Xcode Command Line Tools. To do so, open the Terminal, found in /Applications/Utilities/, and enter:

xcode-select --install

Click “Install” to download and install Xcode Command Line Tools. You don’t need to "Get Xcode" from the App Store. If you have a slow Internet connection, it may take many minutes.

Verify that you’ve successfully installed Xcode Command Line Tools:

xcode-select -p

You should see:

/Library/Developer/CommandLineTools

Homebrew

To install the remaining prerequisites, we recommend first installing the "missing package manager for macOS" otherwise known as Homebrew. To do so, open a terminal window and enter:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update

To verify that you’ve successfully installed brew:

brew --version

You should see:

Homebrew 1.6.9-8-g25542d7
Homebrew/homebrew-core (git revision 0e0c84; last commit 2018-06-20)

Java JDK

You must install the Java JDK 8.0 or higher.

Once you have installed Homebrew, you can install openjdk by opening a terminal window and enter:

brew install openjdk
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Then you need to export the JAVA_HOME variable:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk.jdk

Maven

You must install Maven.

Once you have installed Homebrew, you can install maven by opening a terminal window and enter:

brew install 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.