Home > Blockchain >  local.settings.json ignored for Java Azure Functions
local.settings.json ignored for Java Azure Functions

Time:11-03

I have followed doc guidance on how to setup java azure functions project with InteliJ: https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-maven-intellij

Nevertheless when trying to use local.settings.json file to inject application settings when running Functions locally, values are not injected and the file is ignored by the runtime. Is there a way how to make use of local.settings.json as with C# functions? For time being I used workaround of adding values into run configuration.

I am using Java 8, Azure Functions Core tools 4.x

CodePudding user response:

Remove local.settings.json from .gitignore file and publish/deploy the function.

enter image description here

Result:

enter image description here

CodePudding user response:

if you created the skeleton using microsoft help:

mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=8"

in your pom.xml you should find a section that does copy the local setting into the target folder

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <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-extensions-lib</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>${stagingDirectory}/.azurefunctions</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.basedir}/src/main/resources/.azurefunctions</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Install the azure function core tools:

brew tap azure/functions
brew install azure-functions-core-tools@4
# if upgrading on a machine that has 2.x installed
brew link --overwrite azure-functions-core-tools@4

#Install extensions
func extensions install

Then you can either run with:

mvn clean package azure-functions:run -DenableDebug -Dverbose=true

and attach your intellij debugger Run->Debug->attach to process or attach to localhost:5005

this will honour the local.settings.json and let you debugging

As far as i know the Azure Function run from intellij needs the parameters specified in the app settings.

  • Related