| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A Java language server based on v3.0 of the protocol and implemented using the Java compiler API.
Install from the VS Code marketplace
let g:lsc_server_commands = {'java': '<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh'}Note: This tool is not compatible with vim-lsp as it only supports LSPv2.0.
Checkout this repository
Run ./scripts/download_{linux|mac|windows}.sh
Run ./scripts/link_{linux|mac|windows}.sh
Run mvn package -DskipTests
In Emacs 29+, Eglot is built-in, otherwise you can install it with M-x package-install eglot
Add this configuration to your Emacs init file:
(add-hook 'java-mode-hook #'eglot-ensure)For older Eglot versions (<= 1.12.29), you'll also need:
(add-to-list 'eglot-server-programs '(java-mode . ("<path-to-java-language-server-dir>/dist/lang_server_{linux|mac|windows}.sh")))Alternatively, for newer versions (>= 1.19), it is sufficient to have a script called java-language-server in your PATH that launches the actual server. In Linux, this can be done for instance by creating a script in /usr/local/bin:
sudo bash -c 'cat << EOF > /usr/local/bin/java-language-server
#! /bin/sh
<path-to-java-language-server-dir>/dist/lang_server_linux.sh
EOF'
sudo chmod +x /usr/local/bin/java-language-serverMacOS and Windows should work similarly.
{
"servers":
{
"java":
{
"command": ["bash","<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh"],
"url": "https://github.com/georgewfraser/java-language-server",
"highlightingModeRegex": "^Java$"
}
}
}{
"clients":
{
"jls":
{
"enabled": true,
"command": ["bash", "<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh"],
"scopes": ["source.java"],
"syntaxes": ["Packages/Java/Java.sublime-syntax"],
"languageId": "java"
}
}
}The language server will provide autocomplete and other features using:
If the language server doesn't detect your external dependencies automatically, you can specify them using .vscode/settings.json
{
"java.externalDependencies": [
"junit:junit:jar:4.12:test", // Maven format
"junit:junit:4.12" // Gradle-style format is also allowed
]
}If all else fails, you can specify the Java class path and the locations of source jars manually:
{
"java.classPath": [
"lib/some-dependency.jar"
],
"java.docPath": [
"lib/some-dependency-sources.jar"
]
}You can generate a list of external dependencies using your build tool:
The Java language server will look for the dependencies you specify in java.externalDependencies in your Maven and Gradle caches ~/.m2 and ~/.gradle. You should use your build tool to download the library and source jars of all your dependencies so that the Java language server can find them:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile group: 'junit', name: 'junit', version: '4.+', classifier: 'sources'
}
The Java language server uses the Java compiler API to implement language features like linting, autocomplete, and smart navigation, and the language server protocol to communicate with text editors like VSCode.
The Java compiler API provides incremental compilation at the level of files: you can create a long-lived instance of the Java compiler, and as the user edits, you only need to recompile files that have changed. The Java language server optimizes this further by focusing compilation on the region of interest by erasing irrelevant code. For example, suppose we want to provide autocomplete after print in the below code:
class Printer {
void printFoo() {
System.out.println("foo");
}
void printBar() {
System.out.println("bar");
}
void main() {
print // Autocomplete here
}
}None of the code inside printFoo() and printBar() is relevant to autocompleting print. Before servicing the autocomplete request, the Java language server erases the contents of these methods:
class Printer {
void printFoo() {
}
void printBar() {
}
void main() {
print // Autocomplete here
}
}For most requests, the vast majority of code can be erased, dramatically speeding up compilation.
The java service process will output a log file to stderr, which is visible in VSCode using View / Output, under "Java".
Before installing locally, you need to install prerequisites: npm, maven, protobuf. For example on Mac OS, you can install these using Brew:
brew install npm maven protobuf
You also need to have Java 25 installed. Point the JAVA_HOME environment variable to it. For example, on Mac OS:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home/
Assuming you have these prerequisites, you should be able to install locally using:
npm install -g vsce npm install ./scripts/build.sh
Please run ./configure before your first commit to install a pre-commit hook that formats the code.
| Back | FazBrowse Home | New Git URL |