Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Maven in Alpine-Image not working (ClassNotFoundException) #497

Open
fabian-froehlich opened this issue Feb 2, 2024 · 12 comments
Open
Labels
bug Something isn't working

Comments

@fabian-froehlich
Copy link

fabian-froehlich commented Feb 2, 2024

Please add the exact image (with tag) that you are using

21.0.2_13-jdk-alpine

Please add the version of Docker you are running

25.0.2

What happened?

Switching from 21.0.1_12-jdk-alpine to 21.0.2_13-jdk-alpine causes some problems with maven. The alpine JDK image is used as a base for building our builder image for gitlab ci/cd.

The minimal example dockerfile looks like this:

FROM eclipse-temurin:21.0.2_13-jdk-alpine

# upgrade alpine linux
RUN apk update && apk add --upgrade apk-tools && apk upgrade --available && rm -rf /var/cache/apk/*

# install Build-Helper
RUN apk add --no-cache \
    bash \
    maven

CMD ["bash"]

Executing mvn -v results in this error:

$ mvn -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

Building the dockerfile with the older version 21.0.1_12-jdk-alpine as a base, the command gets executed well

$ mvn -v
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)
Maven home: /usr/share/java/maven-3
Java version: 21.0.1, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-169-generic", arch: "amd64", family: "unix"

Between the two images there are a few changes under the hood:

  • alpine bumped from 3.18 to 3.19
  • maven bumped from 3.9.2 to 3.9.5
  • jdk bundles with maven bumped from jdk 17 to jdk 21

In the course of putting all these details together, I discovered that the problem with Maven was also present if I just used the alpine:3.19 image tag itself.
It would be helpful for us if we could use the latest temurin jdk without the need to switch to the newest alpine image.

Both container are running on gitlab-runner 16.7.0.

A few odds to add:

  • I have not been able to reproduce the problem when running images locally in Docker Desktop for Windows. All logs/issues are coming from the ci/cd environment.
  • We have basically the same script for Temurin JDK17. Which - in the meanwhile - is also based on alpine 3.19 and maven 3.9.5 and hence brings a bundled Oracle OpenJDK 21 with it. And it works. So the root problem could be in Alpine 3.19, but the Temurin JDK 21 could also be interfering with Oracle JDK 21, resulting in the class problem.

Relevant log output (21.0.2_13-jdk-alpine)

#0 building with "default" instance using docker driver
#1 [internal] load build definition from dockerfile
#1 transferring dockerfile: 331B done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 transferring context: 41B 0.0s done
#2 DONE 0.1s
#3 [auth] eclipse-temurin:pull token for custom-artifactory.com
#3 DONE 0.0s
#4 [internal] load metadata for custom-artifactory.com/eclipse-temurin:21.0.2_13-jdk-alpine
#4 DONE 0.3s
#5 [1/3] FROM custom-artifactory.com/eclipse-temurin:21.0.2_13-jdk-alpine@sha256:6da40af213861c1b9cc475affa011d395d4dbcf0cb031b6a5d05a658fd9e3c5e
#5 resolve custom-artifactory.com/eclipse-temurin:21.0.2_13-jdk-alpine@sha256:6da40af213861c1b9cc475affa011d395d4dbcf0cb031b6a5d05a658fd9e3c5e 0.0s done
#5 sha256:f13b621e73dc63fb6be52dc6540fb34c92b98a0e85c69dea04289c03aa53d91b 4.92kB / 4.92kB done
#5 sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8 1.05MB / 3.41MB 0.1s
#5 sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 2.10MB / 13.14MB 0.1s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 1.05MB / 158.61MB 0.1s
#5 sha256:6da40af213861c1b9cc475affa011d395d4dbcf0cb031b6a5d05a658fd9e3c5e 549B / 549B done
#5 sha256:82698e23d15ada036bc176f6fb210401e0679cd0a4b1e71d05e7329982d6062c 1.37kB / 1.37kB done
#5 sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8 3.41MB / 3.41MB 0.1s done
#5 sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 5.24MB / 13.14MB 0.2s
#5 extracting sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8
#5 sha256:98795b95bb4830f88ab5d81f355f8a6f3bd833705d858023f9b58c42457db454 179B / 179B 0.2s done
#5 sha256:c4451c8b3dbe1616b4f1d08ac6cbd135f48e3d3393f2c37402ac18b0b845dfdc 716B / 716B 0.2s
#5 sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 6.29MB / 13.14MB 0.3s
#5 extracting sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8 0.2s done
#5 sha256:c4451c8b3dbe1616b4f1d08ac6cbd135f48e3d3393f2c37402ac18b0b845dfdc 716B / 716B 0.2s done
#5 sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 10.49MB / 13.14MB 0.5s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 9.44MB / 158.61MB 0.5s
#5 sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 13.14MB / 13.14MB 0.6s done
#5 extracting sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 20.97MB / 158.61MB 1.0s
#5 extracting sha256:59648cfc069f04a8d0eece9cae80e25155888dc9b5de722b58603efafaa0d78b 0.8s done
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 32.51MB / 158.61MB 1.7s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 40.89MB / 158.61MB 2.0s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 53.48MB / 158.61MB 2.4s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 63.96MB / 158.61MB 2.8s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 72.35MB / 158.61MB 3.1s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 81.79MB / 158.61MB 3.4s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 92.27MB / 158.61MB 3.7s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 102.76MB / 158.61MB 4.0s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 113.25MB / 158.61MB 4.3s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 123.73MB / 158.61MB 4.6s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 133.17MB / 158.61MB 4.9s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 141.56MB / 158.61MB 5.2s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 149.95MB / 158.61MB 5.5s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 158.61MB / 158.61MB 5.9s
#5 sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 158.61MB / 158.61MB 5.9s done
#5 extracting sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 0.1s
#5 extracting sha256:6b168e20b9f2c7cde9300b36733340d229efb681e7862b716580cdb07cdb572e 4.5s done
#5 extracting sha256:98795b95bb4830f88ab5d81f355f8a6f3bd833705d858023f9b58c42457db454 done
#5 extracting sha256:c4451c8b3dbe1616b4f1d08ac6cbd135f48e3d3393f2c37402ac18b0b845dfdc
#5 extracting sha256:c4451c8b3dbe1616b4f1d08ac6cbd135f48e3d3393f2c37402ac18b0b845dfdc done
#5 DONE 10.9s
#6 [2/3] RUN apk update && apk add --upgrade apk-tools && apk upgrade --available && rm -rf /var/cache/apk/*
#6 0.380 fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/main/x86_64/APKINDEX.tar.gz
#6 0.561 fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/community/x86_64/APKINDEX.tar.gz
#6 1.034 v3.19.1-26-g2c7dab72cd7 [https://dl-cdn.alpinelinux.org/alpine/v3.19/main]
#6 1.034 v3.19.1-28-g2f20f968460 [https://dl-cdn.alpinelinux.org/alpine/v3.19/community]
#6 1.034 OK: 22982 distinct packages available
#6 1.668 OK: 40 MiB in 39 packages
#6 2.271 OK: 40 MiB in 39 packages
#6 DONE 2.6s
#7 [3/3] RUN apk add --no-cache     bash     maven
#7 0.559 fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/main/x86_64/APKINDEX.tar.gz
#7 0.695 fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/community/x86_64/APKINDEX.tar.gz
#7 1.152 (1/25) Installing ncurses-terminfo-base (6.4_p20231125-r0)
#7 1.169 (2/25) Installing libncursesw (6.4_p20231125-r0)
#7 1.192 (3/25) Installing readline (8.2.1-r2)
#7 1.212 (4/25) Installing bash (5.2.21-r0)
#7 1.254 Executing bash-5.2.21-r0.post-install
#7 1.258 (5/25) Installing java-common (0.5-r0)
#7 1.274 (6/25) Installing java-cacerts (1.0-r1)
#7 1.289 (7/25) Installing openjdk21-jre-headless (21.0.2_p13-r0)
#7 2.645 (8/25) Installing libxau (1.0.11-r3)
#7 2.659 (9/25) Installing libmd (1.1.0-r0)
#7 2.673 (10/25) Installing libbsd (0.11.7-r3)
#7 2.685 (11/25) Installing libxdmcp (1.1.4-r3)
#7 2.699 (12/25) Installing libxcb (1.16-r0)
#7 2.728 (13/25) Installing libx11 (1.8.7-r0)
#7 2.784 (14/25) Installing libxext (1.3.5-r3)
#7 2.795 (15/25) Installing libxi (1.8.1-r2)
#7 2.812 (16/25) Installing libxrender (0.9.11-r4)
#7 2.826 (17/25) Installing libxtst (1.2.4-r4)
#7 2.842 (18/25) Installing alsa-lib (1.2.10-r0)
#7 2.870 (19/25) Installing giflib (5.2.1-r5)
#7 2.885 (20/25) Installing libjpeg-turbo (3.0.1-r0)
#7 2.919 (21/25) Installing lcms2 (2.15-r4)
#7 2.943 (22/25) Installing openjdk21-jre (21.0.2_p13-r0)
#7 2.983 (23/25) Installing openjdk21-jmods (21.0.2_p13-r0)
#7 3.823 (24/25) Installing openjdk21-jdk (21.0.2_p13-r0)
#7 3.917 (25/25) Installing maven (3.9.5-r0)
#7 4.023 Executing busybox-1.36.1-r15.trigger
#7 4.031 Executing ca-certificates-20230506-r0.trigger
#7 4.153 Executing java-common-0.5-r0.trigger
#7 4.162 OK: 343 MiB in 64 packages
#7 DONE 4.5s

Relevant log output (21.0.1_12-jdk-alpine)

#0 building with "default" instance using docker driver
#1 [internal] load .dockerignore
#1 transferring context: 41B done
#1 DONE 0.1s
#2 [internal] load build definition from dockerfile
#2 transferring dockerfile: 331B done
#2 DONE 0.1s
#3 [internal] load metadata for custom-artifactory.com/eclipse-temurin:21.0.1_12-jdk-alpine
#3 ...
#4 [auth] eclipse-temurin:pull token for custom-artifactory.com
#4 DONE 0.0s
#3 [internal] load metadata for custom-artifactory.com/eclipse-temurin:21.0.1_12-jdk-alpine
#3 DONE 0.3s
#5 [1/3] FROM custom-artifactory.com/eclipse-temurin:21.0.1_12-jdk-alpine@sha256:075f8207cbfecf7e509e2d93e2ffc36c097b52a8109a9bfd40326fa12bd5c438
#5 resolve custom-artifactory.com/eclipse-temurin:21.0.1_12-jdk-alpine@sha256:075f8207cbfecf7e509e2d93e2ffc36c097b52a8109a9bfd40326fa12bd5c438 0.0s done
#5 sha256:c926b61bad3b94ae7351bafd0c184c159ebf0643b085f7ef1d47ecdc7316833c 3.15MB / 3.40MB 0.1s
#5 sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc 3.15MB / 13.14MB 0.1s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 0B / 157.66MB 0.1s
#5 sha256:075f8207cbfecf7e509e2d93e2ffc36c097b52a8109a9bfd40326fa12bd5c438 549B / 549B done
#5 sha256:7e1c2f37fffae18238a4bb018080a0a46d23bfe646d0e1eaacb35a4fdf383a2d 1.37kB / 1.37kB done
#5 sha256:c9017e7c8441517b002e05be8e72b0032d6d55e108e720c8ac6a5255d5611baa 4.94kB / 4.94kB done
#5 sha256:c926b61bad3b94ae7351bafd0c184c159ebf0643b085f7ef1d47ecdc7316833c 3.40MB / 3.40MB 0.1s done
#5 sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc 8.39MB / 13.14MB 0.2s
#5 extracting sha256:c926b61bad3b94ae7351bafd0c184c159ebf0643b085f7ef1d47ecdc7316833c
#5 sha256:1103e3032e0ab2751fa60d490107a4b908c287ed9264496a5285c5127ba8a8b1 176B / 176B 0.1s done
#5 sha256:dab03e20f0bc9420a8ab17a6aa1f2cad9ff28b9394902fedb9e44ef361a7edca 734B / 734B 0.2s done
#5 sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc 10.49MB / 13.14MB 0.3s
#5 sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc 13.14MB / 13.14MB 0.4s done
#5 extracting sha256:c926b61bad3b94ae7351bafd0c184c159ebf0643b085f7ef1d47ecdc7316833c 0.2s done
#5 extracting sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 9.44MB / 157.66MB 0.8s
#5 extracting sha256:e5820a814e8c90e2b86457ad1da29a79516ae242489d7bf67ea216d150c1efdc 0.8s done
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 19.92MB / 157.66MB 1.5s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 33.55MB / 157.66MB 1.9s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 46.14MB / 157.66MB 2.4s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 60.82MB / 157.66MB 2.9s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 74.45MB / 157.66MB 3.3s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 85.98MB / 157.66MB 3.9s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 96.47MB / 157.66MB 4.2s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 106.95MB / 157.66MB 4.5s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 118.49MB / 157.66MB 4.8s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 132.12MB / 157.66MB 5.1s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 140.51MB / 157.66MB 5.3s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 148.90MB / 157.66MB 5.5s
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 157.66MB / 157.66MB 5.8s
#5 extracting sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2
#5 sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 157.66MB / 157.66MB 5.8s done
#5 extracting sha256:fd0a188ff282b81403d8a726aacd5d985ef4761a8a8f5c876dea381e7a9337a2 4.2s done
#5 extracting sha256:1103e3032e0ab2751fa60d490107a4b908c287ed9264496a5285c5127ba8a8b1
#5 extracting sha256:1103e3032e0ab2751fa60d490107a4b908c287ed9264496a5285c5127ba8a8b1 done
#5 extracting sha256:dab03e20f0bc9420a8ab17a6aa1f2cad9ff28b9394902fedb9e44ef361a7edca done
#5 DONE 10.4s
#6 [2/3] RUN apk update && apk add --upgrade apk-tools && apk upgrade --available && rm -rf /var/cache/apk/*
#6 0.298 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
#6 0.483 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
#6 0.748 v3.18.6-7-g0094b6ccd2e [https://dl-cdn.alpinelinux.org/alpine/v3.18/main]
#6 0.748 v3.18.6-6-gc08ed1eac8b [https://dl-cdn.alpinelinux.org/alpine/v3.18/community]
#6 0.748 OK: 20072 distinct packages available
#6 1.058 (1/2) Upgrading libcrypto3 (3.1.4-r1 -> 3.1.4-r5)
#6 1.269 (2/2) Upgrading libssl3 (3.1.4-r1 -> 3.1.4-r5)
#6 1.295 Executing ca-certificates-20230506-r0.trigger
#6 1.428 OK: 40 MiB in 44 packages
#6 1.749 (1/1) Upgrading tzdata (2023c-r1 -> 2023d-r0)
#6 1.950 OK: 40 MiB in 44 packages
#6 DONE 2.3s
#7 [3/3] RUN apk add --no-cache     bash     maven
#7 0.506 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
#7 0.639 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
#7 0.919 (1/20) Installing java-common (0.5-r0)
#7 0.933 (2/20) Installing openjdk17-jre-headless (17.0.10_p7-r0)
#7 2.185 (3/20) Installing libxau (1.0.11-r2)
#7 2.198 (4/20) Installing libmd (1.0.4-r2)
#7 2.237 (5/20) Installing libbsd (0.11.7-r1)
#7 2.251 (6/20) Installing libxdmcp (1.1.4-r2)
#7 2.264 (7/20) Installing libxcb (1.15-r1)
#7 2.284 (8/20) Installing libx11 (1.8.7-r0)
#7 2.324 (9/20) Installing libxext (1.3.5-r2)
#7 2.337 (10/20) Installing libxi (1.8.1-r0)
#7 2.353 (11/20) Installing libxrender (0.9.11-r3)
#7 2.366 (12/20) Installing libxtst (1.2.4-r2)
#7 2.381 (13/20) Installing alsa-lib (1.2.9-r1)
#7 2.407 (14/20) Installing giflib (5.2.1-r4)
#7 2.420 (15/20) Installing libjpeg-turbo (2.1.5.1-r3)
#7 2.440 (16/20) Installing lcms2 (2.15-r2)
#7 2.458 (17/20) Installing openjdk17-jre (17.0.10_p7-r0)
#7 2.495 (18/20) Installing openjdk17-jmods (17.0.10_p7-r0)
#7 3.183 (19/20) Installing openjdk17-jdk (17.0.10_p7-r0)
#7 3.255 (20/20) Installing maven (3.9.2-r0)
#7 3.351 Executing busybox-1.36.1-r5.trigger
#7 3.356 Executing java-common-0.5-r0.trigger
#7 3.362 OK: 325 MiB in 64 packages
#7 DONE 3.7s
@fabian-froehlich fabian-froehlich added the bug Something isn't working label Feb 2, 2024
@gdams
Copy link
Member

gdams commented Feb 2, 2024

@fabian-froehlich I've run your steps and it appears to me that when you download maven inside an Alpine container it downloads the Alpine build of OpenJDK21 rather than using Temurin. I would suggest that the best approach for you would be to switch to the official docker image (maven:3-eclipse-temurin-21-alpine)

@fabian-froehlich
Copy link
Author

fabian-froehlich commented Feb 2, 2024

@gdams good to see, that there is also an image for that! Sadly the issue remains the same for the Java-21 part.

Java 17

$ mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/share/maven
Java version: 17.0.10, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-169-generic", arch: "amd64", family: "unix"

Java 21

$ mvn -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

dockerfile

FROM maven:3-eclipse-temurin-21-alpine
CMD ["bash"]

@gdams
Copy link
Member

gdams commented Feb 3, 2024

that's strange, I'm not able to reproduce this on aarch64 so I'll try on amd64:

/ # mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/share/maven
Java version: 21.0.2, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.4.16-linuxkit", arch: "aarch64", family: "unix"

@gdams
Copy link
Member

gdams commented Feb 3, 2024

I'm also not able to reproduce this on an amd64 box:

/ # mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/share/maven
Java version: 21.0.2, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-126-generic", arch: "amd64", family: "unix"

@gdams
Copy link
Member

gdams commented Feb 3, 2024

@fabian-froehlich I wonder if you're experiencing the same error observed in https://stackoverflow.com/questions/11118237/maven-error-could-not-find-or-load-main-class-org-codehaus-plexus-classworlds-l. Can you please check through the solutions here?

@fabian-froehlich
Copy link
Author

Unfortunately no hint changed anything. I figured out, that when I execute "mvn -v" from within the docker build phase RUN mvn -v it works. But it does not in the final Image. Maybe CMD ["bash"] is the problem?

Interestingly the debug mode of bash shows the error in ci/cd environment and local as well. This time even for the JDK-17 variant of the image:

$ echo $M2_HOME
$ echo $M2
$ echo $M3_HOME
$ echo $JAVA_HOME
/opt/java/openjdk
$ echo $PATH
/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ bash -x mvn -v
+ '[' -z '' ']'
+ '[' -f /usr/local/etc/mavenrc ']'
+ '[' -f /etc/mavenrc ']'
+ '[' -f /root/.mavenrc ']'
+ cygwin=false
+ mingw=false
+ case "`uname`" in
++ uname
+ PRG=mvn
+ '[' -h mvn ']'
++ pwd
+ saveddir=/project/path/image
++ dirname mvn
+ MAVEN_HOME=./..
++ cd ./..
++ pwd
+ MAVEN_HOME=/project/path/common
+ cd /project/path/image
+ false
+ false
+ '[' -z /opt/java/openjdk ']'
+ JAVACMD=/opt/java/openjdk/bin/java
+ '[' '!' -x /opt/java/openjdk/bin/java ']'
++ echo '/project/path/common/boot/plexus-classworlds-*.jar'
+ CLASSWORLDS_JAR='/project/path/common/boot/plexus-classworlds-*.jar'
+ CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+ false
++ find_maven_basedir -v
+++ find_file_argument_basedir -v
++++ pwd
+++ basedir=/project/path/image
+++ found_file_switch=0
+++ for arg in "$@"
+++ '[' 0 -eq 1 ']'
+++ '[' -v = -f -o -v = --file ']'
+++ echo /project/path/image
++ basedir=/project/path/image
++ wdir=/project/path/image
++ '[' /project/path/image '!=' / ']'
++ '[' -d /project/path/image/.mvn ']'
+++ cd /project/path/image/..
+++ pwd
++ wdir=/project/path/common
++ '[' /project/path/common '!=' / ']'
++ '[' -d /project/path/common/.mvn ']'
+++ cd /project/path/common/..
+++ pwd
++ wdir=/builds/pvog
++ '[' /builds/pvog '!=' / ']'
++ '[' -d /project/path/.mvn ']'
+++ cd /project/path/..
+++ pwd
++ wdir=/builds
++ '[' /builds '!=' / ']'
++ '[' -d /builds/.mvn ']'
+++ cd /builds/..
+++ pwd
++ wdir=/
++ '[' / '!=' / ']'
++ echo /project/path/image
+ MAVEN_PROJECTBASEDIR=/project/path/image
++ concat_lines /project/path/image/.mvn/jvm.config
++ '[' -f /project/path/image/.mvn/jvm.config ']'
+ MAVEN_OPTS=' '
+ false
+ export MAVEN_PROJECTBASEDIR
+ MAVEN_CMD_LINE_ARGS='/root/.m2 -v'
+ export MAVEN_CMD_LINE_ARGS
+ exec /opt/java/openjdk/bin/java -classpath '/project/path/common/boot/plexus-classworlds-*.jar' -Dclassworlds.conf=/project/path/common/bin/m2.conf -Dmaven.home=/project/path/common -Dlibrary.jansi.path=/project/path/common/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/project/path/image org.codehaus.plexus.classworlds.launcher.Launcher -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

@gdams
Copy link
Member

gdams commented Feb 5, 2024

Unfortunately no hint changed anything. I figured out, that when I execute "mvn -v" from within the docker build phase RUN mvn -v it works. But it does not in the final Image. Maybe CMD ["bash"] is the problem?

Interestingly the debug mode of bash shows the error in ci/cd environment and local as well. This time even for the JDK-17 variant of the image:

$ echo $M2_HOME
$ echo $M2
$ echo $M3_HOME
$ echo $JAVA_HOME
/opt/java/openjdk
$ echo $PATH
/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ bash -x mvn -v
+ '[' -z '' ']'
+ '[' -f /usr/local/etc/mavenrc ']'
+ '[' -f /etc/mavenrc ']'
+ '[' -f /root/.mavenrc ']'
+ cygwin=false
+ mingw=false
+ case "`uname`" in
++ uname
+ PRG=mvn
+ '[' -h mvn ']'
++ pwd
+ saveddir=/project/path/image
++ dirname mvn
+ MAVEN_HOME=./..
++ cd ./..
++ pwd
+ MAVEN_HOME=/project/path/common
+ cd /project/path/image
+ false
+ false
+ '[' -z /opt/java/openjdk ']'
+ JAVACMD=/opt/java/openjdk/bin/java
+ '[' '!' -x /opt/java/openjdk/bin/java ']'
++ echo '/project/path/common/boot/plexus-classworlds-*.jar'
+ CLASSWORLDS_JAR='/project/path/common/boot/plexus-classworlds-*.jar'
+ CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+ false
++ find_maven_basedir -v
+++ find_file_argument_basedir -v
++++ pwd
+++ basedir=/project/path/image
+++ found_file_switch=0
+++ for arg in "$@"
+++ '[' 0 -eq 1 ']'
+++ '[' -v = -f -o -v = --file ']'
+++ echo /project/path/image
++ basedir=/project/path/image
++ wdir=/project/path/image
++ '[' /project/path/image '!=' / ']'
++ '[' -d /project/path/image/.mvn ']'
+++ cd /project/path/image/..
+++ pwd
++ wdir=/project/path/common
++ '[' /project/path/common '!=' / ']'
++ '[' -d /project/path/common/.mvn ']'
+++ cd /project/path/common/..
+++ pwd
++ wdir=/builds/pvog
++ '[' /builds/pvog '!=' / ']'
++ '[' -d /project/path/.mvn ']'
+++ cd /project/path/..
+++ pwd
++ wdir=/builds
++ '[' /builds '!=' / ']'
++ '[' -d /builds/.mvn ']'
+++ cd /builds/..
+++ pwd
++ wdir=/
++ '[' / '!=' / ']'
++ echo /project/path/image
+ MAVEN_PROJECTBASEDIR=/project/path/image
++ concat_lines /project/path/image/.mvn/jvm.config
++ '[' -f /project/path/image/.mvn/jvm.config ']'
+ MAVEN_OPTS=' '
+ false
+ export MAVEN_PROJECTBASEDIR
+ MAVEN_CMD_LINE_ARGS='/root/.m2 -v'
+ export MAVEN_CMD_LINE_ARGS
+ exec /opt/java/openjdk/bin/java -classpath '/project/path/common/boot/plexus-classworlds-*.jar' -Dclassworlds.conf=/project/path/common/bin/m2.conf -Dmaven.home=/project/path/common -Dlibrary.jansi.path=/project/path/common/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/project/path/image org.codehaus.plexus.classworlds.launcher.Launcher -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

Ahh this makes sense, we removed bash from the alpine image to keep it lightweight. You'll need to manually install it or switch to using sh as your CMD

@fabian-froehlich
Copy link
Author

fabian-froehlich commented Feb 5, 2024

You removed bash only from the JDK-21 image, or from the JDK-17 image as well? Is it not strange, that bash -x mvn -v does produce some output if there is no bash installed in the first place.

In the first post (at the time I was not using the special maven image) I was installing bash with apk add.
Applying this to maven:3-eclipse-temurin-21-alpine did no change. Also using CMD ["sh"] instead of bash had no impact on the error message.

@fabian-froehlich
Copy link
Author

fabian-froehlich commented Feb 7, 2024

Update:
I got the minimal example with maven:3-eclipse-temurin-21-alpine working by selecting another gitlab-runner environment. The config behind and initial setup is not transparent to me. I will reach out to our internal it department. Maybe we find out the conflict in the configuration so I can report it here.

Edit: I am still asking myself, if I would need to execute the maven-entrypoint code somehow, as it seems to copy a few config files that might be necessary in order to get maven working properly.

@fabian-froehlich
Copy link
Author

So the problem is reproducible, but we have not found any difference that explains this behavior.

I can say that these images work

  • maven:3.9.5-eclipse-temurin-17-alpine
  • maven:3.9.6-eclipse-temurin-17-alpine
  • maven:3.9.5-eclipse-temurin-21-alpine

and this one is not

  • maven:3.9.6-eclipse-temurin-21-alpine

The patch version here also hides the fact that the newer image contains the minor version upgrade in alpine linux. We install bash in these images. Running a maven command inside the docker build process RUN mvn - v is no problem.

It looks like the best idea would be to let this slide a bit and wait for the next patch versions of jdk + maven + alpine that might fix this problem.

@fabian-froehlich
Copy link
Author

fabian-froehlich commented Feb 27, 2024

Today we failed to start our spring-boot (3.2.3) application based on the latest image 21.0.2_13-jre-alpine in our kubernetes cluster.
Downgrading to 21.0.1_12-jre-alpine solved that issue.

FROM eclipse-temurin:21.0.2_13-jre-alpine as builder

WORKDIR /home/appuser
ARG JAR_FILE=target/application.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM eclipse-temurin:21.0.2_13-jre-alpine

RUN addgroup -g 1000 appuser && adduser -D -u 1000 -G appuser appuser
WORKDIR /home/appuser

EXPOSE 8080

COPY --from=builder /home/appuser/dependencies/ ./
COPY --from=builder /home/appuser/spring-boot-loader/ ./
COPY --from=builder /home/appuser/snapshot-dependencies/ ./
COPY --from=builder /home/appuser/application/ ./

USER appuser

CMD ["sh", "-c", "exec java org.springframework.boot.loader.launch.JarLauncher"]

Exception

Picked up JAVA_TOOL_OPTIONS: ...
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:94)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
  
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/context/event/ApplicationStartedEvent
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.base/java.lang.Class.getDeclaredMethod(Unknown Source)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:89)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.event.ApplicationStartedEvent

It looks like this problem is no longer Maven related and is a more general problem of interoperability between Java, Alpine and our host system.

Shall I create a new issue for that?

@karianna
Copy link
Contributor

karianna commented Mar 5, 2024

I think we can keep this open for the history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants