Introduction
This guide shows you how to set up an example Java project Codespaces에서 Visual Studio Code 데스크톱 애플리케이션 또는 VS Code 웹 클라이언트를 사용합니다. codespace에서 프로젝트를 열고 미리 정의된 개발 컨테이너 구성을 추가 및 수정하는 예제를 안내합니다.
Step 1: Open the project in a codespace
-
Click Use this template, then click Open in a codespace.

When you create a codespace, your project is created on a remote virtual machine that is dedicated to you. By default, the container for your codespace has many languages and runtimes, including Java. It also includes a set of commonly used tools such as Gradle, Maven, git, wget, rsync, openssh, and nano.
vCPU 및 RAM의 양을 조정하거나 환경을 개인 설정하기 위해 dot 파일을 추가하거나 설치된 도구와 스크립트를 수정하여 codespace를 사용자 지정할 수 있습니다.
Codespaces는 codespace에서 작업할 때 사용하는 개발 컨테이너를 구성하기 위해 devcontainer.json이라는 파일을 사용합니다. 각 리포지토리에는 codespace에서 코드 작업을 하는 데 필요한 개발 환경을 정확하게 제공하기 위해 하나 이상의 devcontainer.json 파일이 포함될 수 있습니다.
시작 시 Codespaces는 개발 컨테이너 구성을 구성하는 devcontainer.json 파일 및 종속 파일을 사용하여 도구 및 런타임을 설치하고 프로젝트에 필요한 기타 설치 작업을 수행합니다. 자세한 내용은 “개발 컨테이너 소개”를 참조하세요.
Step 2: Add a dev container configuration
The default development container, or "dev container," for GitHub Codespaces will allow you to work successfully on a Java project like vscode-remote-try-java. However, we recommend that you configure your own dev container to include all of the tools and scripts your project needs. This will ensure a fully reproducible environment for all GitHub Codespaces users in your repository.
사용자 지정 개발 컨테이너를 사용하도록 리포지토리를 설정하려면 하나 이상의 devcontainer.json 파일을 만들어야 합니다. 미리 정의된 구성 템플릿의 Visual Studio Code에서 추가하거나 직접 작성할 수 있습니다. 개발 컨테이너 구성에 대한 자세한 내용은 "개발 컨테이너 소개"를 참조하세요.
-
Visual Studio Code Command Palette에 액세스하고(Shift+Command+P(Mac)/Ctrl+Shift+P(Windows/Linux)) "dev container"라고 입력합니다. Codespaces: Add Development Container Configuration Files... (codespace: 개발 컨테이너 구성 파일 추가...)를 선택합니다.

-
Type
javaand click the Java option. Other options are available if your project uses particular tools. For example, Java & PostgreSQL.
-
Click the latest version of Java.

-
Select the option to Install Maven and click OK.

