AmazonLinux2023にJavaとMavenをインストールする

# 概要
これのAmazonLinux2023版です。

https://qiita.com/tamorieeeen/items/bcdf9729a5e9194c5d20

AmazonLinux2→AmazonLinux2023に乗り換えるにあたってローカルにAmazonLinux2023(以下AL2023)を立てて検証中なのでEC2で立てたとき用にメモ。

# 環境
- Windows 11 Pro
- VirtualBox 7.0.12
- Amazon Linux 2023
  - Operating System: Amazon Linux 2023.4.20240319
  - Kernel: Linux 6.1.79-99.167.amzn2023.x86_64

# 構築手順
## 1. JDK17をインストールする
- AL2023にはデフォルトでJavaは入っていないので入れます
  - Amazon Corretto 17(JDK)を入れます
```console
$ dnf list --available "java-*corretto*"
java-1.8.0-amazon-corretto.x86_64                                      1:1.8.0_402.b08-1.amzn2023                                 amazonlinux
java-1.8.0-amazon-corretto-devel.x86_64                                1:1.8.0_402.b08-1.amzn2023                                 amazonlinux
java-11-amazon-corretto.x86_64                                         1:11.0.22+7-1.amzn2023                                     amazonlinux
java-11-amazon-corretto-devel.x86_64                                   1:11.0.22+7-1.amzn2023                                     amazonlinux
java-11-amazon-corretto-headless.x86_64                                1:11.0.22+7-1.amzn2023                                     amazonlinux
java-11-amazon-corretto-javadoc.x86_64                                 1:11.0.22+7-1.amzn2023                                     amazonlinux
java-11-amazon-corretto-jmods.x86_64                                   1:11.0.22+7-1.amzn2023                                     amazonlinux
java-17-amazon-corretto.x86_64                                         1:17.0.10+8-1.amzn2023.1                                   amazonlinux
java-17-amazon-corretto-devel.x86_64                                   1:17.0.10+8-1.amzn2023.1                                   amazonlinux
java-17-amazon-corretto-headless.x86_64                                1:17.0.10+8-1.amzn2023.1                                   amazonlinux
java-17-amazon-corretto-javadoc.x86_64                                 1:17.0.10+8-1.amzn2023.1                                   amazonlinux
java-17-amazon-corretto-jmods.x86_64                                   1:17.0.10+8-1.amzn2023.1                                   amazonlinux
java-21-amazon-corretto.x86_64                                         1:21.0.2+14-1.amzn2023.1                                   amazonlinux
java-21-amazon-corretto-devel.x86_64                                   1:21.0.2+14-1.amzn2023.1                                   amazonlinux
java-21-amazon-corretto-headless.x86_64                                1:21.0.2+14-1.amzn2023.1                                   amazonlinux
java-21-amazon-corretto-javadoc.x86_64                                 1:21.0.2+14-1.amzn2023.1                                   amazonlinux
java-21-amazon-corretto-jmods.x86_64

$ sudo dnf -y install java-17-amazon-corretto-devel
Dependencies resolved.
=============================================================================================================================================
 Package                                        Architecture         Version                                 Repository                 Size
=============================================================================================================================================
Installing:
 java-17-amazon-corretto-devel                  x86_64               1:17.0.10+8-1.amzn2023.1                amazonlinux               142 k
Installing dependencies:
 alsa-lib                                       x86_64               1.2.7.2-1.amzn2023.0.2                  amazonlinux               504 k
 cairo                                          x86_64               1.17.6-2.amzn2023.0.1                   amazonlinux               684 k
 dejavu-sans-fonts                              noarch               2.37-16.amzn2023.0.2                    amazonlinux               1.3 M
 dejavu-sans-mono-fonts                         noarch               2.37-16.amzn2023.0.2                    amazonlinux               467 k
 dejavu-serif-fonts                             noarch               2.37-16.amzn2023.0.2                    amazonlinux               1.0 M
 fontconfig                                     x86_64               2.13.94-2.amzn2023.0.2                  amazonlinux               273 k
 fonts-filesystem                               noarch               1:2.0.5-12.amzn2023.0.2                 amazonlinux               9.5 k
 freetype                                       x86_64               2.13.0-2.amzn2023.0.1                   amazonlinux               422 k
 google-noto-fonts-common                       noarch               20201206-2.amzn2023.0.2                 amazonlinux                15 k
 google-noto-sans-vf-fonts                      noarch               20201206-2.amzn2023.0.2                 amazonlinux               492 k
 graphite2                                      x86_64               1.3.14-7.amzn2023.0.2                   amazonlinux                97 k
 harfbuzz                                       x86_64               7.0.0-2.amzn2023.0.1                    amazonlinux               868 k
 java-17-amazon-corretto-headless               x86_64               1:17.0.10+8-1.amzn2023.1                amazonlinux                91 M
 javapackages-filesystem                        noarch               6.0.0-7.amzn2023.0.6                    amazonlinux                12 k
 langpacks-core-font-en                         noarch               3.0-21.amzn2023.0.4                     amazonlinux                10 k
 libX11                                         x86_64               1.7.2-3.amzn2023.0.4                    amazonlinux               657 k
 libX11-common                                  noarch               1.7.2-3.amzn2023.0.4                    amazonlinux               152 k
 libXau                                         x86_64               1.0.9-6.amzn2023.0.2                    amazonlinux                31 k
 libXext                                        x86_64               1.3.4-6.amzn2023.0.2                    amazonlinux                41 k
 libXrender                                     x86_64               0.9.10-14.amzn2023.0.2                  amazonlinux                28 k
 libbrotli                                      x86_64               1.0.9-4.amzn2023.0.2                    amazonlinux               315 k
 libjpeg-turbo                                  x86_64               2.1.4-2.amzn2023.0.5                    amazonlinux               190 k
 libpng                                         x86_64               2:1.6.37-10.amzn2023.0.6                amazonlinux               128 k
 libxcb                                         x86_64               1.13.1-7.amzn2023.0.2                   amazonlinux               230 k
 pixman                                         x86_64               0.40.0-3.amzn2023.0.3                   amazonlinux               295 k
 xml-common                                     noarch               0.6.3-56.amzn2023.0.2                   amazonlinux                32 k

Transaction Summary
=============================================================================================================================================
Install  27 Packages

$ java -version
openjdk version "17.0.10" 2024-01-16 LTS
OpenJDK Runtime Environment Corretto-17.0.10.8.1 (build 17.0.10+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.10.8.1 (build 17.0.10+8-LTS, mixed mode, sharing)
```

