Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function in Java does not work locally

I am trying to run Azure function locally on my mac with IntelliJ. I did everything, step by step in this tutorial: https://docs.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 ?

like image 778
Mário Jaroš Avatar asked Sep 23 '20 16:09

Mário Jaroš


Video Answer


2 Answers

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)

like image 175
Mário Jaroš Avatar answered Sep 28 '22 12:09

Mário Jaroš


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"

As shown here: IntelliJ IDEA Run Configuration for JAVA_HOME variable

like image 45
CajunCoding Avatar answered Sep 28 '22 11:09

CajunCoding