-
A list of additional features you can install is displayed. We'll install Ant, the Java library and command-line tool for building applications. To install this feature, type
ant, selectAnt (via SDKMAN), then click OK.
-
A message is displayed telling you that the dev container configuration file already exists. Click Overwrite.
A
devcontainer.jsonfile is created and is opened in the editor.
Details of your custom dev container configuration
If you look in the Visual Studio Code Explorer you'll see that a .devcontainer directory has been added to the root of your project's repository containing the devcontainer.json file. This is the main configuration file for codespaces created from this repository.
devcontainer.json
The devcontainer.json file that you have added will contain values for the name, image, and features properties. Some additional properties that you may find useful are included but are commented out.
The file will look similar to this, depending on which image you chose:
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/java
{
"name": "Java",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/java:0-17",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installMaven": "true",
"installGradle": "false"
},
"ghcr.io/devcontainers-contrib/features/ant-sdkman:2": {}
}
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "java -version",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
- name: You can name your dev container anything you want. A default value is supplied.
- image: The name of an image in a container registry (DockerHub, GitHub Container registry, or Azure Container Registry) that will be used to create the dev container for the codespace.
- features: A list of one or more objects, each of which references one of the available dev container features. Features are self-contained, shareable units of installation code and development container configuration. They provide an easy way to add more tooling, runtime, or library features to your development container. For more information, see "Available Dev Container Features" on the Development Containers website. You can add features by going to the VS Code Command Palette and typing
features. - forwardPorts: Any ports listed here will be forwarded automatically. For more information, see "Forwarding ports in your codespace."
- postCreateCommand: Use this property to run commands after your codespace is created.
- customizations: This property allows you to customize a specific tool or service when it is used for working in a codespace. For example, you can configure specific settings and extensions for VS Code. For more information, see "Supporting tools and services" on the Development Containers website.
- remoteUser: By default, you’re running as the vscode user, but you can optionally set this to root.
For a complete list of available properties, see the dev containers specification on the Development Containers website.
Additional dev container configuration files
If you are familiar with Docker, you may want to use a Dockerfile, or Docker Compose, to configure your codespace environment, in addition to the devcontainer.json file. You can do this by adding your Dockerfile or docker-compose.yml files alongside the devcontainer.json file. For more information, see "Using Images, Dockerfiles, and Docker Compose" on the Development Containers website.
Step 3: Modify your devcontainer.json file
With your dev container configuration added and a basic understanding of what everything does, you can now make changes to customize your environment further. In this example, you'll add properties that will:
- Run a command, after the dev container is created, to create a new file.
- Automatically install two VS Code extensions in this codespace.
-
In the
devcontainer.jsonfile, add a comma after thefeaturesproperty.JSON "features": { "ghcr.io/devcontainers/features/java:1": { "version": "none", "installMaven": "true", "installGradle": "false" }, "ghcr.io/devcontainers-contrib/features/ant-sdkman:2": {} }, -
Uncomment the
postCreateCommandproperty and change its value toecho \"This file was added by the postCreateCommand.\" > TEMP.md.JSON // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "echo \"This file was added by the postCreateCommand.\" > TEMP.md", -
Uncomment the
customizationsproperty and edit it as follows to install the "Code Spell Checker" extension and the "Extension Pack for Java."JSON // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "streetsidesoftware.code-spell-checker", "vscjava.vscode-java-pack" ] } }The
devcontainer.jsonfile should now look similar to this, depending on which image you chose:// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/java { "name": "Java", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "image": "mcr.microsoft.com/devcontainers/java:0-17", "features": { "ghcr.io/devcontainers/features/java:1": { "version": "none", "installMaven": "true", "installGradle": "false" }, "ghcr.io/devcontainers-contrib/features/ant-sdkman:2": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "echo \"This file was added by the postCreateCommand.\" > TEMP.md", // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "streetsidesoftware.code-spell-checker", "vscjava.vscode-java-pack" ] } } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" } -
Save your changes.
-
VS Code Command Palette(Shift+Command+P(Mac)/Ctrl+Shift+P(Windows/Linux))에 액세스한 다음 “rebuild”라고 입력을 시작합니다. codespace: 컨테이너 다시 빌드 를 선택합니다.
codespace 내에서 다시 빌드하면 리포지토리에 변경 내용을 커밋하기 전에 변경 내용이 예상대로 작동하는지 확인할 수 있습니다. 오류가 발생하는 경우 컨테이너를 계속 조정하기 위해 다시 빌드할 수 있는 복구 컨테이너가 있는 codespace에 배치됩니다.팁: 경우에 따라 전체 다시 빌드를 수행하여 캐시를 지우고 새 이미지로 컨테이너를 다시 빌드할 수 있습니다. 자세한 내용은 "컨테이너의 전체 다시 빌드 수행"을 참조하세요.
After the dev container is rebuilt, and your codespace becomes available again, the
postCreateCommandwill have been run, creating aTEMP.mdfile, and the two extensions will be available for use.
Step 4: Run your application
-
Run the application by pressing
F5. -
If a "toast" notification message is displayed at the bottom right corner of VS Code, asking whether you want to switch to standard mode, click Yes.

-
When the project files have been imported, click the Debug Console tab to see the program output.

Step 5: Commit your changes
새 코드 또는 구성 변경을 통해 codespace를 변경한 후에 변경 내용을 커밋할 수 있습니다. 리포지토리에 변경 내용을 커밋하면 이 리포지토리에서 codespace를 만드는 다른 모든 사용자가 동일한 구성을 갖게 됩니다. 이는 또한 모든 사용자에게 VS Code 확장 추가와 같은 모든 사용자 지정이 표시됨을 의미합니다.
자세한 내용은 “codespace에서 소스 제어 사용”을 참조하세요.
Next steps
You should now be able to add a custom dev container configuration to your own Java project.
- Codespaces에 대한 암호화된 비밀 관리
- Codespaces에 대한 GPG 확인 관리
- codespace의 포트 전달

