Skip to content

Commit de1214e

Browse files
mohsenarigcurtis
andauthored
IDE integration instructions (#190)
## Summary Added IDE integration instructions for Eclipse and VSCode for Java projects. The files are added to a new directory in `docs/app/docs/ide_integration/` adjacent to `language_support/` directory. But I'm open to putting the guides somewhere more appropriate. ## How was it tested? Local IDE setup. Signed-off-by: mohsenari <[email protected]> Co-authored-by: Greg Curtis <[email protected]>
1 parent d1f41ea commit de1214e

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Eclipse IDE configuration
3+
---
4+
5+
6+
## Java
7+
This guide describes how to configure Eclipse to work with a devbox Java environment.
8+
9+
### Setting up Devbox shell
10+
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:
11+
12+
1. `devbox init` if you don't have a devbox.json in the root directory of your project.
13+
2. `devbox add jdk` to make sure jdk gets installed in your devbox shell.
14+
3. `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:
15+
```bash
16+
/nix/store/qaf9fysymdoj19qtyg7209s83lajz65b-zulu17.34.19-ca-jdk-17.0.3
17+
```
18+
4. Open Eclipse IDE and create a new Java project if you don't have already
19+
5. From the top menu go to Run > Run Configurations > JRE and choose **Alternate JRE:**
20+
6. Click on **Installed JREs...** and click **Add...** in the window of Installed JREs.
21+
7. Choose **Standard VM** as JRE Type and click Next.
22+
8. 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.
23+
9. Click **Apply and Close** in Installed JREs window. Then close Run Configurations.
24+
25+
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.
26+
27+
### Setting up Eclipse Terminal
28+
29+
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.
30+
31+
1. Press `ctrl + alt/opt + T` to open terminal window in Eclipse.
32+
2. Navigate to the projects root directory using `cd` command.
33+
3. Make sure `devbox.json` is present in the root directory `ls | grep devbox.json`
34+
4. Run `devbox shell` to activate devbox shell in the terminal.
35+
5. 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:
36+
```bash
37+
my_java_project/
38+
-- src/
39+
-- -- main/
40+
-- -- -- hello.java
41+
```
42+
You can use the following command to compile:
43+
to compile:
44+
```bash
45+
javac my_java_project/src/main/hello.java
46+
```
47+
6. Use `java` command to run the compiled proect. For example, to run the sample project from above:
48+
```bash
49+
cd src/
50+
java main/hello
51+
```
52+
53+
If this guide is missing something, feel free to contribute by opening a [pull request](https://github.com/jetpack-io/devbox/pulls) in Github.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: VSCode configuration
3+
---
4+
5+
6+
## Java
7+
___
8+
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.
9+
10+
### Setting up Run and Debugger
11+
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:
12+
13+
1. `devbox init` if you don't have a devbox.json in the root directory of your project.
14+
2. `devbox add jdk` to make sure jdk gets installed in your devbox shell.
15+
3. `devbox shell -- 'which java` to 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:
16+
```bash
17+
/nix/store/qaf9fysymdoj19qtyg7209s83lajz65b-zulu17.34.19-ca-jdk-17.0.3/bin/java
18+
```
19+
4. 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.
20+
5. Click on **Run and Debug** icon from the left sidebar.
21+
6. 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.
22+
7. Once the `launch.json` file is opened, update the `configurations` parameter to look like snippet below:
23+
```json
24+
{
25+
"type": "java",
26+
"name": "Launch Current File",
27+
"request": "launch",
28+
"mainClass": "<project_directory_name>/<main_package>.<main_class>",
29+
"projectName": "<project_name>",
30+
"javaExec": "<path_to_java_executable_from_step_4>"
31+
}
32+
```
33+
Update the values in between < and > to match your project and environment.
34+
8. Click on **Run and Debug** or the green triangle at the top of the left sidebar to run and debug your project.
35+
36+
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.
37+
38+
### Setting up Terminal
39+
40+
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.
41+
42+
1. Open VS Code terminal (`ctrl + shift + ~` in MacOS)
43+
2. Navigate to the projects root directory using `cd` command.
44+
3. Make sure `devbox.json` is present in the root directory `ls | grep devbox.json`
45+
4. Run `devbox shell` to activate devbox shell in the terminal.
46+
5. 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:
47+
```bash
48+
my_java_project/
49+
-- src/
50+
-- -- main/
51+
-- -- -- hello.java
52+
```
53+
You can use the following command to compile:
54+
to compile:
55+
```bash
56+
javac my_java_project/src/main/hello.java
57+
```
58+
6. Use `java` command to run the compiled proect. For example, to run the sample project from above:
59+
```bash
60+
cd src/
61+
java main/hello
62+
```
63+
64+
If this guide is missing something, feel free to contribute by opening a [pull request](https://github.com/jetpack-io/devbox/pulls) in Github.

0 commit comments

Comments
 (0)