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

Maven needs JAVA_HOME set to: /usr/lib/jvm/java-1.8.0-amazon-corretto/jre #481

Open
dss010101 opened this issue Dec 12, 2023 · 7 comments
Open
Labels
bug Something isn't working

Comments

@dss010101
Copy link

dss010101 commented Dec 12, 2023

If JAVA_HOME is /usr/lib/jvm/java-1.8.0-amazon-corretto, maven complains:

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

Setting JAVA_HOME to /usr/lib/jvm/java-1.8.0-amazon-corretto/jre
resolves the issue, but not sure of broader impact in doing so.

@dss010101 dss010101 added the bug Something isn't working label Dec 12, 2023
@benty-amzn
Copy link
Contributor

Can you share which Corretto package(s) you currently have installed?

The value /usr/lib/jvm/java-1.8.0-amazon-corretto should work if you have a full jdk installed (package may have, for exmaple, -devel suffix, depending on your distribution), while /usr/lib/jvm/java-1.8.0-amazon-corretto/jre is just a runtime environment.

You'll notice in the error message that a full jdk is needed:

NB: JAVA_HOME should point to a JDK not a JRE

@dss010101
Copy link
Author

kage(s) you currently have installed?

in my docker file i have the below

FROM amazonlinux:2023
...
RUN dnf -y install java-1.8.0-amazon-corretto
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto
...

Note im setting the JAVA_HOME env based on what i saw here: corretto/corretto-8-docker@055b9f3

Based on what you state, is the above just the JRE install then?

@dss010101
Copy link
Author

dss010101 commented Dec 13, 2023

rebuilding the container with java-1.8.0-amazon-corretto-devel seems to have resolved the issue. Curious, do i need to explicitly set JAVA_HOME in the case of the *-devel package?

@dss010101
Copy link
Author

rebuilding the container with java-1.8.0-amazon-corretto-devel seems to have resolved the issue. Curious, do i need to explicitly set JAVA_HOME in the case of the *-devel package?

I take this back...it doesnt work with java-1.8.0-amazon-corretto-devel install either.
I had to export JAVA_HOME=/usr/lib/jvm/java

`java-1.8.0-amazon-corretto-devel also seem to install java 17

@lutkerd
Copy link
Contributor

lutkerd commented Dec 13, 2023

java-1.8.0-amazon-corretto-devel should not be installing Java 17, I was not able to reproduce that on a fresh docker.

Are you also installing Maven from the AL2023 yum repositories? If so, that is what is pulling in Java 17. The reason is that Java 17 is the "system Java" for Amazon Linux 2023 and most packages that require Java are built against that version.

You can run dnf repoquery --installed --whatrequires java-17-amazon-corretto-headless to see why java 17 is getting installed. /usr/lib/jvm/java is an alternative setup by the RPMs being installed and should be pointing to the latest installed version. You can run realpath /usr/lib/jvm/java and you should see it pointing to /usr/lib/jvm/java-17-amazon-corretto.x86_64

On a docker I started if I install java-1.8.0-amazon-corretto-devel and maven, I can then switch the Java version that mvn picks up with setting JAVA_HOME

# mvn -v
Apache Maven 3.8.4 (Red Hat 3.8.4-3.amzn2023.0.5)
Maven home: /usr/share/maven
Java version: 17.0.9, vendor: Amazon.com Inc., runtime: /usr/lib/jvm/java-17-amazon-corretto.x86_64
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "5.4.257-177.360.amzn2int.x86_64", arch: "amd64", family: "unix"

bash-5.2# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/
bash-5.2# mvn -v
Apache Maven 3.8.4 (Red Hat 3.8.4-3.amzn2023.0.5)
Maven home: /usr/share/maven
Java version: 1.8.0_392, vendor: Amazon.com Inc., runtime: /usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "5.4.257-177.360.amzn2int.x86_64", arch: "amd64", family: "unix"

@dss010101
Copy link
Author

dss010101 commented Dec 13, 2023

ah..yes, i am installing maven - that answers that bit of confusion.

On the jdk (devel) vs jre - what are the JAVA_HOME supposed to be they seem different. In order to get Maven to find java,

for the JRE, i needed /usr/lib/jvm/java-1.8.0-amazon-corretto/jre
for the JDK, i needed to set /usr/lib/jvm/java

@lutkerd
Copy link
Contributor

lutkerd commented Dec 13, 2023

Maven is looking for $JAVA_HOME/bin/java, see code snippet below, if you are building code you will need javac which is in the java-1.8.0-amazon-corretto-devel package anyway.

if [ -z "$JAVA_HOME" ] ; then
  JAVACMD="`\\unset -f command; \\command -v java`"
else
  JAVACMD="$JAVA_HOME/bin/java"
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "The JAVA_HOME environment variable is not defined correctly," >&2
  echo "this environment variable is needed to run this program." >&2
  exit 1
fi

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