question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java function will not run on Mac/MacM1/Linux without JAVA_HOME changes

See original GitHub issue

If I follow the VS Code quickstart on a Mac or Mac1, the app will start but ultimately will not run at runtime. I get gRPC errors between host and worker like this:

Failed to attach to remote debuggee VM. Reason: java.net.ConnectException: Connection refused..Core Tools Version:       4.0.4915 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.14.0.19631 
Functions:         HttpExample: [GET,POST] http://localhost:7071/api/HttpExample For detailed output, run func with --verbose flag.
[2023-02-27T18:42:17.709Z] Host lock lease acquired by instance ID '000000000000000000000000731A3487'.
[2023-02-27T18:43:12.593Z] Starting worker process failed
[2023-02-27T18:43:12.593Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
[2023-02-27T18:43:12.661Z] Failed to start a new language worker for runtime: java.
[2023-02-27T18:43:12.661Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.

The reason explained to me by the team, is the worker.config.json under the Azure Core Tools is looking at this path which either exactly has to match your java path, or needs to be overridden by a classical JAVA_HOME environment variable on Mac or Linux.
“defaultExecutablePath”: “%JAVA_HOME%/bin/java”,

Since I installed Java on my Mac M1 using homebrew using Microsoft’s Adopt OpenJDK, the path returned by which java is actually /usr/bin/java. When I try /usr as path it still does not work (keeping in mind the tools append /bin/java for you so leave that out. We believe this is actually an alias and that might be a root cause issue.

The workaround that finally works is as follows. Create a local.settings.json file with the following contents and place it in the same folder next to host.json.

Mac and Mac M1 (homebrew installs to /Library/Java/JavaVirtualMachines/JDKVERSION/Contents/Home/bin/java)

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "java",
    "JAVA_HOME": "/Library/Java/JavaVirtualMachines/microsoft-17.jdk/Contents/Home"
    }
}

Note that I have microsoft-17.jdk but you’ll have to replace with the path and version to your JDK.

Windows WSL2 (installs to /bin/java so home path is /)

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "java",
    "JAVA_HOME": "/"
    }
}

The expected fixes could be some or all of the following:

  • return a helpful java not found in JAVA_HOME error
  • enable core tools to understand /usr/bin/java type paths
  • update docs with workarounds/guidance for Mac and Linux per above

Issue Analytics

  • State:open
  • Created 7 months ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dkontykocommented, Mar 28, 2023

Hi, I set JAVA_HOME to /Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home in local.settings.java, but I still get the same error: “Failed to start Worker Channel. Process fileName: %JAVA_HOME%/bin/java”. Am I missing a step beyond updating and saving that settings file, then rerunning the function? Thanks.

Edit: And of course I figured it out right after I posted this. I had to set JAVA_HOME in the run configuration settings. Just setting it in the local.setttings.json wasn’t working.

image

1reaction
paulyukcommented, Mar 23, 2023

Yes @kaibocai you are right i misdiagnosed. the issue is like you say setting to usr.

However, I think the right behavior is to first try JAVA_HOME, but then fall back to PATH. Most JDKs have /usr/bin in the path, and therefore your /usr/bin/java will work with NO JAVA_HOME set, just like Maven. Could we consider that instead?

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - JAVA_HOME set but not taking effect
To fix this just move up the "%JAVA_HOME%/bin" as a first entry in path variable. Share.
Read more >
Why is java -version returning a different version to the one ...
Start -> Control Panel -> System -> Advanced · Click on Environment Variables, under System Variables, find PATH , and click on it....
Read more >
usr/libexec/java_home is completely broken on Big Sur
In my case if JAVA_HOME is not set, then the java_home command will not output anything at all. Even the -V option or...
Read more >
Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux
Click OK and click Apply to apply the changes. Open Command Prompt and check the value of the JAVA_HOME variable: echo %JAVA_HOME%. The...
Read more >
Setting the JAVA_HOME Variable in Windows
Locate your Java installation directory · Do one of the following: · Click the Environment Variables button. · Under System Variables, click New....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found