1# Java
2
3There are two extensions that provide Java language support for Zed:
4
5- Zed Java: [zed-extensions/java](https://github.com/zed-extensions/java) and
6- Java with Eclipse JDTLS: [zed-java-eclipse-jdtls](https://github.com/ABckh/zed-java-eclipse-jdtls).
7
8Both use:
9
10- Tree Sitter: [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java)
11- Language Server: [eclipse-jdtls/eclipse.jdt.ls](https://github.com/eclipse-jdtls/eclipse.jdt.ls)
12
13## Pre-requisites
14
15### Install OpenJDK
16
17You will need to install a Java runtime (OpenJDK).
18
19- MacOS: `brew install openjdk`
20- Ubuntu: `sudo add-apt-repository ppa:openjdk-23 && sudo apt-get install openjdk-23`
21- Windows: `choco install openjdk`
22- Arch Linux: `sudo pacman -S jre-openjdk-headless`
23
24Or manually download and install [OpenJDK 23](https://jdk.java.net/23/).
25
26### (Optional) Install JDTLS
27
28If you are using Java with Eclipse JDTLS, you can skip this section as it will automatically download a binary for you.
29
30If you are using Zed Java you need to install your own copy of Eclipse JDT Language Server (`eclipse.jdt.ls`).
31
32- MacOS: `brew install jdtls`
33- Arch: [`jdtls` from AUR](https://aur.archlinux.org/packages/jdtls)
34
35Or manually download install:
36
37- [JDTLS Milestone Builds](http://download.eclipse.org/jdtls/milestones/) (updated every two weeks)
38- [JDTLS Snapshot Builds](https://download.eclipse.org/jdtls/snapshots/) (frequent updates)
39
40## Extension Install
41
42You can install either by opening {#action zed::Extensions}({#kb zed::Extensions}) and searching for `java`.
43We recommend you install one or the other and not both.
44
45## Settings / Initialization Options
46
47See [JDTLS Language Server Settings & Capabilities](https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Language-Server-Settings-&-Capabilities) for a complete list of settings.
48
49Add the following to your Zed Settings by launching {#action zed::OpenSettings}({#kb zed::OpenSettings}).
50
51### Zed Java Settings
52
53```json
54{
55 "lsp": {
56 "jdtls": {
57 "settings": {},
58 "initialization_options": {}
59 }
60 }
61}
62```
63
64### Java with Eclipse JDTLS settings
65
66```json
67{
68 "lsp": {
69 "java": {
70 "settings": {},
71 "initialization_options": {}
72 }
73 }
74}
75```
76
77## See also
78
79- [Zed Java Readme](https://github.com/zed-extensions/java)
80- [Java with Eclipse JDTLS Readme](https://github.com/ABckh/zed-java-eclipse-jdtls)
81
82## Support
83
84If you have issues with either of these plugins, please open issues on their respective repositories:
85
86- [Zed Java Issues](https://github.com/zed-extensions/java/issues)
87- [Java with Eclipse JDTLS Issues](https://github.com/ABckh/zed-java-eclipse-jdtls/issues)
88
89## Example Configs
90
91### Zed Java Classpath
92
93You can optionally configure the class path that JDTLS uses with:
94
95```json
96{
97 "lsp": {
98 "jdtls": {
99 "settings": {
100 "classpath": "/path/to/classes.jar:/path/to/more/classes/"
101 }
102 }
103 }
104}
105```
106
107### Zed Java Initialization Options
108
109There are also many more options you can pass directly to the language server, for example:
110
111```json
112{
113 "lsp": {
114 "jdtls": {
115 "initialization_options": {
116 "bundles": [],
117 "workspaceFolders": ["file:///home/snjeza/Project"],
118 "settings": {
119 "java": {
120 "home": "/usr/local/jdk-9.0.1",
121 "errors": {
122 "incompleteClasspath": {
123 "severity": "warning"
124 }
125 },
126 "configuration": {
127 "updateBuildConfiguration": "interactive",
128 "maven": {
129 "userSettings": null
130 }
131 },
132 "trace": {
133 "server": "verbose"
134 },
135 "import": {
136 "gradle": {
137 "enabled": true
138 },
139 "maven": {
140 "enabled": true
141 },
142 "exclusions": [
143 "**/node_modules/**",
144 "**/.metadata/**",
145 "**/archetype-resources/**",
146 "**/META-INF/maven/**",
147 "/**/test/**"
148 ]
149 },
150 "referencesCodeLens": {
151 "enabled": false
152 },
153 "signatureHelp": {
154 "enabled": false
155 },
156 "implementationsCodeLens": {
157 "enabled": false
158 },
159 "format": {
160 "enabled": true
161 },
162 "saveActions": {
163 "organizeImports": false
164 },
165 "contentProvider": {
166 "preferred": null
167 },
168 "autobuild": {
169 "enabled": false
170 },
171 "completion": {
172 "favoriteStaticMembers": [
173 "org.junit.Assert.*",
174 "org.junit.Assume.*",
175 "org.junit.jupiter.api.Assertions.*",
176 "org.junit.jupiter.api.Assumptions.*",
177 "org.junit.jupiter.api.DynamicContainer.*",
178 "org.junit.jupiter.api.DynamicTest.*"
179 ],
180 "importOrder": ["java", "javax", "com", "org"]
181 }
182 }
183 }
184 }
185 }
186 }
187}
188```
189
190### Java with Eclipse JTDLS Configuration {#zed-java-eclipse-configuration}
191
192Configuration options match those provided in the [redhat-developer/vscode-java extension](https://github.com/redhat-developer/vscode-java#supported-vs-code-settings).
193
194For example, to enable [Lombok Support](https://github.com/redhat-developer/vscode-java/wiki/Lombok-support):
195
196```json
197{
198 "lsp": {
199 "java": {
200 "settings": {
201 "java.jdt.ls.lombokSupport.enabled:": true
202 }
203 }
204 }
205}
206```