I’m having some trouble with a container deployed on AWS.
I was using gradle 8.1.1 and tried 8.7 but still see the same behavior.
The error I’m getting is:
ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk [Link ](/cloudwatch/home?region=us-west-2#logsV2:log-groups/log-group/mylg/log-events/myservice%2Fmyservice%2Fef20fd37-fa41-4942-b502-f681f193b30e?start=1712007417875$26end=1712007717875) ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk
The part it’s dying on is this from the service start script:
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
My Dockerfile is:
FROM eclipse-temurin:11
ARG product_name
ARG product_version
ENV PRODUCT_NAME=$product_name
ENV PRODUCT_VERSION=$product_version
ENV JAVA_HOME=/opt/java/openjdk
# Who to contact if there are issues
LABEL maintainer="devteam@mycompany.com"
# Primary directory
WORKDIR /opt/mycompany/
# Copy the distribution to the primary dir
# ADD also automatically un-tars
ADD $PRODUCT_NAME-$PRODUCT_VERSION.tar /opt/mycompany/
# Make the script executable
RUN chmod +x /opt/mycompany/$PRODUCT_NAME-$PRODUCT_VERSION/bin/$PRODUCT_NAME
# Desginate the script to start at launch
ENTRYPOINT ["sh", "-c", "/opt/mycompany/$PRODUCT_NAME-$PRODUCT_VERSION/bin/myservice"]
I’ve carefully take apart the Docker container and can see the directory /opt/java/openjdk/bin contains a java executable.
I’ve tried playing with customizing the unixStartScriptTemplate.txt file, but that doesn’t seem to work. I got errors about not being able to write to build/distributions when I could see the directory is present.
gsexton-T60GTHPQ96:image gsexton$ ls -alh opt
total 0
drwxr-xr-x 4 gsexton staff 128B Apr 1 12:50 .
drwxr-xr-x 23 gsexton staff 736B Apr 1 16:14 ..
drwxr-xr-x 4 gsexton staff 128B Jun 15 2023 java
gsexton-T60GTHPQ96:image gsexton$ ls -alh opt/java
total 0
drwxr-xr-x 4 gsexton staff 128B Jun 15 2023 .
drwxr-xr-x 4 gsexton staff 128B Apr 1 12:50 ..
-rwxr-xr-x 1 gsexton staff 0B Dec 31 1969 .wh..wh..opq
drwxr-xr-x 11 gsexton staff 352B Jun 15 2023 openjdk
gsexton-T60GTHPQ96:image gsexton$ ls -alh opt/java/openjdk
total 16
drwxr-xr-x 11 gsexton staff 352B Jun 15 2023 .
drwxr-xr-x 4 gsexton staff 128B Jun 15 2023 ..
-rw-r--r-- 1 gsexton staff 2.3K Apr 18 2023 NOTICE
drwxr-xr-x 35 gsexton staff 1.1K Apr 18 2023 bin
drwxr-xr-x 7 gsexton staff 224B Apr 18 2023 conf
drwxr-xr-x 9 gsexton staff 288B Apr 18 2023 include
drwxr-xr-x 73 gsexton staff 2.3K Apr 18 2023 jmods
drwxr-xr-x 73 gsexton staff 2.3K Apr 18 2023 legal
drwxr-xr-x 52 gsexton staff 1.6K Apr 18 2023 lib
drwxr-xr-x 5 gsexton staff 160B Apr 18 2023 man
-rw-r--r-- 1 gsexton staff 1.6K Apr 18 2023 release
gsexton-T60GTHPQ96:image gsexton$ ls -alh opt/java/openjdk/bin
total 1264
drwxr-xr-x 35 gsexton staff 1.1K Apr 18 2023 .
drwxr-xr-x 11 gsexton staff 352B Jun 15 2023 ..
-rwxr-xr-x 1 gsexton staff 12K Apr 18 2023 java
I’m probably overlooking something simple, but I’m just not seeing it.
Any help would be appreciated.