|
| 1 | +--- |
| 2 | +title: Update Java versions in Azure Functions |
| 3 | +description: Learn how to update an existing function app in Azure Functions to run on a new version of Java. |
| 4 | +ms.topic: how-to |
| 5 | +ms.date: 09/14/2023 |
| 6 | +zone_pivot_groups: app-service-platform-windows-linux |
| 7 | +--- |
| 8 | + |
| 9 | +# Update Java versions in Azure Functions |
| 10 | + |
| 11 | +The Azure Functions supports specific versions of Java. This support changes based on the support or Java versions. As these supported versions change, you need to update your Java function apps. You may also want to update your apps to take advantage of features in newer supported version of Java. For more information, see [Supported versions](functions-reference-java.md#supported-versions) in the Java developer guide. |
| 12 | + |
| 13 | +:::zone pivot="platform-windows" |
| 14 | +The way that you update your function app depends on whether you run on Windows or Linux. This version is for Windows. Choose your OS at the [top](#top) of the article. |
| 15 | +:::zone-end |
| 16 | +:::zone pivot="platform-linux" |
| 17 | +The way that you update your function app depends on whether you run on Windows or Linux. This version is for Linux. Choose your OS at the [top](#top) of the article. |
| 18 | +:::zone-end |
| 19 | + |
| 20 | +## Prepare to update |
| 21 | + |
| 22 | +Before you update the Java version in Azure, you should complete these tasks: |
| 23 | + |
| 24 | +### 1. Verify your functions locally |
| 25 | + |
| 26 | +Before upgrading the Java version used by your function app in Azure, make sure that you have fully tested and verified your function code locally on the new target version of Java. Examples in this article assume you're updating to Java 17. |
| 27 | + |
| 28 | +### 2. Move to the latest Functions runtime |
| 29 | + |
| 30 | +Before updating your Java version, make sure your function app is running on the latest version of the Functions runtime (version 4.x). |
| 31 | + |
| 32 | +### [Azure portal](#tab/azure-portal) |
| 33 | + |
| 34 | +Use these steps to determine your Functions runtime version: |
| 35 | + |
| 36 | +1. In the [Azure portal](https://portal.azure.com), locate your function app and select **Configuration** on the left-hand side under **Settings**. |
| 37 | + |
| 38 | +1. Select the **Function runtime settings** tab and check the **Runtime version** value to see if your function app is running on version 4.x of the Functions runtime (`~4`). |
| 39 | + |
| 40 | + :::image type="content" source="media/update-java-versions/update-functions-version-portal.png" alt-text="Screenshot of how to view the Functions runtime version for your app in the Azure portal."::: |
| 41 | + |
| 42 | +### [Azure CLI](#tab/azure-cli) |
| 43 | + |
| 44 | +Use this [`az functionapp config appsettings list`](/cli/azure/functionapp/config/appsettings#az-functionapp-config-appsettings-list) command to check your runtime version: |
| 45 | + |
| 46 | +```azurecli |
| 47 | +az functionapp config appsettings list --name "<FUNCTION_APP_NAME>" --resource-group "<RESOURCE_GROUP_NAME>" |
| 48 | +``` |
| 49 | +The `FUNCTIONS_EXTENSION_VERSION` setting sets the runtime version. A value of `~4` means that your function app is already running on the latest minor version of the latest major version (4.x). |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +If you need to first update your function app to version 4.x, see [Migrate apps from Azure Functions version 3.x to version 4.x](./migrate-version-3-version-4.md). You should follow the instructions in this article rather than just manually changing the `FUNCTIONS_EXTENSION_VERSION` setting. |
| 54 | + |
| 55 | +## Update the Java version |
| 56 | +:::zone pivot="platform-windows" |
| 57 | +You can use the Azure portal, Azure CLI, or Azure PowerShell to update the Java version for your function app. |
| 58 | +These procedures apply to all [Functions hosting options](./functions-scale.md). |
| 59 | +:::zone-end |
| 60 | +:::zone pivot="platform-linux" |
| 61 | +>[!NOTE] |
| 62 | +> You can't change the Java version in the Azure portal when your function app is running on Linux in a [Consumption plan](./consumption-plan.md). Instead use the Azure CLI. |
| 63 | +:::zone-end |
| 64 | +### [Azure portal](#tab/azure-portal) |
| 65 | +:::zone pivot="platform-linux" |
| 66 | +You can only use these steps for function apps hosted in a [Premium plan](./functions-premium-plan.md) or a [Dedicated (App Service) plan](./dedicated-plan.md). For a [Consumption plan](./consumption-plan.md), you must instead use the Azure CLI. |
| 67 | +::: zone-end |
| 68 | +Use the following steps to update the Java version: |
| 69 | + |
| 70 | +1. In the [Azure portal](https://portal.azure.com), locate your function app and select **Configuration** on the left-hand side. |
| 71 | + |
| 72 | +1. In the **General settings** tab, update the **Java version** to `Java 17`. |
| 73 | + |
| 74 | + :::image type="content" source="media/update-java-versions/update-java-version-portal.png" alt-text="Screenshot of how to set the desired Java version for a function app in the Azure portal."::: |
| 75 | + |
| 76 | +1. When notified about a restart, select **Continue**, and then **Save**. |
| 77 | + |
| 78 | +### [Azure CLI](#tab/azure-cli) |
| 79 | + |
| 80 | +You can use the Azure CLI to update the Java version for any hosting plan. |
| 81 | + |
| 82 | +:::zone pivot="platform-windows" |
| 83 | +Run the [`az functionapp config set`](/cli/azure/functionapp/config#az-functionapp-config-set) command to update the Java version site setting to `17`: |
| 84 | + |
| 85 | +```azurecli |
| 86 | +az functionapp config set --java-version "17" --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" |
| 87 | +``` |
| 88 | +:::zone-end |
| 89 | +:::zone pivot="platform-linux" |
| 90 | +Run the [`az functionapp config set`](/cli/azure/functionapp/config#az-functionapp-config-set) command to update the Linux site setting with the new Java version for your function app. |
| 91 | + |
| 92 | +```azurecli |
| 93 | +az functionapp config set --linux-fx-version "java|17" --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" |
| 94 | +``` |
| 95 | +:::zone-end |
| 96 | + |
| 97 | +In this example, replace `<APP_NAME>` and `<RESOURCE_GROUP>` with the name of your function app and resource group, respectively. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +Your function app restarts after you update the Java version. To learn more about Functions support for Java, see [Language runtime support policy](language-support-policy.md). |
| 102 | + |
| 103 | +## Next steps |
| 104 | + |
| 105 | +> [!div class="nextstepaction"] |
| 106 | +> [Java developer guide](./functions-reference-java.md) |
| 107 | + |
0 commit comments