OR-Tools Maven for Java を使用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
はじめに
このガイドでは、簡単な作業例を用いて、Java の OR-Tools の使い方について説明します。
この手順は他の Windows バリアントでも動作する可能性がありますが、次の要件を満たすマシンでのみテストしています。
Windows 10 64 ビット(x86_64)と次のもの:
- Microsoft Visual Studio Enterprise 2022
- Microsoft Visual Studio Community 2022 Preview 2 以降
前提条件
以降のセクションでは、OR-Tools をインストールするための前提条件について説明します。
Microsoft Visual C++ 再配布可能パッケージ
Java 用 OR-Tools ライブラリは C++ ネイティブ ライブラリのラッパーであるため、Visual Studio 2022 用 Microsoft Visual C++ 再配布可能パッケージ(x64 バージョンを選択)がインストールされている必要があります。
Java JDK
また、Java JDK 64 ビットのバージョン 8.0 以降がインストールされている必要があります。
詳しくはこちらをご覧ください。
Maven
Maven 64 ビットがインストールされている必要もあります。
詳しくはこちらをご覧ください。
Maven を使用したインストール
Maven アプリケーションに OR-Tools を含めるには、そのアーティファクトへの依存関係をプロジェクトの pom.xml ファイルに追加します。たとえば、
<!-- https://mvnrepository.com/artifact/com.google.ortools/ortools-java -->
<dependency>
<groupId>com.google.ortools</groupId>
<artifactId>ortools-java</artifactId>
<version>9.10.4067</version>
</dependency>
Java サンプルコードを取得する
サンプルコードは java_or-tools リポジトリにあります。
リポジトリを ZIP ファイルとしてダウンロードして展開するか、リポジトリのクローンを作成します。
git clone -b v9.10 --depth 1 https://github.com/or-tools/java_or-tools
サンプル ディレクトリに移動します。
cd java_or-tools
サンプルをビルドする
java_or-tools
ディレクトリから:
次のコマンドを使用してプロジェクトをビルドします。
mvn compile -B
サンプルを実行する
java_or-tools
ディレクトリから:
次のコマンドを使用してバイナリを実行します。
mvn exec:java
これで完了です。OR-Tools を使用してアプリケーションを実行したので、OR-Tools の使用を開始する準備が整いました。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-08-09 UTC。
[null,null,["最終更新日 2024-08-09 UTC。"],[[["\u003cp\u003eThis guide provides step-by-step instructions for setting up and running OR-Tools in Java on Windows 10 64-bit using Maven.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure you have prerequisites like Microsoft Visual C++ Redistributable, Java JDK 8 or later, and Maven installed.\u003c/p\u003e\n"],["\u003cp\u003eYou can integrate OR-Tools into your Maven project by adding a dependency to your project's \u003ccode\u003epom.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eExample code is available in the \u003ccode\u003ejava_or-tools\u003c/code\u003e repository on GitHub and can be built and run using Maven commands.\u003c/p\u003e\n"],["\u003cp\u003eAfter successfully running the example, you can explore further functionalities and features of OR-Tools for your Java applications.\u003c/p\u003e\n"]]],["This guide details how to use OR-Tools in Java. Key actions include installing prerequisites: the Microsoft Visual C++ Redistributable (x64), a 64-bit Java JDK (8.0+), and 64-bit Maven. To integrate OR-Tools, add its artifact dependency to the project's pom.xml file. Download or clone the `java_or-tools` repository, navigate to its directory, and then build the project with `mvn compile -B`. Finally, execute the example by running `mvn exec:java`.\n"],null,["# Using OR-Tools Maven for Java\n\nIntroduction\n------------\n\nThis guide gets you started with OR-Tools in Java with a simple working\nexample.\n\nAlthough these instructions might also work on other Windows variants, we\nhave only tested them on machines meeting the following requirements:\n\n\nWindows 10 64-bit (x86_64) with:\n\n- Microsoft Visual Studio Enterprise 2022\n- Microsoft Visual Studio Community 2022 Preview 2 or above\n\n\u003cbr /\u003e\n\nPrerequisites\n-------------\n\nThe following sections describe the prerequisites for installing OR-Tools.\n\n### Microsoft Visual C++ Redistributable\n\nYou must have the\n[Microsoft Visual C++ Redistributable for Visual Studio 2022](https://visualstudio.microsoft.com/downloads/?q=Visual+C%2B%2B+Redistributable+for+Visual+Studio) (select the x64 version) installed\non your computer, since OR-Tools library for Java is a wrapper for the\nC++ native library.\n\n### Java JDK\n\nYou must also have a Java JDK 64 bit, version 8.0 or later installed.\n\nYou can find more details\n[here](https://java.com/en/download/help/download_options.xml).\n\n### Maven\n\nYou must also have a Maven 64 bit installed.\n\nYou can find more details [here](https://maven.apache.org/download.cgi).\n\nInstalling with Maven\n---------------------\n\nTo include OR-Tools in your Maven application, add a dependency on its artifacts\nto your project's pom.xml file. For example, \n\n \u003c!-- https://mvnrepository.com/artifact/com.google.ortools/ortools-java --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.ortools\u003c/groupId\u003e\n \u003cartifactId\u003eortools-java\u003c/artifactId\u003e\n \u003cversion\u003e9.12.4544\u003c/version\u003e\n \u003c/dependency\u003e\n\nGet the Java example code\n-------------------------\n\nThe example code is located in the\n[java_or-tools](https://github.com/or-tools/java_or-tools) repository.\n\n1. [Download the repository as a zip file](https://github.com/or-tools/java_or-tools/archive/v9.12.zip)\n and extract it, or clone the repository:\n\n git clone -b v9.12 --depth 1 https://github.com/or-tools/java_or-tools\n\n2. Change to the examples directory:\n\n cd java_or-tools\n\nBuild the example\n-----------------\n\nFrom the `java_or-tools` directory:\n\nBuild the project using:\n\n\n mvn compile -B\n\n\u003cbr /\u003e\n\nRun the example\n---------------\n\nFrom the `java_or-tools` directory:\n\nRun the binary using:\n\n\n mvn exec:java\n\n\u003cbr /\u003e\n\nCongratulations! You've just run an application with OR-Tools, you are ready to\n[get started with OR-Tools](../../introduction/java)."]]