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

The JAVA_HOME environment variable is not defined correctly, #358

Closed
sharon-go opened this issue Nov 10, 2022 · 4 comments
Closed

The JAVA_HOME environment variable is not defined correctly, #358

sharon-go opened this issue Nov 10, 2022 · 4 comments

Comments

@sharon-go
Copy link

sharon-go commented Nov 10, 2022

Hey,

On my local server echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

docker-compose.yml
version: "3"
services:
maven:
# Run pre-built maven image from docker library
image: maven
volumes:
# Cache maven dependencies
- $HOME/.m2:/root/.m2
# Mount the application source and target directories
- ..:/app
# Run maven inside the application directory
working_dir: /app
volumes:
maven-repository:

pipeline.yml
steps:

  • label: ":maven: :package:"
    command: mvn clean install -P local
    artifact_paths: "target/*.jar"
    plugins:
    • docker-compose#v4.5.0:
      run: maven
      config: .buildkite/docker-compose.yml

when trying to build my java project getting this error:

docker-compose -f .buildkite/docker-compose.yml -p buildkite0184627a9f4e4fc4b0452a9bdce7c59b run --name buildkite0184627a9f4e4fc4b0452a9bdce7c59b_maven_build_49 --rm maven /bin/sh -e -c 'mvn clean install -P local'
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

user command error: The plugin docker-compose command hook exited with status 1

@toote
Copy link
Contributor

toote commented Nov 10, 2022

@sharon-go from what I can read, the error comes from your docker image so that means that the variable is not defined correctly in the environment inside the container. The fact that it is defined in your machine is irrelevant... unless you pass it on, which I wouldn't recommend because probably the path specified in that variable wouldn't be the same.

That said, assuming you are running the official and latest maven image as mentioned, that variable is indeed defined when the image is created and it is propagated when running as well:

$ docker run --rm -ti maven:latest /bin/sh -c 'env | sort | grep JAVA'
JAVA_HOME=/opt/java/openjdk
JAVA_VERSION=jdk-17.0.5+8

I can duplicate the error if I replace the variable with another value:

$ docker run --rm -ti -e JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home maven 
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

So the issue appears to be that either your docker compose file or your plugin's configuration is replacing the variable as it comes in the image to an invalid value :(

@toote toote closed this as completed Nov 10, 2022
@sharon-go
Copy link
Author

sharon-go commented Nov 14, 2022

Hey,

Look like an issue in docker-maven
carlossg/docker-maven#282

I did try to run the mvn command using your example same issue:
docker run --rm -ti maven:latest /bin/sh -c 'mvn --version'
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

docker run --rm -ti maven:latest /bin/sh -c 'env | sort | grep JAVA'
JAVA_HOME=/opt/java/openjdk
JAVA_VERSION=jdk-17.0.5+8

@toote
Copy link
Contributor

toote commented Nov 14, 2022

@sharon-go glad to know that it is a compatibility issue between the latest maven images and old docker daemons and not something in this plugin :)

@sharon-go
Copy link
Author

Yes this is the issue :)

Thank you .

docker run --rm -ti maven:latest /bin/sh -c 'mvn --version'
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/share/maven
Java version: 17.0.5, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.49-linuxkit", arch: "amd64", family: "unix"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants