[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-08-29 (世界標準時間)。"],[[["\u003cp\u003eThis guide provides instructions for building OR-Tools from source with Java support on Linux, primarily for users who need to modify the code or use third-party solvers.\u003c/p\u003e\n"],["\u003cp\u003eBefore building, you need to install prerequisites like C++ tools, SWIG, Java JDK 8.0 or higher, and Maven 3.3 or higher, using the provided commands for your specific Linux distribution.\u003c/p\u003e\n"],["\u003cp\u003eYou can download the stable or main branch of the OR-Tools source code from GitHub and configure the build using CMake, enabling or disabling support for solvers like SCIP and Gurobi.\u003c/p\u003e\n"],["\u003cp\u003eBuild the source code using CMake, test it by running the examples, and optionally install OR-Tools on your system for easier access.\u003c/p\u003e\n"],["\u003cp\u003eIf you need to reinstall, you can clean the build files and reconfigure/rebuild using the provided commands, ensuring a fresh installation.\u003c/p\u003e\n"]]],["This guide details building OR-Tools from source with Java support on Linux. Key actions include: installing C++, SWIG, Java JDK (\u003e= 8.0), and Maven (\u003e= 3.3) using terminal commands specific to each Linux distribution. The process involves downloading source code from the `stable` or `main` branch, configuring the build with CMake, and compiling using specified commands. Optional solvers like SCIP and Gurobi are integrated. Lastly, the user is able to test and install the OR-Tools.\n"],null,["# Building from source OR-Tools Java on Linux\n\nIntroduction\n------------\n\nThis guide explains how to build from source OR-Tools, with support for\nJava, on Linux.\n\nUnless you plan to modify the source code or use a third-party solver with\nOR-Tools, we recommend the [package installation](./binary_linux).\n\nAlthough these instructions might also work on other Linux variants, we\nhave only tested them on machines meeting the following requirements:\n\n\n- Alpine Edge 64-bit (x86_64)\n- Centos 7 LTS 64-bit (x86_64)\n- Debian SID 64-bit (x86_64)\n- Debian 11 (bullseye) 64-bit (x86_64)\n- Fedora 38 64-bit (x86_64)\n- Fedora 37 64-bit (x86_64)\n- OpenSuse Leap 64-bit (x86_64)\n- Ubuntu 24.10 64-bit (x86_64)\n- Ubuntu 22.04 LTS 64-bit (x86_64)\n- Ubuntu 20.04 LTS 64-bit (x86_64)\n\n\u003cbr /\u003e\n\nPrerequisites\n-------------\n\nThe following sections describe the prerequisites for installing OR-Tools.\n\n### C++ tools\n\nTo install C++ tools, open a terminal window and enter: \n\n### Alpine\n\n apk add alpine-sdk linux-headers cmake lsb-release-minimal\n\n### Centos\n\n sudo yum groupinstall -y 'Development Tools'\n sudo yum install -y pkgconfig redhat-lsb-core\n\n### Debian\n\n sudo apt update\n sudo apt install -y build-essential cmake lsb-release\n\n### Fedora\n\n sudo dnf groupinstall -y 'Development Tools'\n sudo dnf install -y gcc-c++ cmake redhat-lsb-core\n\n### Fedora\n\n sudo dnf groupinstall -y 'Development Tools'\n sudo dnf install -y gcc-c++ cmake redhat-lsb-core\n\n### OpenSUSE\n\n sudo zypper refresh\n sudo zypper install -y git gcc11 gcc11-c++ lsb-release\n\n### Ubuntu\n\n sudo apt update\n sudo apt install -y build-essential cmake lsb-release\n\n### Ubuntu\n\n sudo apt update\n sudo apt install -y build-essential cmake lsb-release\n\n### Ubuntu\n\n sudo apt update\n sudo apt install -y build-essential cmake lsb-release\n\n### SWIG\n\nTo install SWIG, open a terminal window and enter: \n\n### Alpine\n\n apk add swig\n\n### Centos\n\n sudo yum install -y swig\n\n### Debian\n\n sudo apt install -y swig\n\n### Fedora\n\n sudo dnf install -y swig\n\n### Fedora\n\n sudo dnf install -y swig\n\n### OpenSUSE\n\n sudo zypper install -y swig\n\n### Ubuntu\n\n sudo apt install -y swig\n\n### Ubuntu\n\n sudo apt install -y swig\n\n### Ubuntu\n\n sudo apt install -y swig\n\n### Java JDK \\\u003e= 8.0\n\nTo install the Java JDK version 8.0 or higher, open a terminal window and enter: \n\n### Alpine\n\n sudo apk add openjdk8\n export JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk\n\n### Centos\n\n sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel\n\n### Debian\n\n sudo apt install -y default-jdk\n export JAVA_HOME=/usr/lib/jvm/default-java\n\n### Fedora\n\n sudo dnf install -y java-openjdk java-openjdk-devel\n\n### Fedora\n\n sudo dnf install -y java-openjdk java-openjdk-devel\n\n### OpenSUSE\n\n sudo zypper install -y java-1_8_0-openjdk java-1_8_0-openjdk-devel\n\n### Ubuntu\n\n sudo apt install -y default-jdk\n\n### Ubuntu\n\n sudo apt install -y default-jdk\n\n### Ubuntu\n\n sudo apt install -y default-jdk\n\n### Maven \\\u003e= 3.3\n\nTo install Maven version 3.3 or higher, open a terminal window and enter: \n\n### Alpine\n\n sudo apk add maven\n\n### Centos\n\n sudo yum install -y maven\n\n### Debian\n\n sudo apt install -y maven\n\n### Fedora\n\n sudo dnf install -y maven\n\n### Fedora\n\n sudo dnf install -y maven\n\n### OpenSUSE\n\n sudo zypper install -y maven\n\n### Ubuntu\n\n sudo apt install -y maven\n\n### Ubuntu\n\n sudo apt install -y maven\n\n### Ubuntu\n\n sudo apt install -y maven\n\nYou can test Maven is correctly installed and can find java using the following command: \n\n mvn -v\n\n\u003cbr /\u003e\n\nDownload the source code\n------------------------\n\nThere are two distinct branches of the OR-Tools source code on\n[GitHub](https://github.com/google/or-tools): `stable` and `main`.\n\nThe `stable` branch has been thoroughly tested and should work flawlessly on all\nsupported platforms. \n\nThe `main` branch is where the latest updates and\nimprovements have been applied; it's more current, but less stable.\n\n### Download the stable source code\n\nYou can get the stable source code for OR-Tools in either of the following ways:\n\n- Clone the `stable` branch by entering:\n\n git clone https://github.com/google/or-tools\n\n- Download the latest release in a compressed file, by clicking the\n `Clone or download` button in [GitHub](https://github.com/google/or-tools).\n\n| **Warning:** The full path to the installation directory (where you extract the files) must not contain any spaces.\n\n### Download the main source code\n\nTo retrieve the source code from the `main` branch, enter: \n\n git clone -b main https://github.com/google/or-tools\n\n### Download previous releases\n\nYou can get the source code for previous releases in either of the following ways:\n\n- Download a previous release from the [GitHub release page](https://github.com/google/or-tools/releases).\n- Assuming you have already created a local repository (by `git clone`),\n you can check out a specific release using a Git\n [tag](https://github.com/google/or-tools/tags).\n For example, to work with the v9.12 release instead of the\n `main` branch, enter the following commands in your local repo:\n\n git fetch --all --tags --prune\n git checkout tags/v9.12 -b v9.12\n\nConfigure the build\n-------------------\n\nBefore building OR-Tools, you'll need to configure the CMake build system\ngenerator.\n\nOpen a terminal and navigate to the directory where you extracted the files.\nThen enter:\n\n\n cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_JAVA=ON\n\n\u003cbr /\u003e\n\n| **Tip:** For a complete list of available OR-Tools CMake options, please take a look [here](https://github.com/google/or-tools/tree/stable/cmake#readme)\n\nCheckout the\n[CMake documentation](https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem)\nfor details.\n\n### Using SCIP\n\nSince v7.8, SCIP is now integrated so you won't have to install it manually.\n| **Note:** You can disable the support of SCIP solver by using `-DUSE_SCIP=OFF`\n| **Warning:** While OR-Tools ships with SCIP, please consult the [SCIP license](https://scipopt.org/index.php#license) to ensure that you are complying with it.\n\n### Using Gurobi\n\nGurobi is now pre-integrated. When needed, at runtime, OR-Tools will search for\nthe Gurobi shared library in the default install path of the Gurobi installers\non MAC OS X and Windows, or by using the `GUROBI_HOME` environment variable.\n| **Note:** You can disable the support of Gurobi solver by using `-DUSE_GUROBI=OFF`\n\n### Using an optional third-party MIP solver\n\nYou can also use OR-Tools with any of the following optional third-party MIP\nsolvers whose support is disabled by default:\n\n- [CPLEX](https://www.ibm.com/analytics/cplex-optimizer)\n- [GLPK](https://www.gnu.org/software/glpk/) (Linux and MacOS only)\n- [XPRESS Solver](https://www.fico.com/en/products/fico-xpress-solver)\n\nPlease take a look at\n[this documentation](https://github.com/google/or-tools/tree/main/cmake#enabling-cplex-support)\nfor details.\n\nBuild the source code\n---------------------\n\nTo build the source code, open a terminal and navigate to the directory where\nyou extracted the files. Then enter the following command to compile OR-Tools:\n\n\n cmake --build build --config Release --target all -j -v\n\n\u003cbr /\u003e\n\nCheckout the\n[CMake documentation](https://cmake.org/cmake/help/latest/manual/cmake.1.html#build-a-project)\nfor details.\n\nTest the source code\n--------------------\n\nYou can check that everything is running correctly by entering:\n\n\n cmake --build build --config Release --target test -v\n\n\u003cbr /\u003e\n\nThis runs examples for OR-Tools. If all the examples run\nsuccessfully, you are ready to\n[get started with OR-Tools](/optimization/introduction/java).\n\nCleaning the build files\n------------------------\n\nIf you need to re-install OR-Tools, the command:\n\n\n rm -r build\n\n\u003cbr /\u003e\n\nwill remove all compiled dependencies.\nThis can be useful for resetting to a clean state.\n\nThen re-enter the commands:\n\n\n cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_JAVA=ON\n\n\u003cbr /\u003e\n\n\n cmake --build build --config Release --target all -j -v\n\n\u003cbr /\u003e\n\nInstalling OR-Tools on your operating system\n--------------------------------------------\n\nYou can install OR-Tools for Java on your operating system by entering:\n\n\n cmake --build build --config Release --target install -v\n\n\u003cbr /\u003e\n\n| **Tip:** To change the default install location please refer to the [`CMAKE_INSTALL_PREFIX`](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) documentation."]]