Problem description
I have my Java library A and I create a new Azure Functions module B (following https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-maven-intellij), which should use A as a dependency.
Now:
- if I create B as a new and standalone module, it works;
- if I add B as another submodule of a common parent C, it does not.
More specifically: no problems with compilation, running and deployment of my functions, but when any of them is triggered I get a ClassNotFoundException for each class defined in A. And no wonder it happens, since A.jar is not present in the lib subfolder of the Azure Function's run folder (something like {myUser}\AppData\Local\Temp\azure-functions16636049357177434984 on my Windows PC in case of local run). But I don't understand why the dependency jar is not copied there, especially that after compilation it's present in the target\azure-functions\taxclaims-azure-1596530670055\lib folder of my IntelliJ project.
Why does this happen and how to fix it?
Minimal example
I have TestParent Java Maven project, with two modules:
- dependency-module
- azure-functions-module (depending on dependency-module)
In dependency-module I have a DependencyClass with empty body, whereas in azure-functions-module I have HttpTriggerFunction class with the following method:
@FunctionName("TestFunction")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context)
{
DependencyClass instance = new DependencyClass();
return request.createResponseBuilder(HttpStatus.OK).body("OK").build();
}
This module can be successfully deployed, but when the TestFunction is triggered, I obtain ClassNotFoundException for DependencyClass.
However, if I create another project, called TestStandaloneParent, with a module standalone-azure-functions-module and the same function as above, then everything works smoothly.
If needed of course I can add further details, especially the pom.xml files.