title | description | author | ms.topic | ms.date | ms.author | ms.devlang | ms.custom |
---|---|---|---|---|---|---|---|
Create a Java function in Azure Functions using IntelliJ |
Learn how to use IntelliJ to create a simple HTTP-triggered Java function, which you then publish to run in a serverless environment in Azure. |
yucwan |
how-to |
07/01/2018 |
yucwan |
java |
mvc, devcenter, devx-track-java |
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
[!INCLUDE quickstarts-free-trial-note]
To create and publish Java functions to Azure using IntelliJ, install the following software:
- An Azure account with an active subscription. Create an account for free.
- An Azure supported Java Development Kit (JDK) for Java 8
- An IntelliJ IDEA Ultimate Edition or Community Edition installed
- Maven 3.5.0+
- Latest Function Core Tools
-
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 installed, click Restart to activate the plugin.
-
To sign in to your Azure account, open sidebar Azure Explorer, and then click the Azure Sign In icon in the bar on top (or from IDEA menu Tools/Azure/Azure Sign in).
-
In the Azure Sign In window, select Device Login, and then click Sign in (other sign in options).
-
Click Copy&Open in Azure Device Login dialog .
-
In the browser, paste your device code (which has been copied when you click Copy&Open in last step) and then click Next.
-
In the Select Subscriptions dialog box, select the subscriptions that you want to use, and then click Select.
In this section, you use Azure Toolkit for IntelliJ to create a local Azure Functions project. Later in this article, you'll publish your function code to Azure.
-
Open IntelliJ Welcome dialog, select Create New Project to open a new Project wizard, 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.
-
Navigate to
src/main/java/org/example/functions/HttpTriggerFunction.java
to see the code generated. Beside the line 17, you will notice that there is a green Run button, click it and select Run 'azure-function-exam...', you will see that your function app is running locally with a few logs. -
You can try the function by accessing the printed endpoint from browser, like
http://localhost:7071/api/HttpTrigger-Java?name=Azure
. -
The log is also printed out in your IDEA, now, stop the function app by clicking the stop button.
-
To debug the function code in your project locally, select the Debug button in the toolbar. If you don't see the toolbar, enable it by choosing View > Appearance > Toolbar.
-
Click on line 20 of the file
src/main/java/org/example/functions/HttpTriggerFunction.java
to add a breakpoint, access the endpointhttp://localhost:7071/api/HttpTrigger-Java?name=Azure
again , you will find the breakpoint is hit, you can try more debug features like step, watch, evaluation. Stop the debug session by click the stop button.
-
Right click your project in IntelliJ Project explorer, 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 we can simply accept default. Click OK and the new function app you just created will be automatically selected. Click Run to deploy your functions.
-
You can manage your function apps with Azure Explorer in your IDEA, click on Function App, you will see all your function apps here.
-
Click to select on one of your function apps, and right click, select Show Properties to open the detail page.
-
Right click on your HttpTrigger-Java function app, and select Trigger Function, you will see that the browser is opened with the trigger URL.
-
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, click OK to create, in this way, you can create new functions as you want.
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...
[!div class="nextstepaction"] Adding an Azure Storage queue output binding