การใช้ OR-Tools Maven สำหรับ Java
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บทนำ
คู่มือนี้จะช่วยให้คุณสามารถเริ่มต้นใช้งาน "หรือ" ใน Java ด้วยตัวอย่างการทำงานง่ายๆ
แม้ว่าวิธีการเหล่านี้อาจใช้ได้กับตัวแปรอื่นๆ ของ Linux ด้วย แต่เราได้ทดสอบคำสั่งดังกล่าวในเครื่องที่เป็นไปตามข้อกำหนดต่อไปนี้เท่านั้น
- Alpine Edge 64 บิต (x86_64)
- Centos 7 LTS 64 บิต (x86_64)
- Debian SID 64 บิต (x86_64)
- Debian 11 (bullseye) 64 บิต (x86_64)
- Fedora 38 64 บิต (x86_64)
- Fedora 37 64 บิต (x86_64)
- OpenSuse Leap 64 บิต (x86_64)
- Ubuntu 24.04 64 บิต (x86_64)
- Ubuntu 22.04 LTS 64 บิต (x86_64)
- Ubuntu 20.04 LTS 64 บิต (x86_64)
ข้อกำหนดเบื้องต้น
ส่วนต่อไปนี้จะอธิบายข้อกำหนดเบื้องต้นสำหรับการติดตั้ง OR-เครื่องมือ
Java JDK >= 8.0
หากต้องการติดตั้ง Java JDK เวอร์ชัน 8.0 ขึ้นไป ให้เปิดหน้าต่างเทอร์มินัลแล้วป้อนข้อมูลต่อไปนี้
Alpine
sudo apk add openjdk8
export JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
เซนโตส
sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
เดเบียน
sudo apt install -y default-jdk
export JAVA_HOME=/usr/lib/jvm/default-java
หมวก Fedora
sudo dnf install -y java-openjdk java-openjdk-devel
หมวก Fedora
sudo dnf install -y java-openjdk java-openjdk-devel
OpenSUSE
sudo zypper install -y java-1_8_0-openjdk java-1_8_0-openjdk-devel
Ubuntu
sudo apt install -y default-jdk
Ubuntu
sudo apt install -y default-jdk
Ubuntu
sudo apt install -y default-jdk
มากขึ้น >= 3.3
หากต้องการติดตั้ง Maven เวอร์ชัน 3.3 ขึ้นไป ให้เปิดหน้าต่างเทอร์มินัลแล้วป้อนข้อมูลต่อไปนี้
Alpine
sudo apk add maven
เซนโตส
sudo yum install -y maven
เดเบียน
sudo apt install -y maven
หมวก Fedora
sudo dnf install -y maven
หมวก Fedora
sudo dnf install -y maven
OpenSUSE
sudo zypper install -y maven
Ubuntu
sudo apt install -y maven
Ubuntu
sudo apt install -y maven
Ubuntu
sudo apt install -y maven
คุณทดสอบได้ว่าติดตั้ง Maven อย่างถูกต้องหรือไม่และค้นหา Java โดยใช้คำสั่งต่อไปนี้
mvn -v
การติดตั้งด้วย Maven
หากต้องการรวม OR-Tools ในแอปพลิเคชัน Maven ให้เพิ่มทรัพยากร Dependency ของอาร์ติแฟกต์ไปยังไฟล์ 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-Tools แล้ว
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-09 UTC
[null,null,["อัปเดตล่าสุด 2024-08-09 UTC"],[[["\u003cp\u003eThis guide provides instructions for setting up and running OR-Tools in Java on various Linux distributions.\u003c/p\u003e\n"],["\u003cp\u003eUsers must have Java JDK 8.0 or higher and Maven 3.3 or higher installed as prerequisites.\u003c/p\u003e\n"],["\u003cp\u003eOR-Tools can be easily integrated into Maven projects by adding a dependency to the project's \u003ccode\u003epom.xml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe guide includes steps to download, build, and run a simple OR-Tools example application.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful completion, users can proceed to further explore and utilize OR-Tools functionalities.\u003c/p\u003e\n"]]],["This guide details how to set up and run OR-Tools in Java. First, install Java JDK (version 8.0 or higher) using the appropriate commands for your OS (Alpine, Centos, Debian, Fedora, OpenSUSE, or Ubuntu). Next, install Maven (version 3.3 or higher) with similar commands. To include OR-Tools, add the provided dependency to your `pom.xml` file. Download or clone the `java_or-tools` repository, then navigate to its directory. Finally, build and run the example using `mvn compile -B` and `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 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### 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\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)."]]