7.3 KiB
IMPORTANT NOTE: We're starting to migrate contents of this repo to the devcontainers org, as part of the work on the open dev container specification.
We'll now be publishing the java
image from devcontainers/images/src/java.
For more details, you can review the announcement issue.
Java
Summary
Develop Java applications. Includes the JDK and Java extensions.
Metadata | Value |
---|---|
Contributors | The VS Code Java Team |
Categories | Core, Languages |
Definition type | Dockerfile |
Published images | mcr.microsoft.com/vscode/devcontainers/java |
Available image variants | 11 / 11-bullseye, 17 / 17-bullseye, 11-buster, 17-buster (full list) |
Published image architecture(s) | x86-64, arm64/aarch64 for bullseye variants |
Works in Codespaces | Yes |
Container host OS support | Linux, macOS, Windows |
Container OS | Debian |
Languages, platforms | Java |
See history for information on the contents of published images.
Using this definition
Note: A version of this definition for JDK 8 is also available!
While this definition should work unmodified, you can select the version of Java the container uses by updating the VARIANT
arg in the included devcontainer.json
(and rebuilding if you've already created the container).
// Or you can use 11-bullseye or 11-buster if you want to pin to an OS version
"args": { "VARIANT": "11" }
You can also directly reference pre-built versions of .devcontainer/base.Dockerfile
by using the image
property in .devcontainer/devcontainer.json
or updating the FROM
statement in your own Dockerfile
to one of the following. An example Dockerfile
is included in this repository.
mcr.microsoft.com/vscode/devcontainers/java
(latest)mcr.microsoft.com/vscode/devcontainers/java:11
(or11-bullseye
,11-buster
to pin to an OS version)mcr.microsoft.com/vscode/devcontainers/java:17
(or17-bullseye
,17-buster
to pin to an OS version)
You can decide how often you want updates by referencing a semantic version of each image. For example:
mcr.microsoft.com/vscode/devcontainers/java:0-11
(or0-11-bullseye
,0-11-buster
to pin to an OS version)mcr.microsoft.com/vscode/devcontainers/java:0.203-11
(or0.203-11-bullseye
,0.203-11-buster
to pin to an OS version)mcr.microsoft.com/vscode/devcontainers/java:0.203.0-11
(or0.203.0-11-bullseye
,0.203.0-11-buster
to pin to an OS version)
However, we only do security patching on the latest non-breaking, in support versions of images (e.g. 0-11
). You may want to run apt-get update && apt-get upgrade
in your Dockerfile if you lock to a more specific version to at least pick up OS security updates.
See history for information on the contents of each version and here for a complete list of available tags.
Alternatively, you can use the contents of base.Dockerfile
to fully customize your container's contents or to build it for a container host architecture not supported by the image.
Debug Configuration
Note that only the integrated terminal is supported by the Remote - Containers extension. You may need to modify launch.json
configurations to include the following value if an external console is used.
"console": "integratedTerminal"
Installing Maven or Gradle
You can opt to install a version of Maven or Gradle by adding "INSTALL_MAVEN: "true"
or "INSTALL_GRADLE: "true"
to build args in .devcontainer/devcontainer.json
. Both of these are set by default. For example:
"args": {
"VARIANT": "11",
"INSTALL_GRADLE": "true",
"INSTALL_MAVEN": "true"
}
Remove the appropriate arg or set its value to "false"
to skip installing the specified tool.
You can also specify the version of Gradle or Maven if needed.
"args": {
"VARIANT": "11",
"INSTALL_GRADLE": "true",
"MAVEN_VERSION": "3.8.3",
"INSTALL_MAVEN": "true",
"GRADLE_VERSION": "7.2"
}
Installing Node.js
Given JavaScript front-end web client code written for use in conjunction with a Java back-end often requires the use of Node.js-based utilities to build, this container also includes nvm
so that you can easily install Node.js. You can enable installation and change the version of Node.js installed or disable its installation by updating the args
property in .devcontainer/devcontainer.json
.
"args": {
"VARIANT": "11",
"NODE_VERSION": "10" // Set to "none" to skip Node.js installation
}
Adding the definition to your folder
-
If this is your first time using a development container, please see getting started information on setting up Remote-Containers or creating a codespace using GitHub Codespaces.
-
To use the pre-built image:
- Start VS Code and open your project folder or connect to a codespace.
- Press F1 select and Add Development Container Configuration Files... command for Remote-Containers or Codespaces.
- Select this definition. You may also need to select Show All Definitions... for it to appear.
-
To build a custom version of the image instead:
- Clone this repository locally.
- Start VS Code and open your project folder or connect to a codespace.
- Use your local operating system's file explorer to drag-and-drop the locally cloned copy of the
.devcontainer
folder for this definition into the VS Code file explorer for your opened project or codespace. - Update
.devcontainer/devcontainer.json
to reference"dockerfile": "base.Dockerfile"
.
-
After following step 2 or 3, the contents of the
.devcontainer
folder in your project can be adapted to meet your needs. -
Finally, press F1 and run Remote-Containers: Reopen Folder in Container or Codespaces: Rebuild Container to start using the definition.
Testing the definition
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
- If this is your first time using a development container, please follow the getting started steps to set up your machine.
- Clone this repository.
- Start VS Code, press F1, and select Remote-Containers: Open Folder in Container...
- Select the
containers/java
folder. - After the folder has opened in the container, press F5 to start the project.
- You should see "Hello Remote World!" in the a Debug Console after the program executes.
- From here, you can add breakpoints or edit the contents of the
test-project
folder to do further testing.
License
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See LICENSE.