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

Java executable not found depending on container #678

Open
2 of 5 tasks
abbasyadollahi opened this issue Aug 29, 2024 · 3 comments
Open
2 of 5 tasks

Java executable not found depending on container #678

abbasyadollahi opened this issue Aug 29, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@abbasyadollahi
Copy link

Description:
I have a simplified action which sets up Java inside of a container. Depending on the container used, I get an error because it fails to run the the installed Java executable, even though it seems to exist. The Java version doesn't seem to matter.

Task version:
v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
Here's a barebones example of the steps in the GitHub action, where test-docker fails and test-ubuntu works.

...
jobs:
  test-docker:
    runs-on: ubuntu-latest
    container: docker:cli
    steps:
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 11
      - name: Execute Java
        run: |
          which java
          type java
          echo $JAVA_HOME
          echo $PATH
          java --help

  test-ubuntu:
    runs-on: ubuntu-latest
    container: ubuntu:latest
    steps:
      - name: Install docker and docker-compose
        run: |
          apt -y update 
          apt -y install sudo curl
          curl -fsSL https://get.docker.com -o get-docker.sh
          sudo sh ./get-docker.sh
          apt-get install docker-compose-plugin
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 11
      - name: Execute Java
        run: |
          which java
          type java
          echo $JAVA_HOME
          echo $PATH
          java --help

Expected behavior:
I expect both jobs to successfully install the java executable (which they seem to do) and be able to execute it.

Actual behavior:
The test-docker job seems to install the java library properly, but doesn't seem to be able to execute it. On the other hand, the test-ubuntu job installs the java library properly and is able to run the java executable as expected. In both cases, the java lib seems to exists on disk, but the job using the docker:cli image as its container can't find the java executable. Below is an excerpt of the output of the Execute Java step of each job.

test-docker

/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
java is /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/__w/_temp/24f7e9c6-9173-452f-b7b0-833ce68b877a.sh: line 5: /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java: not found

test-ubuntu

/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
java is /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Usage: java [options] <mainclass> [args...]
           (to execute a class)
...
@abbasyadollahi abbasyadollahi added bug Something isn't working needs triage labels Aug 29, 2024
@aparnajyothi-y
Copy link
Contributor

Hello @abbasyadollahi, Thank you for creating this issue and we will look into it :)

@srcimon
Copy link

srcimon commented Sep 8, 2024

Having kind of the same issue here with my project. Mockito cannot find the java executable. I worked around it via pinning the ubuntu version to 24.04. With ubuntu-latest I get:

Caused by: java.lang.reflect.InvocationTargetException
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
	at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:103)
	... 10 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker.

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 21
JVM vendor name    : Eclipse Adoptium
JVM vendor version : 21.0.4+7-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.4+7-LTS
JVM info           : mixed mode, sharing
OS name            : Windows NT
OS version         : 6.5.0-1025-azure

Please let me know if I confuse something here.

@suyashgaonkar
Copy link

Hi @abbasyadollahi , This issue can be resolved by adding an extra step in the job. Following are the steps that you need to add to make the job work. -
name:Install Java
run: |
apk update && \
apk upgrade
apk add openjdk11=11.0.24_p8-r0

To make the job run successfully, we need to install java in the container using the docker's apline package manager to make to get java executable detected.
Please refer to the attached snip.

Screenshot 2024-09-11 at 2 57 36 PM

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

6 participants
@abbasyadollahi @srcimon @aparnajyothi-y @suyashgaonkar and others