Create your first Java function in Azure using IntelliJ
This article shows you how to use Java and IntelliJ to create an Azure function.
Specifically, this article shows you:
- How to create an HTTP-triggered Java function in an IntelliJ IDEA project.
- Steps for testing and debugging the project in the integrated development environment (IDE) on your own computer.
- Instructions for deploying the function project to Azure Functions.
- An Azure account with an active subscription. Create an account for free.
- An Azure supported Java Development Kit (JDK) for Java, version 8 or 11
- An IntelliJ IDEA Ultimate Edition or Community Edition installed
- Maven 3.5.0+
- Latest Function Core Tools
Install plugin and sign in
To install the Azure Toolkit for IntelliJ and then sign in, follow these steps:
In IntelliJ IDEA's Settings/Preferences dialog (Ctrl+Alt+S), select Plugins. Then, find the Azure Toolkit for IntelliJ in the Marketplace and click Install. After it's installed, click Restart to activate the plugin.
To sign in to your Azure account, open the Azure Explorer sidebar, and then click the Azure Sign In icon in the bar on top (or from the IDEA menu, select Tools > Azure > Azure Sign in).
In the Azure Sign In window, select OAuth 2.0, and then click Sign in. For other sign-in options, see Sign-in instructions for the Azure Toolkit for IntelliJ.
In the browser, sign in with your account and then go back to IntelliJ. In the Select Subscriptions dialog box, click on the subscriptions that you want to use, then click Select.
Create your local project
To use Azure Toolkit for IntelliJ to create a local Azure Functions project, follow these steps:
Open IntelliJ IDEA's Welcome dialog, select New Project to open a new project wizard, then select Azure Functions.
Select Http Trigger, then click Next and follow the wizard to go through all the configurations in the following pages. Confirm your project location, then click Finish. Intellj IDEA will then open your new project.
Run the project locally
To run the project locally, follow these steps:
You must have the JAVA_HOME environment variable set correctly to the JDK directory that is used during code compiling using Maven. Make sure that the version of the JDK is at least as high as the
Navigate to src/main/java/org/example/functions/HttpTriggerFunction.java to see the code generated. Beside the line 24, you'll notice that there's a green Run button. Click it and select Run 'Functions-azur...'. You'll see that your function app is running locally with a few logs.
You can try the function by accessing the displayed endpoint from browser, such as
The log is also displayed in your IDEA. Stop the function app by clicking the Stop button.
Debug the project locally
To debug the project locally, follow these steps:
Select the Debug button in the toolbar. If you don't see the toolbar, enable it by choosing View > Appearance > Toolbar.
Click on line 31 of the file src/main/java/org/example/functions/HttpTriggerFunction.java to add a breakpoint. Access the endpoint
http://localhost:7071/api/HttpTrigger-Java?name=Azureagain and you'll find the breakpoint is hit. You can then try more debug features like Step, Watch, and Evaluation. Stop the debug session by clicking the Stop button.
Deploy your project to Azure
To deploy your project to Azure, follow these steps:
Right click your project in IntelliJ Project explorer, then select Azure -> Deploy to Azure Functions.
If you don't have any Function App yet, click + in the Function line. Type in the function app name and choose proper platform. Here you can accept the default value. Click OK and the new function app you created will be automatically selected. Click Run to deploy your functions.
Manage function apps from IDEA
To manage your function apps with Azure Explorer in your IDEA, follow these steps:
Click on Function App and you'll see all your function apps listed.
Click to select on one of your function apps, then right click and select Show Properties to open the detail page.
Right click on your HttpTrigger-Java function app, then select Trigger Function in Browser. You'll see that the browser is opened with the trigger URL.
Add more functions to the project
To add more functions to your project, follow these steps:
Right click on the package org.example.functions and select New -> Azure Function Class.
Fill in the class name HttpTest and select HttpTrigger in the create function class wizard, then click OK to create. In this way, you can create new functions as you want.
Cleaning up functions
Select one of your function apps using Azure Explorer in your IDEA, then right-click and select Delete. This command might take several minutes to run. When it's done, the status will refresh in Azure Explorer.
You've created a Java project with an HTTP triggered function, run it on your local machine, and deployed it to Azure. Now, extend your function by continuing to the following article:
Submit and view feedback for