1---
2title: Java
3description: "Configure Java language support in Zed, including language servers, formatting, and debugging."
4---
5
6# Java
7
8Java language support in Zed is provided by:
9
10- Zed Java: [zed-extensions/java](https://github.com/zed-extensions/java)
11- Tree-sitter: [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java)
12- Language Server: [eclipse-jdtls/eclipse.jdt.ls](https://github.com/eclipse-jdtls/eclipse.jdt.ls)
13
14## Install OpenJDK
15
16You will need to install a Java runtime (OpenJDK).
17
18- macOS: `brew install openjdk`
19- Ubuntu: `sudo add-apt-repository ppa:openjdk-23 && sudo apt-get install openjdk-23`
20- Windows: `choco install openjdk`
21- Arch Linux: `sudo pacman -S jre-openjdk-headless`
22
23Or manually download and install [OpenJDK 23](https://jdk.java.net/23/).
24
25## Extension Install
26
27You can install by opening {#action zed::Extensions}({#kb zed::Extensions}) and searching for `java`.
28
29## Quick start and configuration
30
31For the majority of users, Java support should work out of the box.
32
33- It is generally recommended to open projects with the Zed-project root at the Java project root folder (where you would commonly have your `pom.xml` or `build.gradle` file).
34
35- By default the extension will download and run the latest official version of JDTLS for you, but this requires Java version 21 to be available on your system via either the `$JAVA_HOME` environment variable or as a `java(.exe)` executable on your `$PATH`. If your project requires a lower Java version in the environment, you can specify a different JDK to use for running JDTLS via the `java_home` configuration option.
36
37- You can provide a **custom launch script for JDTLS**, by adding an executable named `jdtls` (or `jdtls.bat` on Windows) to your `$PATH` environment variable. If this is present, the extension will skip downloading and launching a managed instance and use the one from the environment.
38
39- To support [Lombok](https://projectlombok.org/), the lombok-jar must be downloaded and registered as a Java-Agent when launching JDTLS. By default the extension automatically takes care of that, but in case you don't want that you can set the `lombok_support` configuration-option to `false`.
40
41Here is a common `settings.json` including the above mentioned configurations:
42
43```jsonc
44{
45 "lsp": {
46 "jdtls": {
47 "settings": {
48 "java_home": "/path/to/your/JDK21+",
49 "lombok_support": true,
50 },
51 },
52 },
53}
54```
55
56## Debugging
57
58Debug support is enabled via our [Fork of Java Debug](https://github.com/zed-industries/java-debug), which the extension will automatically download and start for you. Please refer to the [Debugger Documentation](https://zed.dev/docs/debugger#getting-started) for general information about how debugging works in Zed.
59
60To get started with Java, click the `edit debug.json` button in the Debug menu, and replace the contents of the file with the following:
61
62```jsonc
63[
64 {
65 "adapter": "Java",
66 "request": "launch",
67 "label": "Launch Debugger",
68 // if your project has multiple entry points, specify the one to use:
69 // "mainClass": "com.myorganization.myproject.MyMainClass",
70 //
71 // this effectively sets a breakpoint at your program entry:
72 "stopOnEntry": true,
73 // the working directory for the debug process
74 "cwd": "$ZED_WORKTREE_ROOT",
75 },
76]
77```
78
79You should then be able to start a new Debug Session with the "Launch Debugger" scenario from the debug menu.
80
81## Launch Scripts (aka Tasks) in Windows
82
83This extension provides tasks for running your application and tests from within Zed via little play buttons next to tests/entry points. However, due to current limitations of Zed's extension interface, we can not provide scripts that will work across Maven and Gradle on both Windows and Unix-compatible systems, so out of the box the launch scripts only work on Mac and Linux.
84
85There is a fairly straightforward fix that you can apply to make it work on Windows by supplying your own task scripts. Please see [this Issue](https://github.com/zed-extensions/java/issues/94) for information on how to do that and read the [Tasks section in Zeds documentation](https://zed.dev/docs/tasks) for more information.
86
87## Advanced Configuration/JDTLS initialization Options
88
89JDTLS provides many configuration options that can be passed via the `initialize` LSP-request. The extension will pass the JSON-object from `lsp.jdtls.settings.initialization_options` in your settings on to JDTLS. Please refer to the [JDTLS Configuration Wiki Page](https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request) for the available options and values. Below is an example `settings.json` that would pass on the example configuration from the above wiki page to JDTLS:
90
91```jsonc
92{
93 "lsp": {
94 "jdtls": {
95 "settings": {
96 // this will be sent to JDTLS as initializationOptions:
97 "initialization_options": {
98 "bundles": [],
99 // use this if your zed project root folder is not the same as the java project root:
100 "workspaceFolders": ["file:///home/snjeza/Project"],
101 "settings": {
102 "java": {
103 "home": "/usr/local/jdk-9.0.1",
104 "errors": {
105 "incompleteClasspath": {
106 "severity": "warning",
107 },
108 },
109 "configuration": {
110 "updateBuildConfiguration": "interactive",
111 "maven": {
112 "userSettings": null,
113 },
114 },
115 "import": {
116 "gradle": {
117 "enabled": true,
118 },
119 "maven": {
120 "enabled": true,
121 },
122 "exclusions": [
123 "**/node_modules/**",
124 "**/.metadata/**",
125 "**/archetype-resources/**",
126 "**/META-INF/maven/**",
127 "/**/test/**",
128 ],
129 },
130 "referencesCodeLens": {
131 "enabled": false,
132 },
133 "signatureHelp": {
134 "enabled": false,
135 },
136 "implementationCodeLens": "all",
137 "format": {
138 "enabled": true,
139 },
140 "saveActions": {
141 "organizeImports": false,
142 },
143 "contentProvider": {
144 "preferred": null,
145 },
146 "autobuild": {
147 "enabled": false,
148 },
149 "completion": {
150 "favoriteStaticMembers": [
151 "org.junit.Assert.*",
152 "org.junit.Assume.*",
153 "org.junit.jupiter.api.Assertions.*",
154 "org.junit.jupiter.api.Assumptions.*",
155 "org.junit.jupiter.api.DynamicContainer.*",
156 "org.junit.jupiter.api.DynamicTest.*",
157 ],
158 "importOrder": ["java", "javax", "com", "org"],
159 },
160 },
161 },
162 },
163 },
164 },
165 },
166}
167```
168
169## See also
170
171[Zed Java Repo](https://github.com/zed-extensions/java)
172[Eclipse JDTLS Repo](https://github.com/eclipse-jdtls/eclipse.jdt.ls)