This guide describes how to configure Eclipse to work with a devbox Java environment.
Setting up Devbox shell
To create a devbox shell make sure to have devbox installed. If you don't have devbox installed follow the installation guide first. Then run the following commands from the root of your project's repo:
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 -- 'echo $JAVA_HOME'to activate your devbox shell temporarily to find the path to your java home. Copy and save the path. It should look something like:
- Open Eclipse IDE and create a new Java project if you don't have already
- From the top menu go to Run > Run Configurations > JRE and choose Alternate JRE:
- Click on Installed JREs... and click Add... in the window of Installed JREs.
- Choose Standard VM as JRE Type and click Next.
- Paste the value you copied in step 4 in JRE HOME and put an arbitrary name such as "devbox-jre" in JRE Name and click Finish.
- Click Apply and Close in Installed JREs window. Then close Run Configurations.
Now your project in Eclipse is setup to compile and run with the same Java that is installed in your devbox shell. Next step is to run your Java code inside Devbox.
Setting up Eclipse Terminal
The following steps show how to run a Java application in a devbox shell using the Eclipse terminal. Note that most of these steps are not exclusive to Eclipse and can also be used in any Linux or macOS terminal.
ctrl + alt/opt + Tto open terminal window in Eclipse.
- 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.