gpt4 book ai didi

java - Java 中的 Azure Function 无法在本地运行

转载 作者:行者123 更新时间:2023-12-03 15:34:40 25 4
gpt4 key购买 nike

我正在尝试使用 IntelliJ 在我的 Mac 上本地运行 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 代码尝试了它,但出现了相同的错误。

在java中本地运行Azure Function的唯一方法是使用archetype生成项目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
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

有人有相关问题吗? func 开始为 java 工作吗功能?

最佳答案

语言 worker java的Java路径在安装目录azure-function-core-tools@3/%version/workers/java的配置文件worker.config.json中设置

{
"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%"]
}
}

您需要将 defaultExecutablePath"%JAVA_HOME%/bin/java 更改为 java 可执行文件的绝对路径(例如 /usr/bin/java )。

可以通过readlink -f $(which func)找到安装目录

关于java - Java 中的 Azure Function 无法在本地运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64032219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com