## 2. Mavenをインストールする
- searchすると`maven.noarch`があるのでdnfでインストールします
  - 検索結果は大量なので省略してます

```console
$ dnf search maven
======================================================== Name Exactly Matched: maven ========================================================
maven.noarch : Java project management and project comprehension tool

$ sudo dnf -y install maven
Dependencies resolved.
=============================================================================================================================================
 Package                                              Architecture        Version                             Repository                Size
=============================================================================================================================================
Installing:
 maven                                                noarch              1:3.8.4-3.amzn2023.0.5              amazonlinux               18 k
Installing dependencies:
 apache-commons-cli                                   noarch              1.5.0-3.amzn2023.0.3                amazonlinux               76 k
 apache-commons-codec                                 noarch              1.15-6.amzn2023.0.3                 amazonlinux              303 k
 apache-commons-io                                    noarch              1:2.8.0-7.amzn2023.0.4              amazonlinux              284 k
 apache-commons-lang3                                 noarch              3.12.0-7.amzn2023.0.3               amazonlinux              559 k
 atinject                                             noarch              1.0.5-3.amzn2023.0.3                amazonlinux               23 k
 cdi-api                                              noarch              2.0.2-6.amzn2023.0.3                amazonlinux               54 k
 google-guice                                         noarch              4.2.3-8.amzn2023.0.6                amazonlinux              473 k
 guava                                                noarch              31.0.1-3.amzn2023.0.6               amazonlinux              2.4 M
 httpcomponents-client                                noarch              4.5.13-4.amzn2023.0.4               amazonlinux              657 k
 httpcomponents-core                                  noarch              4.4.13-6.amzn2023.0.3               amazonlinux              632 k
 jakarta-annotations                                  noarch              1.3.5-13.amzn2023.0.3               amazonlinux               46 k
 jansi                                                x86_64              2.4.0-3.amzn2023.0.3                amazonlinux              113 k
 jcl-over-slf4j                                       noarch              1.7.32-3.amzn2023.0.4               amazonlinux               25 k
 jsoup                                                noarch              1.13.1-9.amzn2023.0.5               amazonlinux              377 k
 jsr-305                                              noarch              3.0.2-5.amzn2023.0.4                amazonlinux               32 k
 maven-amazon-corretto17                              noarch              1:3.8.4-3.amzn2023.0.5              amazonlinux              9.4 k
 maven-lib                                            noarch              1:3.8.4-3.amzn2023.0.5              amazonlinux              1.5 M
 maven-resolver                                       noarch              1:1.7.3-3.amzn2023.0.4              amazonlinux              557 k
 maven-shared-utils                                   noarch              3.3.4-4.amzn2023.0.3                amazonlinux              152 k
 maven-wagon                                          noarch              3.4.2-6.amzn2023.0.4                amazonlinux              113 k
 plexus-cipher                                        noarch              1.8-3.amzn2023.0.3                  amazonlinux               27 k
 plexus-classworlds                                   noarch              2.6.0-10.amzn2023.0.4               amazonlinux               61 k
 plexus-containers-component-annotations              noarch              2.1.0-9.amzn2023.0.4                amazonlinux               19 k
 plexus-interpolation                                 noarch              1.26-10.amzn2023.0.4                amazonlinux               80 k
 plexus-sec-dispatcher                                noarch              2.0-3.amzn2023.0.3                  amazonlinux               34 k
 plexus-utils                                         noarch              3.3.0-9.amzn2023.0.4                amazonlinux              254 k
 publicsuffix-list                                    noarch              20240212-61.amzn2023                amazonlinux               89 k
 sisu                                                 noarch              1:0.3.4-9.amzn2023.0.4              amazonlinux              510 k
 slf4j                                                noarch              1.7.32-3.amzn2023.0.4               amazonlinux               70 k

Transaction Summary
=============================================================================================================================================
Install  30 Packages

$ $ mvn --version
Apache Maven 3.8.4 (Red Hat 3.8.4-3.amzn2023.0.5)
Maven home: /usr/share/maven
Java version: 17.0.10, vendor: Amazon.com Inc., runtime: /usr/lib/jvm/java-17-amazon-corretto.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "6.1.79-99.167.amzn2023.x86_64", arch: "amd64", family: "unix"
```