자바용 OR-도구 Maven 사용
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
소개
이 가이드에서는 간단한 실제 예제를 통해 자바에서 OR-도구를 시작하는 방법을 설명합니다.
이 안내는 다른 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
Debian
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
Maven 3.3 이상
Maven 버전 3.3 이상을 설치하려면 터미널 창을 열고 다음을 입력합니다.
Alpine
sudo apk add maven
센토스
sudo yum install -y maven
Debian
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으로 설치
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-도구를 시작할 준비가 된 것입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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)."]]