1# Java
  2
  3Java language support in Zed is provided by:
  4
  5- Zed Java: [zed-extensions/java](https://github.com/zed-extensions/java)
  6- Tree-sitter: [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java)
  7- Language Server: [eclipse-jdtls/eclipse.jdt.ls](https://github.com/eclipse-jdtls/eclipse.jdt.ls)
  8
  9## Install OpenJDK
 10
 11You will need to install a Java runtime (OpenJDK).
 12
 13- macOS: `brew install openjdk`
 14- Ubuntu: `sudo add-apt-repository ppa:openjdk-23 && sudo apt-get install openjdk-23`
 15- Windows: `choco install openjdk`
 16- Arch Linux: `sudo pacman -S jre-openjdk-headless`
 17
 18Or manually download and install [OpenJDK 23](https://jdk.java.net/23/).
 19
 20## Extension Install
 21
 22You can install either by opening {#action zed::Extensions}({#kb zed::Extensions}) and searching for `java`.
 23
 24## Settings / Initialization Options
 25
 26The extension will automatically download the language server, see: [Manual JDTLS Install](#manual-jdts-install) below if you'd prefer to manage that yourself.
 27
 28For available `initialization_options` please see the [Initialize Request section of the Eclipse.jdt.ls Wiki](https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request).
 29
 30You can add these customizations to your Zed Settings by launching {#action zed::OpenSettings}({#kb zed::OpenSettings}) or by using a `.zed/setting.json` inside your project.
 31
 32### Zed Java Settings
 33
 34```json [settings]
 35{
 36  "lsp": {
 37    "jdtls": {
 38      "initialization_options": {}
 39    }
 40  }
 41}
 42```
 43
 44## Example Configs
 45
 46### JDTLS Binary
 47
 48By default, zed will look in your `PATH` for a `jdtls` binary, if you wish to specify an explicit binary you can do so via settings:
 49
 50```json [settings]
 51  "lsp": {
 52    "jdtls": {
 53      "binary": {
 54        "path": "/path/to/java/bin/jdtls",
 55        // "arguments": [],
 56        // "env": {},
 57        "ignore_system_version": true
 58      }
 59    }
 60  }
 61```
 62
 63### Zed Java Initialization Options
 64
 65There are also many more options you can pass directly to the language server, for example:
 66
 67```json [settings]
 68{
 69  "lsp": {
 70    "jdtls": {
 71      "initialization_options": {
 72        "bundles": [],
 73        "workspaceFolders": ["file:///home/snjeza/Project"],
 74        "settings": {
 75          "java": {
 76            "home": "/usr/local/jdk-9.0.1",
 77            "errors": {
 78              "incompleteClasspath": {
 79                "severity": "warning"
 80              }
 81            },
 82            "configuration": {
 83              "updateBuildConfiguration": "interactive",
 84              "maven": {
 85                "userSettings": null
 86              }
 87            },
 88            "trace": {
 89              "server": "verbose"
 90            },
 91            "import": {
 92              "gradle": {
 93                "enabled": true
 94              },
 95              "maven": {
 96                "enabled": true
 97              },
 98              "exclusions": [
 99                "**/node_modules/**",
100                "**/.metadata/**",
101                "**/archetype-resources/**",
102                "**/META-INF/maven/**",
103                "/**/test/**"
104              ]
105            },
106            "jdt": {
107              "ls": {
108                "lombokSupport": {
109                  "enabled": false // Set this to true to enable lombok support
110                }
111              }
112            },
113            "referencesCodeLens": {
114              "enabled": false
115            },
116            "signatureHelp": {
117              "enabled": false
118            },
119            "implementationsCodeLens": {
120              "enabled": false
121            },
122            "format": {
123              "enabled": true
124            },
125            "saveActions": {
126              "organizeImports": false
127            },
128            "contentProvider": {
129              "preferred": null
130            },
131            "autobuild": {
132              "enabled": false
133            },
134            "completion": {
135              "favoriteStaticMembers": [
136                "org.junit.Assert.*",
137                "org.junit.Assume.*",
138                "org.junit.jupiter.api.Assertions.*",
139                "org.junit.jupiter.api.Assumptions.*",
140                "org.junit.jupiter.api.DynamicContainer.*",
141                "org.junit.jupiter.api.DynamicTest.*"
142              ],
143              "importOrder": ["java", "javax", "com", "org"]
144            }
145          }
146        }
147      }
148    }
149  }
150}
151```
152
153## Manual JDTLS Install
154
155If you prefer, you can install JDTLS yourself and the extension can be configured to use that instead.
156
157- macOS: `brew install jdtls`
158- Arch: [`jdtls` from AUR](https://aur.archlinux.org/packages/jdtls)
159
160Or manually download install:
161
162- [JDTLS Milestone Builds](http://download.eclipse.org/jdtls/milestones/) (updated every two weeks)
163- [JDTLS Snapshot Builds](https://download.eclipse.org/jdtls/snapshots/) (frequent updates)
164
165## See also
166
167- [Zed Java Repo](https://github.com/zed-extensions/java)
168- [Zed Java Issues](https://github.com/zed-extensions/java/issues)