title | description | services | documentationcenter | author | manager | keywords | ms.service | ms.devlang | ms.topic | ms.date | ms.author | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Create an Azure function with Java and IntelliJ | Microsoft Docs |
Learn how to create and publish a simple HTTP-triggered, serverless app on Azure with Java and IntelliJ. |
functions |
na |
jeffhollan |
jpconnock |
azure functions, functions, event processing, compute, serverless architecture, java |
azure-functions |
java |
conceptual |
07/01/2018 |
jehollan |
mvc, devcenter |
Note
Java for Azure Functions is currently in preview.
This article shows you:
- How to create a serverless function project with IntelliJ IDEA and Apache Maven
- Steps for testing and debugging the function in the integrated development environment (IDE) on your own computer
- Instructions for deploying the function project to Azure Functions
[!INCLUDE quickstarts-free-trial-note]
To develop a function with Java and IntelliJ, install the following software:
- Java Developer Kit (JDK), version 8
- Apache Maven, version 3.0 or higher
- IntelliJ IDEA, Community or Ultimate versions with Maven
- Azure CLI
Important
The JAVA_HOME environment variable must be set to the install location of the JDK to complete the steps in this article.
We recommend that you install Azure Functions Core Tools, version 2. It provides a local development environment for writing, running, and debugging Azure Functions.
- In IntelliJ IDEA, select Create New Project.
- In the New Project window, select Maven from the left pane.
- Select the Create from archetype check box, and then select Add Archetype for the azure-functions-archetype.
- In the Add Archetype window, complete the fields as follows:
- GroupId: com.microsoft.azure
- ArtifactId: azure-functions-archetype
- Version: Use the latest version from the central repository
- Select OK, and then select Next.
- Enter your details for current project, and select Finish.
Maven creates the project files in a new folder with the same name as the ArtifactId value. The project's generated code is a simple HTTP-triggered function that echoes the body of the triggering HTTP request.
Note
To run and debug functions locally, make sure you've installed Azure Functions Core Tools, version 2.
-
Import changes manually or enable auto import.
-
Open the Maven Projects toolbar.
-
Expand Lifecycle, and then open package. The solution is built and packaged in a newly created target directory.
-
Expand Plugins > azure-functions and open azure-functions:run to start the Azure Functions local runtime.
-
Close the run dialog box when you're done testing your function. Only one function host can be active and running locally at a time.
-
To start the function host in debug mode, add -DenableDebug as the argument when you run your function. You can either change the configuration in maven goals or run the following command in a terminal window:
mvn azure-functions:run -DenableDebug
This command causes the function host to open a debug port at 5005.
-
On the Run menu, select Edit Configurations.
-
Select (+) to add a Remote.
-
Complete the Name and Settings fields, and then select OK to save the configuration.
-
After setup, select Debug < Remote Configuration Name > or press Shift+F9 on your keyboard to start debugging.
-
When you're finished, stop the debugger and the running process. Only one function host can be active and running locally at a time.
-
Before you can deploy your function to Azure, you must log in by using the Azure CLI.
az login
-
Deploy your code into a new function by using the
azure-functions:deploy
Maven target. You can also select the azure-functions:deploy option in the Maven Projects window.mvn azure-functions:deploy
-
Find the URL for your function in the Azure CLI output after the function has been successfully deployed.
[INFO] Successfully deployed Function App with package. [INFO] Deleting deployment package from Azure Storage... [INFO] Successfully deleted deployment package fabrikam-function-20170920120101928.20170920143621915.zip [INFO] Successfully deployed Function App at https://fabrikam-function-20170920120101928.azurewebsites.net [INFO] ------------------------------------------------------------------------
- Review the Java Functions developer guide for more information on developing Java functions.
- Add additional functions with different triggers to your project by using the
azure-functions:add
Maven target.