英文:
Azure Function in Java does not work locally
问题
我正尝试在我的 Mac 上使用 IntelliJ 本地运行 Azure 函数。我按照此教程的步骤一步一步进行了设置:https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-maven-intellij 但是当我启动项目时,控制台显示以下错误:
Azure Functions Core Tools (3.0.2912 Commit hash: bfcbbe48ed6fdacdf9b309261ecc8093df3b83f2)
Function Runtime Version: 3.0.14287.0
Failed to start Worker Channel. Process fileName: %JAVA_HOME%/bin/java
System.Diagnostics.Process: No such file or directory.
Failed to start language worker process for runtime: (null). workerId:9c6a8dfb-6dcc-4e3c-82a6-0ce0c6949991
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
Hosting environment: Production
Content root path: /Users/mariojaros/Library/Mobile Documents/com~apple~CloudDocs/azure-function-examples
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Host lock lease acquired by instance ID '00000000000000000000000086CB0170'.
^CApplication is shutting down...
我认为问题可能出在语言 worker 部分。
JAVA_HOME:
which java
/usr/bin/java
我还尝试了 func start
,但结果相同,最后我尝试了 Visual Studio Code,但出现了相同的错误。
我唯一能够在本地运行 Java 的 Azure 函数的方法是使用原型生成项目:mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=8
,然后运行 mvn package
和 mvn azurefunctions:run
。
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< sk.devy:rendering-skuska >----------------------
[INFO] Building Azure Java Functions 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- azure-functions-maven-plugin:1.4.0:run (default-cli) @ rendering-skuska ---
[WARNING] Azure Functions only support JDK 8, which is lower than local JDK version 14.0.1
WARNING: An illegal reflective access operation has occurred
...
...
...
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Host lock lease acquired by instance ID '000000
是否有其他人遇到类似的问题?func start
在 Java 函数中工作吗?
英文:
I am trying to run Azure function locally on my mac with IntelliJ. I did everything, step by step in this tutorial: https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-maven-intellij but when I start the project console show me error that
`Azure Functions Core Tools (3.0.2912 Commit hash: bfcbbe48ed6fdacdf9b309261ecc8093df3b83f2)
Function Runtime Version: 3.0.14287.0
Failed to start Worker Channel. Process fileName: %JAVA_HOME%/bin/java
System.Diagnostics.Process: No such file or directory.
Failed to start language worker process for runtime: (null). workerId:9c6a8dfb-6dcc-4e3c-82a6-0ce0c6949991
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
Hosting environment: Production
Content root path: /Users/mariojaros/Library/Mobile Documents/com~apple~CloudDocs/azure-function-examples
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Host lock lease acquired by instance ID '00000000000000000000000086CB0170'.
^CApplication is shutting down...
`
I think that problem is with language worker.
JAVA_HOME:
which java
/usr/bin/java
I was trying func start too and it was same result and finally I tried it with Visual studio code and the same error.
Only way how I can run Azure Function locally in java is when I generate project with archetype mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=8
and then mvn package
mvn azurefunctions:run
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< sk.devy:rendering-skuska >----------------------
[INFO] Building Azure Java Functions 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- azure-functions-maven-plugin:1.4.0:run (default-cli) @ rendering-skuska ---
[WARNING] Azure Functions only support JDK 8, which is lower than local JDK version 14.0.1
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields (file:/Users/mariojaros/.m2/repository/com/microsoft/azure/applicationinsights-core/2.5.1-BETA/applicationinsights-core-2.5.1-BETA.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Azure Function App's staging directory found at: /Users/mariojaros/rendering-skuska/target/azure-functions/rendering-skuska-1600871852849
[INFO] Azure Functions Core Tools found.
Azure Functions Core Tools (3.0.2912 Commit hash: bfcbbe48ed6fdacdf9b309261ecc8093df3b83f2)
Function Runtime Version: 3.0.14287.0
Worker process started and initialized.
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Functions:
HttpTrigger-Java: [GET,POST] http://localhost:7071/api/HttpTrigger-Java
For detailed output, run func with --verbose flag.
Hosting environment: Production
Content root path: /Users/mariojaros/rendering-skuska/target/azure-functions/rendering-skuska-1600871852849
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Host lock lease acquired by instance ID '000000
Has anybody relative problem ? Is func start working for java
functions ?
答案1
得分: 23
Path to Java for language worker java is set in configuration file worker.config.json
in the installation directory azure-function-core-tools@3/%version/workers/java
.
{
"description": {
"language": "java",
"extensions": [".jar"],
"defaultExecutablePath": "/usr/bin/java",
"defaultWorkerPath": "azure-functions-java-worker.jar",
"arguments": ["-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify -Djava.net.preferIPv4Stack=true -jar", "%JAVA_OPTS%"]
}
}
You need to change defaultExecutablePath from "%JAVA_HOME%/bin/java
to the absolute path of your java executable (e.g. /usr/bin/java
).
You can find the installation directory with readlink -f $(which func)
.
英文:
Path to Java for language worker java is set in configuration file worker.config.json
in the installation directory azure-function-core-tools@3/%version/workers/java
{
"description": {
"language": "java",
"extensions": [".jar"],
"defaultExecutablePath": "/usr/bin/java",
"defaultWorkerPath": "azure-functions-java-worker.jar",
"arguments": ["-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify -Djava.net.preferIPv4Stack=true -jar", "%JAVA_OPTS%"]
}
}
You need to change defaultExecutablePath from "%JAVA_HOME%/bin/java
to the absolute path of your java executable (e.g. /usr/bin/java
).
You can find the installation directory with readlink -f $(which func)
答案2
得分: 19
我在安装了最新版本的 IDEA IntelliJ 和带有 Azure Toolkit for IntelliJ 插件的情况下,开始在新的笔记本电脑上针对现有项目安装 Azure Core Tools v3 后收到此错误。
在本地运行 Azure Functions 时,控制台中出现的第一个错误是:
"Failed to start Worker Channel. Process fileName: %JAVA_HOME%/bin/java"
因此,对于在 IntelliJ 中使用 Azure Functions 并遇到此错误的任何人,可以在“运行/调试配置”中为“运行 Functions”配置设置 JAVA_HOME。
只需将其添加到 App Settings 中,将其指向 Java 根文件夹的正确位置。
例如,在 Windows 上,如果您已安装了 Azure 支持的 SDK v11(LTS 版本)(又名用于 Azure 的 Zulu v11),则它安装在主目录下
"C:\Program Files\Zulu\zulu-11",其中 java.exe
位于完整路径 C:\Program Files\Zulu\zulu-11\bin\java.exe
中。
因此,您将添加键值对:
Key = "JAVA_HOME"
Value = "C:\Program Files\Zulu\zulu-11"
英文:
I started receiving this error after installing the latest versions of IDEA IntelliJ w/ Azure Toolkit for IntelliJ plugin, & Azure Core Tools v3 with and existing project on a new laptop.
The first error in the console when running the Azure Functions locally was:
Failed to start Worker Channel. Process fileName: %JAVA_HOME%/bin/java
So, for anyone getting this error using IntelliJ with Azure Functions, the JAVA_HOME can be set in the Run/Debug configuration for the Run Functions
configuration.
Just add it to the App Settings, pointing to the correct location for Java root folder.
For example, on Windows if you've installed the Azure Supported SDK v11 (LTS version) (aka Zulu v11 for Azure) then it is installed into the Home path
C:\Program Files\Zulu\zulu-11
whereby java.exe
is located in the fully qualified path C:\Program Files\Zulu\zulu-11\bin\java.exe
So you would add the Key Value Pair:
Key= "JAVA_HOME"
Value = "C:\Program Files\Zulu\zulu-11"
答案3
得分: 7
我遇到了这个问题,并且发现了由zeretbird提供的解决方案对我几乎起了作用。但是我不得不在我的local.setting.json文件中添加JAVA_HOME和路径,就像这样:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "java",
"StoreServiceendpoint": "blabla",
"StoreServiceKey": "blabla",
"JAVA_HOME": "/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home"
}
}
英文:
i had this issue and found the solution provided by zeretbird almost worked for me. but i had to put JAVA_HOME and the path in my local.setting.json like so.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "java",
"StoreServiceendpoint": "blabla",
"StoreServiceKey": "blabla",
"JAVA_HOME": "/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home"
}
}
答案4
得分: 7
你可以在 VS Code 的 local.settings.json 中添加 JAVA_HOME。
以下是一个示例。
操作系统:WSL Ubuntu-20.04
代码编辑器:VS Code
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "java",
"JAVA_HOME": "/usr"
}
}
英文:
You can add JAVA_HOME in local.settings.json in the VS Code.
Here is an example.
OS: WSL Ubuntu-20.04
Code editor: VS Code
{
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "java",
"JAVA_HOME": "/usr"
}
}
答案5
得分: 3
如果您在 Mac 上使用 core-tool@3,并且希望将 JAVA_HOME 设置为 IntelliJ 运行配置中的 App 设置。https://i.stack.imgur.com/ED3YQ.png
另外:使用 which func
是不起作用的,您必须使用实际二进制文件的路径,该二进制文件位于由 which
找到的包装器旁边。它的位置在这里(如果您使用 npm 安装):/usr/local/lib/node_modules/azure-functions-core-tools/bin/func
英文:
If your are using core-tool@3 on a Mac you can also put the JAVA_HOME as App Setting in the intellij run configuration. https://i.stack.imgur.com/ED3YQ.png
Also: Using the which func
does not work, you have to use the path of the actual binary located next to the wrapper that is found by which
. It is located here (if you installed using npm): /usr/local/lib/node_modules/azure-functions-core-tools/bin/func
答案6
得分: 2
在 macOS 中,变量名为 $JAVA_HOME
,但 Azure 函数仍然寻找 Windows 格式的 %JAVA_HOME%
。因此在路径中找不到任何 Java 可执行文件。
因此,在应用程序运行配置设置中添加 JAVA_HOME
。
英文:
In macOS, the variable name is $JAVA_HOME
, but azure function still find the window format of %JAVA_HOME%
. So it cannot find any java executive file in path.
So add JAVA_HOME
in application run config setting.
答案7
得分: 1
我正在使用 Windows 10 专业版,并在 IntelliJ IDEA 2020.2.3(社区版)中使用 Azure 函数。构建版本号为 #IC-202.7660.26,构建日期为 2020年10月6日。我遇到了相同的问题。
显然它在寻找环境变量 JAVA_HOME。我已经在 Windows 环境变量中进行了添加,如下所示:。设置好之后,我能够在本地运行 Java 函数。
通常在 Windows 操作系统中使用 %JAVA_HOME% 表示法。这可能是一个错误,或者尝试在配置文件级别设置 JAVA_HOME,并确保它指向正确的 JDK。
这只是一种偶然情况,不知何故它奏效了。希望对你也有效。
英文:
I am using windows 10 professional and using azure function using IntelliJ IDEA 2020.2.3 (Community Edition) Build #IC-202.7660.26, built on October 6, 2020. I ran into the same issue .
Apparently it is looking for environment variable JAVA_HOME. I have added the in windows environment variables . After setting this up I was able to run the java function locally.
Generally %JAVA_HOME% notation is used for windows operating system. It might be a bug or try setting JAVA_HOME at profile level and make sure it points to right JDK .
This was just a fluke , somehow it worked . Hope it works for you too .
答案8
得分: 1
Solution for macOS:
- 在终端中执行以下命令,确认已安装的 Java 虚拟机(jvms):
/usr/libexec/java_home -V
- 前往 "Run",然后点击 "Edit Configurations"。编辑 Azure Functions 中的运行函数。在 "App Settings" 中添加一个键为 "JAVA_HOME",值为在步骤 1 中获得的 JVM 路径。
英文:
Solution for macOS
- Confirm the jvms installed, execute this in a terminal
/usr/libexec/java_home -V
- Go to Run, then Edit Configurations. Edit the Run Function in Azure Functions. In App Settings add JAVA_HOME as key and the path to the JVM obtained in 1)
答案9
得分: 0
你可以尝试在VS Code中使用“远程开发(Remote Development)”作为更快捷、更简便的选项。请参考这里的教程。
这里有一个关于Java开发环境的示例。
你需要安装“Remote Development”扩展,并建议选择“Remote-Container”。尝试Java的示例。
扩展链接:https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers&WT.mc_id=azurespringcloud-github-judubois
设置环境教程链接:https://github.com/microsoft/azure-spring-cloud-training/blob/master/00-setup-your-environment/AlternateSetup.md#preparing-visual-studio-code
更多问题请查阅:https://code.visualstudio.com/docs/remote/faq#_remote-containers
英文:
You may try "Remote Development" in VS code as a quicker and easier option. Please refer to the tutorial here
Here is one example of java dev environment
You will have to install Remote Development extension and would suggest Remote-Container. Try sample for Java.
https://code.visualstudio.com/docs/remote/faq#_remote-containers
答案10
得分: 0
一个修复方案正在进行中。详细情况在此处进行跟踪:
https://github.com/Azure/azure-functions-core-tools/issues/3294
建议在localsettings.host.json中设置JAVA_HOME,而不是修改worker.config.json(从技术上讲仍然有效)。
关键是目前在/usr/bin/java中的别名将无法正常工作,这就是为什么像adam
所展示的解决方法能够正常工作,您需要指向实际的java二进制文件所在的Library/install文件夹。
英文:
A fix is being worked on. Details are tracked here:
https://github.com/Azure/azure-functions-core-tools/issues/3294
Setting JAVA_HOME in localsettings.host.json is recommended over altering worker.config.json (which is still technically valid).
The trick is that currently an alias in /usr/bin/java will not work and that's why a workaround like adam
shows will work where you point to the actual Library/install folder of the java binary instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论