|
| 1 | +--- |
| 2 | +title: Build environment variables for Java in Azure Container Apps |
| 3 | +description: Learn about Java image build from source code via environment variables. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 02/27/2024 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Build environment variables for Java in Azure Container Apps |
| 13 | + |
| 14 | +Azure Container Apps uses [Buildpacks](https://buildpacks.io/) to automatically create a container image that allows you to deploy from your source code directly to the cloud. To take control of your build configuration, you can use environment variables to customize parts of your build like the JDK, Maven, and Tomcat. The following article shows you how to configure environment variables to help you take control over builds that automatically create a container for you. |
| 15 | + |
| 16 | +## Supported Java build environment variables |
| 17 | + |
| 18 | +### Configure JDK |
| 19 | + |
| 20 | +Container Apps use [Microsoft Build of OpenJDK](https://www.microsoft.com/openjdk) to build source code and as the runtime environment. Four LTS JDK versions are supported: 8, 11, 17 and 21. |
| 21 | + |
| 22 | +- For source code build, the default version is JDK 17. |
| 23 | + |
| 24 | +- For a JAR file build, the JDK version is read from the file location `META-INF\MANIFEST.MF` in the JAR, but uses the default JDK version 17 if the specified version isn't available. |
| 25 | + |
| 26 | +Here's a listing of the environment variables used to configure JDK: |
| 27 | + |
| 28 | +| Environment variable | Description | Default | |
| 29 | +|--|--|--| |
| 30 | +| `BP_JVM_VERSION` | Controls the JVM version. | `17` | |
| 31 | + |
| 32 | +### Configure Maven |
| 33 | + |
| 34 | +Container Apps supports building Maven-based applications from source. |
| 35 | + |
| 36 | +Here's a listing of the environment variables used to configure Maven: |
| 37 | + |
| 38 | +| Build environment variable | Description | Default | |
| 39 | +|--|--|--| |
| 40 | +| `BP_MAVEN_VERSION` | Sets the major Maven version. Since Buildpacks only ships a single version of each supported line, updates to the buildpack can change the exact version of Maven installed. If you require a specific minor/patch version of Maven, use the Maven wrapper instead. | `3` | |
| 41 | +| `BP_MAVEN_BUILD_ARGUMENTS` | Defines the arguments passed to Maven. The `--batch-mode` is prepended to the argument list in environments without a TTY. | `-Dmaven.test.skip=true --no-transfer-progress package` | |
| 42 | +| `BP_MAVEN_ADDITIONAL_BUILD_ARGUMENTS` | Defines extra arguments used (for example, `-DskipJavadoc` appended to `BP_MAVEN_BUILD_ARGUMENTS`) to pass to Maven. | | |
| 43 | +| `BP_MAVEN_ACTIVE_PROFILES` | Comma separated list of active profiles passed to Maven. | | |
| 44 | +| `BP_MAVEN_BUILT_MODULE` | Designates application artifact that contains the module. By default, the build looks in the root module. | | |
| 45 | +| `BP_MAVEN_BUILT_ARTIFACT` | Location of the built application artifact. This value supersedes the `BP_MAVEN_BUILT_MODULE` variable. You can match a single file, multiple files, or a directory through one or more space separated patterns. | `target/*.[ejw]ar` | |
| 46 | +| `BP_MAVEN_POM_FILE` | Specifies a custom location to the project's *pom.xml* file. This value is relative to the root of the project (for example, */workspace*). | `pom.xml` | |
| 47 | +| `BP_MAVEN_DAEMON_ENABLED` | Triggers the installation and configuration of Apache `maven-mvnd` instead of Maven. Set this value to `true` if you want to the Maven Daemon. | `false` | |
| 48 | +| `BP_MAVEN_SETTINGS_PATH` | Specifies a custom location to Maven's *settings.xml* file. | | |
| 49 | +| `BP_INCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file is retained in the final image. | | |
| 50 | +| `BP_EXCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file is removed from the final image. Any include patterns are applied first, and you can use "exclude patterns" to reduce the files included in the build. | | |
| 51 | +| `BP_JAVA_INSTALL_NODE` | Control whether or not a separate Buildpack installs Yarn and Node.js. If set to `true`, the Buildpack checks the app root or path set by `BP_NODE_PROJECT_PATH`. The project path looks for either a *yarn.lock* file, which requires the installation of Yarn and Node.js. If there's a *package.json* file, then the build only requires Node.js. | `false` | |
| 52 | +| `BP_NODE_PROJECT_PATH` | Direct the project subdirectory to look for *package.json* and *yarn.lock* files. | | |
| 53 | + |
| 54 | +### Configure Tomcat |
| 55 | + |
| 56 | +Container Apps supports running war file in Tomcat application server. |
| 57 | + |
| 58 | +Here's a listing of the environment variables used to configure Tomcat: |
| 59 | + |
| 60 | +| Build environment variable | Description | Default | |
| 61 | +|--|--|--| |
| 62 | +| `BP_TOMCAT_CONTEXT_PATH` | The context path where the application is mounted. | Defaults to empty (`ROOT`) | |
| 63 | +| `BP_TOMCAT_EXT_CONF_SHA256` | The SHA256 hash of the external configuration package. | | |
| 64 | +| `BP_TOMCAT_ENV_PROPERTY_SOURCE_DISABLED` | When set to `true`, the Buildpack doesn't configure `org.apache.tomcat.util.digester.EnvironmentPropertySource`. This configuration option is added to support loading configuration from environment variables and referencing them in Tomcat configuration files. | | |
| 65 | +| `BP_TOMCAT_EXT_CONF_STRIP` | The number of directory levels to strip from the external configuration package. | `0` | |
| 66 | +| `BP_TOMCAT_EXT_CONF_URI` | The download URI of the external configuration package. | | |
| 67 | +| `BP_TOMCAT_EXT_CONF_VERSION` | The version of the external configuration package. | | |
| 68 | +| `BP_TOMCAT_VERSION` | Used to configure a specific Tomcat version. Supported Tomcat versions include 8, 9, and 10. | `9.*` | |
| 69 | + |
| 70 | +### Configure Cloud Build Service |
| 71 | + |
| 72 | +Here's a listing of the environment variables used to configure a Cloud Build Service: |
| 73 | + |
| 74 | +| Build environment variable | Description | Default | |
| 75 | +|--|--|--| |
| 76 | +| `ORYX_DISABLE_TELEMETRY` | Controls whether or not to disable telemetry collection. | `false` | |
| 77 | + |
| 78 | +## How to configure Java build environment variables |
| 79 | + |
| 80 | +You can configure Java build environment variables when you deploy Java application source code via CLI command `az containerapp up`, `az containerapp create`, or `az containerapp update`: |
| 81 | + |
| 82 | +```azurecli |
| 83 | +az containerapp up \ |
| 84 | + --name <CONTAINER_APP_NAME> \ |
| 85 | + --source <SOURCE_DIRECTORY> \ |
| 86 | + --build-env-vars <NAME=VALUE NAME=VALUE> \ |
| 87 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 88 | + --environment <ENVIRONMENT_NAME> |
| 89 | +``` |
| 90 | + |
| 91 | +The `build-env-vars` argument is a list of environment variables for the build, space-separated values in `key=value` format. Here's an example list you can pass in as variables: |
| 92 | + |
| 93 | +```bash |
| 94 | +BP_JVM_VERSION=21 BP_MAVEN_VERSION=4 "BP_MAVEN_BUILD_ARGUMENTS=-Dmaven.test.skip=true --no-transfer-progress package" |
| 95 | +``` |
| 96 | + |
| 97 | +You can also configure the Java build environment variables when you [set up GitHub Actions with Azure CLI in Azure Container Apps](github-actions-cli.md). |
| 98 | + |
| 99 | +```azurecli |
| 100 | +az containerapp github-action add \ |
| 101 | + --repo-url "https://github.com/<OWNER>/<REPOSITORY_NAME>" \ |
| 102 | + --build-env-vars <NAME=VALUE NAME=VALUE> \ |
| 103 | + --branch <BRANCH_NAME> \ |
| 104 | + --name <CONTAINER_APP_NAME> \ |
| 105 | + --resource-group <RESOURCE_GROUP> \ |
| 106 | + --registry-url <URL_TO_CONTAINER_REGISTRY> \ |
| 107 | + --registry-username <REGISTRY_USER_NAME> \ |
| 108 | + --registry-password <REGISTRY_PASSWORD> \ |
| 109 | + --service-principal-client-id <appId> \ |
| 110 | + --service-principal-client-secret <password> \ |
| 111 | + --service-principal-tenant-id <tenant> \ |
| 112 | + --token <YOUR_GITHUB_PERSONAL_ACCESS_TOKEN> |
| 113 | +``` |
| 114 | + |
| 115 | +## Next steps |
| 116 | + |
| 117 | +> [!div class="nextstepaction"] |
| 118 | +> [Build and deploy from a repository](quickstart-code-to-cloud.md) |
0 commit comments