Java function will not run on Mac/MacM1/Linux without JAVA_HOME changes
See original GitHub issueIf 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:
- Created 7 months ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
Hi, I set
JAVA_HOME
to/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home
inlocal.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.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?