question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loaded jars under lib folder are not set on classpath after mvn azure-functions:run

See original GitHub issue

Plugin name and version

azure-functions-maven-plugin v0.2.0

Plugin configuration in your pom.xml

<dependencies>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-functions-java-core</artifactId>
        <version>[1.0.0-beta-1,1.0.0)</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-storage</artifactId>
        <version>7.0.0</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <version>0.2.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-functions-maven-plugin</artifactId>
            <configuration>
                <resourceGroup>${functionResourceGroup}</resourceGroup>
                <appName>${functionAppName}</appName>
                <region>${functionAppRegion}</region>
                <appSettings>
                    <property>
                        <name>FUNCTIONS_EXTENSION_VERSION</name>
                        <value>beta</value>
                    </property>
                </appSettings>
            </configuration>
            <executions>
                <execution>
                    <id>package-functions</id>
                    <goals>
                        <goal>package</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${stagingDirectory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}</directory>
                                <includes>
                                    <include>host.json</include>
                                    <include>local.settings.json</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
                <execution>
                    <id>copy-bin</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${stagingDirectory}/bin</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/bin</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${stagingDirectory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <includeScope>runtime</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Expected behavior

Azure function which uses a class from any dependent jar (which in this case is azure-storage) fails to execute after starting it locally using mvn azure-functions:run

Actual behavior

While starting the azure function the dependent jars loaded in the lib folder (target/azure-functions/<function-name>/lib/) by mvn azure-functions:package should be added to the functions classpath. This doesn’t seem to be happening, and failing to find the dependency makes the function hang indefinitely at the place where a class from a dependent jar is referenced.

As per the closing comment on #86, this should have work, and was suggested not to generate a fat-jar using the maven-shade-plugin

Steps to reproduce the problem

  • Generate a azure function using the documented archtype mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DarchetypeVersion=1.8
  • Add a external dependency to the POM
  • Reference a class from the dependent JAR in the Function.java file generated by the archtype
  • Package and run the function using mvn azure-functions:package & mvn azure-functions:run
  • Call the function using HTTP GET
  • The function fails to respond

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jsnikhilcommented, Apr 16, 2018

@jdneo yes it was azure-functions-core-tools. After the upgrade, it worked as expected.

0reactions
Flanker32commented, Feb 7, 2022

@lovababu Thanks for your report, I tried the same pom configuration in an demo project and it seems that all the dependencies has been copied to lib of staging folder correctly. Could you please help share the output of maven package? image

Read more comments on GitHub >

github_iconTop Results From Across the Web

azure-functions-maven-plugin final jar missing libraries in ...
I suspect function failing in azure due to external dependencies not added to classpath of jar. From the stackoverflow I found similar question ......
Read more >
Tomcat Lib Folder JARs and Classpath - java - Server Fault
Classes in the WEB-INF/classes and jars in the WEB-INF/lib folder (or WAR archive) are loaded by the web application class loader.
Read more >
Adding Classes to the JAR File's Classpath
We want to load classes in MyUtils.jar into the class path for use in MyJar.jar. These two JAR files are in the same...
Read more >
Implementing Azure Functions with Java - mimacom blog
The Maven Dependency plugin is used to provide the dependency jar files in the folder used by the Azure Function plugin. The only...
Read more >
Running a Spring Boot App with Maven vs an Executable Jar
In this tutorial, we'll explore the differences between starting a Spring Boot web application via the mvn spring-boot:run command and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found