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: Dockerfile-java21. Maven can't find JAVA_HOME #150

Closed
Furion137 opened this issue Nov 6, 2024 · 3 comments
Closed

Bug: Dockerfile-java21. Maven can't find JAVA_HOME #150

Furion137 opened this issue Nov 6, 2024 · 3 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@Furion137
Copy link

Description:

We are trying to migrate small SAM application from Dockerfile-java17 to Dockerfile-java21. But on java21 our Jenkins job fails while trying to do "mvn clean install" with the error message "The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program." We don't have such issues on java17.

In short: could you please check that "/var/lang/bin/java" is runnable in Dockerfile-java21 image? As it is in Dockerfile-java17.

According to my investigations %JAVA_HOME is correctly set to "/var/lang". I suppose that here is the code from maven, given us that error:

if [ -z "$JAVA_HOME" ] ; then
  JAVACMD=`which 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

Indeed when I run "test '!' -x /var/lang/bin/java" in Dockerfile-java21 it gives me true, while in Dockerfile-java17 it returns false. So, could you please check that "/var/lang/bin/java" is runnable in Dockerfile-java21 image, as it is in Dockerfile-java17?

Sorry for not providing all the steps-to-reproduce, environment and the rest. I hope that if you confirm that "/var/lang/bin/java" is not runnable in java21 and change it to be so, than the problem will be solved. If it's not the root cause, then I will try to provide you all the details.

@Furion137 Furion137 added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Nov 6, 2024
@mndeveci
Copy link
Contributor

Hi there,

How are you using this image? You shouldn't be using the Dockerfile-java21 directly, instead you should be using the built images from Public ECR here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-image-repositories.html

I did a quick test to see if mvn clean install would work for an application and I was able to get it run. Here are the steps;

  1. Run build image and drop to its shell docker run -it public.ecr.aws/sam/build-java21 /bin/bash
  2. Instantiate a SAM application with Java21. By running sam init and selecting 1 -> 1 -> N -> 7 -> 1 -> 2 -> (enter) -> (enter) -> (enter) -> (enter)
  3. Go into the function source code by running cd sam-app/HelloWorldFunction/
  4. Run mvn clean install in that folder

With this experiment I was able to run the Maven commands above. Can you try with this image to see if it is going to work for your case?

Thanks!

@mndeveci mndeveci added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 12, 2024
@Furion137
Copy link
Author

Yes, we are using image "public.ecr.aws/sam/build-java21", not the dockerfile directly :-) Hmmm... Let me try it your way...

@Furion137
Copy link
Author

That seems to work locally on my machines with MacOs and Docker 20.10.6 and later. But not on our Jenkins "Amazon Linux AI 2018.03" and Docker 18.09.9-ce, build 039a7df. So we switched to a Jenkins machine with a newer OS and Docker and now it works. Thanks for help!

@Furion137 Furion137 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

2 participants