0

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.

6
  • Does the azure-functions-module module reference the dependency of the dependency-module module? Commented Oct 19, 2020 at 9:15
  • Yes, I have the suitable dependency in azure-functions-module's pom.xml: <dependency> <groupId>org.example</groupId> <artifactId>dependency-module</artifactId> <version>1.0-SNAPSHOT</version> </dependency> Commented Oct 19, 2020 at 9:38
  • Stupid question: did you analyse the packaged result if your library is packed together with it? Like unpacking it? Commented Oct 20, 2020 at 8:16
  • You mean checking whether the dependency is not inside the jar? No, it's not there. Commented Oct 20, 2020 at 14:44
  • 1
    Looks like the issue has been addressed github.com/microsoft/azure-tools-for-java/issues/7063 Commented Dec 5, 2022 at 22:54

2 Answers 2

1

Please have a look at this other question here: How to add dependency JAR in java azure functions

It looks like a problem with the packaging, you need to tweak it by using the maven assembly plugin config manually.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the link is really useful. Following the approach described there, I have managed to make Maven create a jar with dependencies instead of the "simple" one. However, this only in the target folder of my project. On run/deploy the .jar is still the old one, and I'm quite perplexed about this. I need to spend more time investigating this.
1

It looks like IntelliJ Azure Plugin doesn't use pom.xml. What you can do is to go File->Project structure->Project settings->Modules, choose module with Azure Functions and manually add jar fil as a dependency. In my case I achieve the result, but I'm not happy with the way of solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.