Azurerm_function_app_function - How to create a java Azure Function with code upload

We’ve created an Azure Function using azurerm_function_app_function

  • Terraform v1.1.0
  • Provider azurerm 3.0.2

Terraform code like this:

resource "azurerm_function_app_function" "default" {
  name            = "MyAzureFunction"
  function_app_id = azurerm_linux_function_app.default.id
  language        = "Java"

  file {
    name    = "my-java-app-1.0-SNAPSHOT.jar"
    content = filebase64("my-java-app-1.0-SNAPSHOT.jar")
  }

  config_json = jsonencode({
    "scriptFile" : "my-java-app-1.0-SNAPSHOT.jar",
    "entryPoint" : "com.mypackage.MyClass.runEvent",
    "bindings" : [
      {
        "type" : "eventGridTrigger",
        "direction" : "in",
        "name" : "eventGridEvent"
      }
    ]
  })
}

And Java .jar code is like this:

package com.mypackage;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.EventGridTrigger;
import com.microsoft.azure.functions.annotation.FunctionName;

public class MyClass {

    @FunctionName("MyAzureFunction")
    public void runEvent(@EventGridTrigger(name = "eventGridEvent") String event, final ExecutionContext context) {
        context.getLogger().info("Java Event Grid trigger function executed.");
        context.getLogger().info(event);
    }
}

But unfortunately, we are facing the ClassNotFoundException exception:

Result: Failure Exception: ClassNotFoundException: com.mypackage.MyClass Stack: java.lang.ClassNotFoundException: com.mypackage.MyClass
java.base/java.net.URLClassLoader.findClass(Unknown Source)
java.base/java.lang.ClassLoader.loadClass(Unknown Source)
java.base/java.lang.ClassLoader.loadClass(Unknown Source)
java.base/java.lang.Class.forName0(Native Method)
java.base/java.lang.Class.forName(Unknown Source)
com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.getContainingClass(EnhancedJavaMethodExecutorImpl.java:63)
com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.<init>(EnhancedJavaMethodExecutorImpl.java:22)
com.microsoft.azure.functions.worker.broker.FactoryJavaMethodExecutor.getJavaMethodExecutor(FactoryJavaMethodExecutor.java:20)
com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.loadMethod(JavaFunctionBroker.java:35)
com.microsoft.azure.functions.worker.handler.FunctionLoadRequestHandler.execute(FunctionLoadRequestHandler.java:27)
com.microsoft.azure.functions.worker.handler.FunctionLoadRequestHandler.execute(FunctionLoadRequestHandler.java:9)
com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
java.base/java.util.concurrent.FutureTask.run(Unknown Source)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.base/java.lang.Thread.run(Unknown Source)

Is there some wrong configuration or missing to have our function runnable successfully?

1 Like