Eclipse IDE
Java
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 init
if you don't have a devbox.json in the root directory of your project.devbox add jdk
to 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:/nix/store/qaf9fysymdoj19qtyg7209s83lajz65b-zulu17.34.19-ca-jdk-17.0.3
- 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.
- Press
ctrl + alt/opt + T
to open terminal window in Eclipse. - Navigate to the projects root directory using
cd
command. - Make sure
devbox.json
is present in the root directoryls | grep devbox.json
- Run
devbox shell
to activate devbox shell in the terminal. - Use
javac
command 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:my_java_project/
-- src/
-- -- main/
-- -- -- hello.javajavac my_java_project/src/main/hello.java
- Use
java
command to run the compiled proect. For example, to run the sample project from above:cd src/
java main/hello
If this guide is missing something, feel free to contribute by opening a pull request in Github.