title | description | ms.topic | ms.date |
---|---|---|---|
Create a Java function using Visual Studio Code - Azure Functions |
Learn how to create a Java function, then publish the local project to serverless hosting in Azure Functions using the Azure Functions extension in Visual Studio Code. |
quickstart |
11/03/2020 |
[!INCLUDE functions-language-selector-quickstart-vs-code]
In this article, you use Visual Studio Code to create a Java function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
Note
If Visual Studio Code isn't your preferred development tool, check out our similar tutorials for Java developers using Maven, Gradle and IntelliJ IDEA.
Before you get started, make sure you have the following requirements in place:
-
An Azure account with an active subscription. Create an account for free.
-
The Java Developer Kit, version 8 or 11.
-
Apache Maven, version 3.0 or above.
-
Visual Studio Code on one of the supported platforms.
-
The Azure Functions extension for Visual Studio Code.
In this section, you use Visual Studio Code to create a local Azure Functions project in Java. Later in this article, you'll publish your function code to Azure.
-
Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project... icon.
-
Choose a directory location for your project workspace and choose Select.
[!NOTE] These steps were designed to be completed outside of a workspace. In this case, do not select a project folder that is part of a workspace.
-
Provide the following information at the prompts:
-
Select a language for your function project: Choose
Java
. -
Select a version of Java: Choose
Java 8
orJava 11
, the Java version on which your functions run in Azure. Choose a Java version that you've verified locally. -
Provide a group ID: Choose
com.function
. -
Provide an artifact ID: Choose
myFunction
. -
Provide a version: Choose
1.0-SNAPSHOT
. -
Provide a package name: Choose
com.function
. -
Provide an app name: Choose
myFunction-12345
. -
Authorization level: Choose
Anonymous
, which enables anyone to call your function endpoint. To learn about authorization level, see Authorization keys. -
Select how you would like to open your project: Choose
Add to workspace
.
-
-
Using this information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. To learn more about files that are created, see Generated project files.
[!INCLUDE functions-run-function-test-local-vs-code]
After you've verified that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.
[!INCLUDE functions-sign-in-vs-code]
[!INCLUDE functions-publish-project-vscode]
[!INCLUDE functions-vs-code-run-remote]
[!INCLUDE functions-cleanup-resources-vs-code.md]
You have used Visual Studio Code to create a function app with a simple HTTP-triggered function. In the next article, you expand that function by adding an output binding. This binding writes the string from the HTTP request to a message in an Azure Queue Storage queue.
[!div class="nextstepaction"] Connect to an Azure Storage queue