Create your first function with Java and Maven (Preview)


Java for Azure Functions is currently in preview.

This quickstart guides through creating a serverless function project with Maven, testing it locally, and deploying it to Azure Functions. When you're done, you have a HTTP-triggered function app running in Azure.

Access a Hello World function from the command line with cURL

If you don't have an Azure subscription, create a free account before you begin.


To develop functions app with Java, you must have the following installed:


The JAVA_HOME environment variable must be set to the install location of the JDK to complete this quickstart.

Install the Azure Functions Core Tools

The Azure Functions Core Tools 2.0 provide a local development environment for writing, running, and debugging Azure Functions. Install the tools with npm, included with Node.js.

npm install -g azure-functions-core-tools@core


If you have trouble installing Azure Functions Core Tools version 2.0, see Version 2.x runtime.

Generate a new Functions project

In an empty folder, run the following command to generate the Functions project from a Maven archetype.


mvn archetype:generate \ \

Windows (CMD)

mvn archetype:generate ^ ^

Maven prompts you for values needed to finish generating the project. For groupId, artifactId, and version values, see the Maven naming conventions reference. The appName value must be unique across Azure, so Maven generates an app name based on the previously entered artifactId as a default. The packageName value determines the Java package for the generated function code.

Define value for property 'groupId': com.fabrikam.functions
Define value for property 'artifactId' : fabrikam-functions
Define value for property 'version' 1.0-SNAPSHOT : 
Define value for property 'package': com.fabrikam.functions
Define value for property 'appName' fabrikam-functions-20170927220323382:
Confirm properties configuration: Y

Maven creates the project files in a new folder with a name of artifactId. The generated code in the project is a simple HTTP triggered function that echoes the body of the request:

public class Function {
     * This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP Body" {your host}/api/hello
     * 2. curl {your host}/api/hello?name=HTTP%20Query
    public HttpResponseMessage<String> hello(
            @HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");

        // Parse query parameter
        String query = request.getQueryParameters().get("name");
        String name = request.getBody().orElse(query);

        if (name == null) {
            return request.createResponse(400, "Please pass a name on the query string or in the request body");
        } else {
            return request.createResponse(200, "Hello, " + name);

Run the function locally

Change directory to the newly created project folder and build and run the function with Maven:

cd fabrikam-function
mvn clean package 
mvn azure-functions:run


If you're experiencing this exception: javax.xml.bind.JAXBException with Java 9, see the workaround on GitHub.

You see this output when the function is running:

Listening on http://localhost:7071
Hit CTRL-C to exit...

Http Functions:

   hello: http://localhost:7071/api/hello

Trigger the function from the command line using curl in a new terminal:

curl -w '\n' -d LocalFunction http://localhost:7071/api/hello
Hello LocalFunction!

Use Ctrl-C in the terminal to stop the function code.

Deploy the function to Azure

The deploy process to Azure Functions uses account credentials from the Azure CLI. Log in with the Azure CLI and then deploy your code into a new Function app using the azure-functions:deploy Maven target.

az login
mvn azure-functions:deploy

When the deploy is complete, you see the URL you can use to access your Azure function app:

[INFO] Successfully deployed Function App with package.
[INFO] Deleting deployment package from Azure Storage...
[INFO] Successfully deleted deployment package
[INFO] Successfully deployed Function App at
[INFO] ------------------------------------------------------------------------

Test the function app running on Azure using curl:

curl -w '\n' -d AzureFunctions
Hello AzureFunctions!

Next steps

You have created a Java function app with a simple HTTP trigger and deployed it to Azure Functions.

  • Review the Java Functions developer guide for more information on developing Java functions.
  • Add additional functions with different triggers to your project using the azure-functions:add Maven target.
  • Debug functions locally with Visual Studio Code. With the Java extension pack installed and with your Functions project open in Visual Studio Code, attach the debugger to port 5005. Then set a breakpoint in the editor and trigger your function while it's running locally: Debug functions in Visual Studio Code