Skip to content

Java executable not found on ubuntu-latest, after installing with actions/setup-java@v4 #840

Closed
@j0nathontayl0r

Description

@j0nathontayl0r

Description:
I'm installing Java using the action-setup-java@v4. However I can't execute the Java binary though it is found in the path, and I can see the binary on the actions file system.

Action to install Java:

      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          check-latest: true

Debugging script:

      - name: Semgrep Scan
        run: |
          chmod +x $JAVA_HOME/bin/java
          echo "Path is: $PATH"
          echo "JAVA_HOME is: $JAVA_HOME"
          echo "JAVA_HOME_21_X64 is $JAVA_HOME_21_X64"
          echo "Which Java? $(which java)"
          echo "Which Java version? $(java -version)"
          echo "What files are found in $JAVA_HOME_21_X64/bin? $(ls -la $JAVA_HOME_21_X64/bin)"
          echo "What files are found in $JAVA_HOME/bin? $(ls -la $JAVA_HOME/bin)"
          $JAVA_HOME_21_X64/bin/java -version
          semgrep ci --allow-local-builds --verbose

Output in my action is below:

Path is: /__t/Java_Temurin-Hotspot_jdk/21.0.7-6.0.LTS/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
JAVA_HOME is: /__t/Java_Temurin-Hotspot_jdk/21.0.7-6.0.LTS/x64
JAVA_HOME_21_X64 is /__t/Java_Temurin-Hotspot_jdk/21.0.7-6.0.LTS/x64
Which Java? /__t/Java_Temurin-Hotspot_jdk/21.0.7-6.0.LTS/x64/bin/java
/__w/_temp/179145c7-767b-4d7c-b398-5aaa1a0e8ada.sh: line 5: java: not found
Which Java version? 
What files are found in /__t/Java_Temurin-Hotspot_jdk/21.0.7-6.0.LTS/x64/bin? total 468
drwxr-xr-x    2 root     root          4096 May 22 03:39 .
drwxrwxrwx    9 root     root          4096 May 22 03:40 ..
-rwxr-xr-x    1 root     root         12304 May 22 03:39 jar
-rwxr-xr-x    1 root     root         12304 May 22 03:39 jarsigner
-rwxr-xr-x    1 root     root         12248 May 22 03:39 java

Task version:
v4

Platform:

  • Ubuntu

Runner type:

  • Hosted

Repro steps:
Tried using java-version: '17' and java-version: '21', no change.

Expected behavior:
java -version should work.

Actual behavior:
Getting "java not found" when trying to execute it, even when using absolute path.

E.g., both of the below don't work:

$JAVA_HOME_21_X64/bin/java -version
java -version

Here's the whole action pipeline:

name: Shared Deploy

permissions:
  contents: read
  id-token: write

env:
  ENVIRONMENT: ${{ inputs.ENVIRONMENT }}

jobs:

  semgrep:
    name: Scan
    #continue-on-error: false
    runs-on: ubuntu-latest
    container:
      image: semgrep/semgrep
    env:
      SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          check-latest: true
      #- run: java HelloWorldApp.java # commented out, not working
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Semgrep Scan
        run: |
          chmod +x $JAVA_HOME/bin/java
          echo "Path is: $PATH"
          echo "JAVA_HOME is: $JAVA_HOME"
          echo "JAVA_HOME_21_X64 is $JAVA_HOME_21_X64"
          echo "Which Java? $(which java)"
          echo "Which Java version? $(java -version)"
          echo "What files are found in $JAVA_HOME_21_X64/bin? $(ls -la $JAVA_HOME_21_X64/bin)"
          echo "What files are found in $JAVA_HOME/bin? $(ls -la $JAVA_HOME/bin)"
          $JAVA_HOME_21_X64/bin/java -version

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions