使用适用于 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。"],[[["This guide provides step-by-step instructions for setting up and running OR-Tools in Java on Windows 10 64-bit using Maven."],["Before starting, ensure you have prerequisites like Microsoft Visual C++ Redistributable, Java JDK 8 or later, and Maven installed."],["You can integrate OR-Tools into your Maven project by adding a dependency to your project's `pom.xml` file."],["Example code is available in the `java_or-tools` repository on GitHub and can be built and run using Maven commands."],["After successfully running the example, you can explore further functionalities and features of OR-Tools for your Java applications."]]],["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"]]