This is a WIP community resource, containing content contributed by community members.
This guide will walk you through creating a new Java project in VS Code from scratch.
Ensure you have followed our guide on Preparing VS Code for Java.
There are two methods you can use to create a new Java project:
The easiest way to create a new Java project is using VS Code's built-in project wizard.
VS Code may prompt you to install the Java Development Kit during project creation. You can skip this if you have already installed the JDK.
Ctrl+Shift+P
| Cmd+Shift+P
Java: Create Java Project
and select it
If you prefer more control over the project setup, you can create a project manually.
Step 1: Create a workspace folder
Create a project folder on your computer (e.g., MyJavaProject
)
Open VS Code and select File
→ Open Folder...
Navigate to and select your project folder
Click "Select Folder" to open it as a workspace
After opening the project folder, VS Code may ask if you want to open it as a workspace. If prompted, click ‘Yes’ when asked to open the folder as a workspace.
Step 2: Set up the project structure
Create the following simple folder structure:
MyJavaProject/
└── src/
└── (your Java source files will go here)
Open the Explorer panel: / Ctrl+Shift+E
| Cmd+Shift+E
Right-click in the Explorer panel (Right-click in the empty area, not on an existing file)
Select New Folder
Name it src
VS Code automatically handles compilation, so you do not need separate folders for compiled .class
files.
Step 3: Create your first Java class
Right-click on the src
folder
Select New File
Name it HelloWorld.java
Add the following code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save the file: / Ctrl+S
| Cmd+S
To compile and run your Java program, click the Run
() button or use the Run
menu. You may not see a .class
file appear in your workspace, as VS Code may compile your code in the background or store the output in a hidden folder. If you see Hello, World!
(or your program's expected output), your environment is set up correctly!
If you already have Java installed, VS Code should automatically detect and configure it when you create your project.
After creating your project, you may need to verify and configure VS Code to use the correct JDK version.
Ctrl+Shift+P
| Cmd+Shift+P
Java: Configure Java Runtime
and select itIf no JDK options appear, try reloading VS Code (Open the Command Palette: / Ctrl+Shift+P
| Cmd+Shift+P
, then type and select Developer: Reload Window
) and ensure your JDK is properly installed and added to your system’s PATH
or select "Find a local JDK" to locate the installed JDK in your file system.
To view and modify project settings:
Ctrl+Shift+P
| Cmd+Shift+P
Java: Open Project Settings
and select it.class
files will be stored.vscode/settings.json
You can also configure project settings by creating a .vscode/settings.json
file in the root directory, if it does not exist:
In the project root directory, create a folder named .vscode
.
Inside the .vscode
folder, create a file named settings.json
. This file will store the project's VS Code configuration settings.
Add these configuration settings to the settings.json
file. Update the values to match your project's source folders, output directory, and library paths as needed.
{
"java.project.sourcePaths": [
"src"
],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
If you are using Git to version control the project, you may want to add the following to your .gitignore
file:
# Compiled class files
*.class
# VS Code workspace settings
.vscode/
main
methodmain
method or in the top right corner of the editorIf the ‘Run’ button does not appear, try reloading VS Code (Open the Command Palette: / Ctrl+Shift+P
| Cmd+Shift+P
, then type and select Developer: Reload Window
) or right-click inside the main
method of your Java file and select ‘Run Java’ from the context menu.
Contributors: John Wong (@Johnwz123)