5.6 KiB
Java
There are two extensions that provide Java language support for Zed:
- Zed Java: zed-extensions/java and
- Java with Eclipse JDTLS: zed-java-eclipse-jdtls.
Both use:
- Tree Sitter: tree-sitter/tree-sitter-java
- Language Server: eclipse-jdtls/eclipse.jdt.ls
Pre-requisites
Install OpenJDK
You will need to install a Java runtime (OpenJDK).
- MacOS:
brew install openjdk
- Ubuntu:
sudo add-apt-repository ppa:openjdk-23 && sudo apt-get install openjdk-23
- Windows:
choco install openjdk
- Arch Linux:
sudo pacman -S jre-openjdk-headless
Or manually download and install OpenJDK 23.
(Optional) Install JDTLS
If you are using Java with Eclipse JDTLS, you can skip this section as it will automatically download a binary for you.
If you are using Zed Java you need to install your own copy of Eclipse JDT Language Server (eclipse.jdt.ls
).
- MacOS:
brew install jdtls
- Arch:
jdtls
from AUR
Or manually download install:
- JDTLS Milestone Builds (updated every two weeks)
- JDTLS Snapshot Builds (frequent updates)
Extension Install
You can install either by opening {#action zed::Extensions}({#kb zed::Extensions}) and searching for java
.
We recommend you install one or the other and not both.
Settings / Initialization Options
For available initialization_options
please see the Initialize Request section of the Eclipse.jdt.ls Wiki.
Add the following to your Zed Settings by launching {#action zed::OpenSettings}({#kb zed::OpenSettings}).
Zed Java Settings
{
"lsp": {
"jdtls": {
"settings": {},
"initialization_options": {}
}
}
}
Java with Eclipse JDTLS settings
{
"lsp": {
"java": {
"settings": {},
"initialization_options": {}
}
}
}
See also
Support
If you have issues with either of these plugins, please open issues on their respective repositories:
Example Configs
Zed Java Classpath
You can optionally configure the class path that JDTLS uses with:
{
"lsp": {
"jdtls": {
"settings": {
"classpath": "/path/to/classes.jar:/path/to/more/classes/"
}
}
}
}
Zed Java Initialization Options
There are also many more options you can pass directly to the language server, for example:
{
"lsp": {
"jdtls": {
"initialization_options": {
"bundles": [],
"workspaceFolders": ["file:///home/snjeza/Project"],
"settings": {
"java": {
"home": "/usr/local/jdk-9.0.1",
"errors": {
"incompleteClasspath": {
"severity": "warning"
}
},
"configuration": {
"updateBuildConfiguration": "interactive",
"maven": {
"userSettings": null
}
},
"trace": {
"server": "verbose"
},
"import": {
"gradle": {
"enabled": true
},
"maven": {
"enabled": true
},
"exclusions": [
"**/node_modules/**",
"**/.metadata/**",
"**/archetype-resources/**",
"**/META-INF/maven/**",
"/**/test/**"
]
},
"referencesCodeLens": {
"enabled": false
},
"signatureHelp": {
"enabled": false
},
"implementationsCodeLens": {
"enabled": false
},
"format": {
"enabled": true
},
"saveActions": {
"organizeImports": false
},
"contentProvider": {
"preferred": null
},
"autobuild": {
"enabled": false
},
"completion": {
"favoriteStaticMembers": [
"org.junit.Assert.*",
"org.junit.Assume.*",
"org.junit.jupiter.api.Assertions.*",
"org.junit.jupiter.api.Assumptions.*",
"org.junit.jupiter.api.DynamicContainer.*",
"org.junit.jupiter.api.DynamicTest.*"
],
"importOrder": ["java", "javax", "com", "org"]
}
}
}
}
}
}
}
Java with Eclipse JTDLS Configuration
Configuration options match those provided in the redhat-developer/vscode-java extension.
For example, to enable Lombok Support:
{
"lsp": {
"java": {
"settings": {
"java.jdt.ls.lombokSupport.enabled:": true
}
}
}
}