VS Code is a popular editor that supports many different programming languages. This guide covers how to configure VS Code to work with a devbox Java environment.
Setting up Run and Debugger
To create a devbox shell make sure to have devbox installed. If you don't have devbox installed follow the installation guide first. Then follow the steps below:
devbox initif you don't have a devbox.json in the root directory of your project.
devbox add jdkto make sure jdk gets installed in your devbox shell.
devbox shell -- 'which javato activate devbox shell temporarily and find the path to your executable java binary inside the devbox shell. Copy and save that path. It should look something like this:
- Open VS Code and create a new Java project if you don't have already. If VS Code prompts for installing Java support choose yes.
- Click on Run and Debug icon from the left sidebar.
- Click on create a launch.json link in the opened sidebar. If you don't see such a link, click on the small gear icon on the top of the open sidebar.
- Once the
launch.jsonfile is opened, update the
configurationsparameter to look like snippet below:Update the values in between < and > to match your project and environment.
"name": "Launch Current File",
- Click on Run and Debug or the green triangle at the top of the left sidebar to run and debug your project.
Now your project in VS Code is setup to run and debug with the same Java that is installed in your devbox shell. Next step is to run your Java code inside Devbox.
Setting up Terminal
The following steps show how to run a Java application in a devbox shell using the VS Code terminal. Note that most of these steps are not exclusive to VS Code and can also be used in any Linux or macOS terminal.
- Open VS Code terminal (
ctrl + shift + ~in MacOS)
- Navigate to the projects root directory using
- Make sure
devbox.jsonis present in the root directory
ls | grep devbox.json
devbox shellto activate devbox shell in the terminal.
javaccommand to compile your Java project. As an example, if you have a simple hello world project and the directory structure such as:You can use the following command to compile: to compile:
-- -- main/
-- -- -- hello.java
javacommand to run the compiled proect. For example, to run the sample project from above:
If this guide is missing something, feel free to contribute by opening a pull request in Github.