azure function java class NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientSecure

haridas 6 Reputation points
2021-11-10T03:34:52.953+00:00

Have a project that sends azure sms using communication package. Function is http triggered and works locally and sends sms as expected. On Azure, function log shows below . Below is the error and pom.xml. Any help is appreciated.

Result: Failure Exception: NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientSecure Stack: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22) at ...

Below is a pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"\>
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>azure-function-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Azure Java Functions</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.17</java.version>
    <azure.functions.maven.plugin.version>1.14.0</azure.functions.maven.plugin.version>
    <azure.functions.java.library.version>1.4.2</azure.functions.java.library.version>
    <functionAppName>smsxxxx</functionAppName>
</properties>

<dependencies>



    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-communication-sms</artifactId>
        <version>1.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.microsoft.azure.functions</groupId>
        <artifactId>azure-functions-java-library</artifactId>
        <version>${azure.functions.java.library.version}</version>
    </dependency>



    <!-- Test -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.4.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.23.4</version>
        <scope>test</scope>
    </dependency>



</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-functions-maven-plugin</artifactId>
            <version>${azure.functions.maven.plugin.version}</version>
            <configuration>
                <!-- function app name -->
                <appName>${functionAppName}</appName>
                <!-- function app resource group -->
                <resourceGroup>${resourceGroup}</resourceGroup>
                <!-- function app service plan name -->
                <appServicePlanName>${appPlan}</appServicePlanName>
                <!-- function app region-->
                <!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-regions for all valid values -->
                <region>eastus</region>
                <!-- function pricingTier, default to be consumption if not specified -->
                <!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-pricing-tiers for all valid values -->
                <!-- <pricingTier></pricingTier> -->

                <!-- Whether to disable application insights, default is false -->
                <!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details for all valid configurations for application insights-->
                <!-- <disableAppInsights></disableAppInsights> -->
                <runtime>
                    <!-- runtime os, could be windows, linux or docker-->
                    <os>linux</os>
                    <javaVersion>${javaVersion}</javaVersion>
                    <!-- for docker function, please set the following parameters -->
                    <!-- <image>[hub-user/]repo-name[:tag]</image> -->
                    <!-- <serverId></serverId> -->
                    <!-- <registryUrl></registryUrl>  -->
                </runtime>
                <appSettings>
                    <property>
                        <name>FUNCTIONS_EXTENSION_VERSION</name>
                        <value>~3</value>
                    </property>
                </appSettings>
            </configuration>
            <executions>
                <execution>
                    <id>package-functions</id>
                    <goals>
                        <goal>package</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!--Remove obj folder generated by .NET SDK in maven clean-->
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>obj</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,670 questions
{count} votes

1 answer

Sort by: Most helpful
  1. haridas 6 Reputation points
    2021-12-29T19:21:16.457+00:00

    @MughundhanRaveendran-MSFT , thanks for your help. Looked at the post you recommended, did resolve the issue with doing below.

    FUNCTIONS_WORKER_JAVA_LOAD_APP_LIBS = 1. Still needed this to work. Need to be added to application settings. This loads
    the client libs before the azure function libs. This is needed due to java version differences.

    2) Maven dependency tree was helpful to identify libs in conflict. Remediating them directly in POM.xml by making the correct lib version required dependent directly to app and having exclusions that are not required.

    3) Going to granularity level where the problem exist. That is checking what is not playing nicer. If there is an azure storage lib, azure function lib and azure communication lib, having app initially with 2 dependencies such as storage and function and if all works well then add 3rd communication else resolve the conflict with step 2 and then add new lib needed.

    1 person found this answer helpful.
    0 comments No comments