Documentation
Topics Overview Overview Linux macOS Windows VS Code for the Web Raspberry Pi Network Additional Components Uninstall VS Code Tutorial Copilot Quickstart User Interface Personalize VS Code Install Extensions Tips and Tricks Intro Videos Overview Setup Quickstart Overview Language Models Context Tools Agents Customization Trust & Safety Overview Agents Tutorial Agents Window Planning Memory Tools Subagents Local Agents Copilot CLI Cloud Agents Third-Party Agents Overview Chat Sessions Add Context Inline Chat Review Edits Checkpoints Artifacts Panel Debug Chat Interactions Prompt Examples Overview Instructions Prompt Files Custom Agents Agent Skills Language Models MCP Hooks Plugins Context Engineering Customize AI Test-Driven Development Edit Notebooks with AI Test with AI Test Web Apps with Browser Tools Debug with AI MCP Dev Guide OpenTelemetry Monitoring Inline Suggestions Smart Actions Best Practices Security Troubleshooting FAQ Cheat Sheet Settings Reference MCP Configuration Workspace Context Display Language Layout Keyboard Shortcuts Settings Settings Sync Extension Marketplace Extension Runtime Security Themes Profiles Overview Voice Interactions Command Line Interface Telemetry Basic Editing IntelliSense Code Navigation Refactoring Snippets Overview Multi-Root Workspaces Workspace Trust Tasks Debugging Debug Configuration Testing Port Forwarding Integrated Browser Overview Quickstart Staging & Committing Branches & Worktrees Repositories & Remotes Merge Conflicts Collaborate on GitHub Troubleshooting FAQ Getting Started Tutorial Terminal Basics Terminal Profiles Shell Integration Appearance Advanced Overview Enterprise Policies AI Settings Extensions Telemetry Updates Overview JavaScript JSON HTML Emmet CSS, SCSS and Less TypeScript Markdown PowerShell C++ Java PHP Python Julia R Ruby Rust Go T-SQL C# .NET Swift Working with JavaScript Node.js Tutorial Node.js Debugging Deploy Node.js Apps Browser Debugging Angular Tutorial React Tutorial Vue Tutorial Debugging Recipes Performance Profiling Extensions Tutorial Transpiling Editing Refactoring Debugging Quick Start Tutorial Run Python Code Editing Linting Formatting Debugging Environments Testing Python Interactive Django Tutorial FastAPI Tutorial Flask Tutorial Create Containers Deploy Python Apps Python in the Web Settings Reference Getting Started Navigate and Edit Refactoring Formatting and Linting Project Management Build Tools Run and Debug Testing Spring Boot Modernizing Java Apps Application Servers Deploy Java Apps GUI Applications Extensions FAQ Intro Videos GCC on Linux GCC on Windows GCC on Windows Subsystem for Linux Clang on macOS Microsoft C++ on Windows Build with CMake CMake Tools on Linux CMake Quick Start C++ Dev Tools for Copilot Editing and Navigating Debugging Configure Debugging Refactoring Settings Reference Configure IntelliSense Configure IntelliSense for Cross-Compiling FAQ Intro Videos Get Started Navigate and Edit IntelliCode Refactoring Formatting and Linting Project Management Build Tools Package Management Run and Debug Testing FAQ Overview Node.js Python ASP.NET Core Debug Docker Compose Registries Deploy to Azure Choose a Dev Environment Customize Develop with Kubernetes Tips and Tricks Overview Jupyter Notebooks Data Science Tutorial Python Interactive Data Wrangler Quick Start Data Wrangler PyTorch Support Azure Machine Learning Manage Jupyter Kernels Jupyter Notebooks on the Web Data Science in Microsoft Fabric Foundry Toolkit Overview Foundry Toolkit Copilot Tools Create Agents Models Playground Agent Builder Agent Inspector Evaluation Tool Catalog Fine-Tuning (Automated Setup) Fine-Tuning (Project Template) Model Conversion Tracing Profiling (Windows ML) FAQ File Structure Manual Model Conversion Manual Model Conversion on GPU Setup Environment Without Foundry Toolkit Template Project Migrating from Visualizer to Agent Inspector Overview Getting Started Resources View Deployment VS Code for the Web - Azure Containers Azure Kubernetes Service Kubernetes MongoDB Remote Debugging for Node.js Overview SSH Dev Containers Windows Subsystem for Linux GitHub Codespaces VS Code Server Tunnels SSH Tutorial WSL Tutorial Tips and Tricks FAQ Overview Tutorial Attach to Container Create Dev Container Advanced Containers devcontainer.json Dev Container CLI Tips and Tricks FAQ Default Keyboard Shortcuts Default Settings Substitution Variables Tasks SchemaOn this page there are 7 sections
Managing Java Projects in VS Code
The Project Manager for Java extension helps you to manage your Java projects and their dependencies. It also helps you to create new Java projects, packages, and classes. To get the complete Java language support in Visual Studio Code, you can install the Extension Pack for Java, which includes the Project Manager for Java extension.
Install the Extension Pack for Java
For details on how to get started with the extension pack, you can review the Getting Started with Java tutorial.
Projects view
The Java Projects view helps you view your Java projects and their dependencies, and provides entry points for project management tasks.
By default, the Java Projects view is displayed below the Explorer view. If you cannot see it, try clicking the ... button in the EXPLORER title bar and select Java Projects.
In the overflow button of the navigation bar, there are more options to use. For example, you can switch between hierarchical view and flat view.
You can find buttons next to the nodes in the Explorer, which provide useful shortcuts for some actions.
There are also many useful features in each node's context menu, you can right-click on the node in Explorer to toggle it out.
Create a new Java project
You can create a new Java project by clicking the + button in the navigation bar, or through the command: Java: Create Java Project... in Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)). During creation, VS Code will facilitate installing required extension(s) per your project type, if the extension(s) weren't already installed.
Import Java projects
You can directly import existing Java projects and modules to your workspace through File > Open Folder... (Make sure the opened folder contains your build tool scripts, for example, pom.xml or build.gradle). VS Code for Java will detect your projects and import them automatically.
When you add a new module into your projects, you can trigger the command Java: Import Java projects in workspace to import them to your workspace. This command helps to import new projects into the workspace without the need to reload the VS Code window.
Export to JAR
You can export your build to JAR from the projects view or by running the command Java: Export Jar....
Configure Runtime for Projects
As Java evolves, it's common that developers work with multiple versions of JDK. You can map them to your local installation paths via the setting: java.configuration.runtimes. The setting has following format:
"java.project.referencedLibraries": [ "library/**/*.jar", "/home/username/lib/foo.jar" ]The settings above will add all .jar files in workspace's library folder along with foo.jar from a specified absolute path to the project's external dependencies.
The referenced libraries are then watched by VS Code, and the project will be refreshed if there is a change to any of these dependent files.
By default, VS Code will reference all JAR files in workspace's lib directory using the glob pattern lib/**/*.jar.
Exclude some libraries
If you want to exclude some libraries from the project, you can expand java.project.referencedLibraries to use include/exclude fields and add an exclude glob pattern:
"java.project.referencedLibraries": { "include": [ "library/**/*.jar", "/home/username/lib/foo.jar" ], "exclude": [ "library/sources/**" ], "sources": { "library/bar.jar": "library/sources/bar-src.jar" } }In this way, bar-src.jar is attached to bar.jar as its source.
Lightweight Mode
VS Code for Java supports two modes, lightweight and standard. With lightweight mode, only source files and JDK are resolved by the language server; with standard mode, imported dependencies are resolved and the project is built by the language server. Lightweight mode works best when you need a quick-start and lightweight environment to work with your source files, for example, reading source code, navigating among source code and JDK, viewing outline and Javadoc, and detecting and fixing syntax errors. Also, code completion is supported within the scope of source files and JDK.
Lightweight mode doesn't resolve imported dependencies nor build the project, so it does not support running, debugging, refactoring, linting, or detecting semantic errors. For these features to be available, you need to switch your workspace from lightweight mode to standard mode.
You can control which mode to launch with by configuring java.server.launchMode with the options below:
- Hybrid (default) - Firstly, a workspace is opened with lightweight mode. You will be asked whether to switch to standard mode if your workspace contains unresolved Java projects. If you choose Later, it will stay in lightweight mode. You can click the language status item on the Status bar to manually switch to standard mode.
- Standard - A workspace is opened with standard mode.
- LightWeight - A workspace is opened with lightweight mode. You can click the language status item on the Status bar to manually switch to standard mode.
The language status item indicates which mode the current workspace is in using different icons.
- - workspace opened with lightweight mode.
- - workspace in the process of being opened with standard mode.
- - workspace opened with standard mode.
Clicking the language status item switches to standard mode.
Build Status
When you edit Java source code in Visual Studio Code, the Java language server is building your workspace to provide you with the necessary language features. You can see the detailed build task status and watch what is happening behind the scene by clicking the language status item in the Status bar. You can also select the check details link when a notification shows the language server is opening Java projects to see the build task status.
Additional resources
There are several Visual Studio Code extensions to support different build systems for Java. Below are extensions for several popular build systems.
- Maven for Java
- Gradle for Java
- Bazel for Java (Bazel is for BUILD files, without Java integration))
If you run into any problems when using the features above, you can contact us by filing an issue.
Next steps
Read on to find out more about:
- Java editing - Explore the editing features for Java in VS Code.
- Java debugging - Find out how to debug your Java project with VS Code.
- Java testing - Use VS Code for your JUnit and TestNG cases.
- Java extensions - Learn about more useful Java extensions for VS Code.