使用适用于 Java 的 OR-Tools Maven
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
简介
本指南通过一个简单的工作示例,帮助您开始使用 Java 中的 OR 工具。
虽然这些说明可能也适用于其他 Windows 变体,但我们只在满足以下要求的计算机上测试过这些说明:
Windows 10 64 位 (x86_64),具有:
- Microsoft Visual Studio 企业版 2022
- Microsoft Visual Studio Community 2022 Preview 2 或更高版本
前提条件
以下部分介绍了安装 OR-Tools 的前提条件。
Microsoft Visual C++ 可再分发
您必须在计算机上安装 Microsoft Visual C++ Redistributable for Visual Studio 2022(选择 x64 版本),因为 Java 版 OR-Tools 库是 C++ 原生库的封装容器。
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 工具运行应用,可以开始使用 OR 工具了。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-09。
[null,null,["最后更新时间 (UTC):2024-08-09。"],[[["\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)."]]