---
title: "Java Language Support in Neovim with jdtls"
canonical: "https://mnafshin.info/devtools/02-java-language-support-with-jdtls/"
author: "Afshin Amini"
date: 2026-11-29
---
# Java Language Support in Neovim with jdtls

A language server is a separate program that understands one language and answers an editor's questions about it: what can follow this dot, where is this method defined, who calls it. The editor and the server talk through the Language Server Protocol (LSP), so one Java server can serve Neovim, VS Code and others. For Java, that server is **jdtls**, the Eclipse JDT Language Server, built on the same compiler and project model as the Eclipse IDE.

## How LazyVim starts jdtls

Neovim has an LSP client built in, but jdtls needs more than a plain start command. It needs a workspace folder per project, extra JAR "bundles" for debugging and testing, and a few Java-only commands. The **nvim-jdtls** plugin handles those details.

LazyVim's `lang.java` extra puts the pieces together:

- Mason installs the `jdtls` package.
- nvim-jdtls starts jdtls when the first `.java` file opens, and reuses the same server for every file in that project.
- The project root is found by looking upward for markers such as `mvnw`, `gradlew` or `pom.xml`.
- Lombok support is switched on: the extra passes the `lombok.jar` that ships inside Mason's jdtls package as a Java agent.

You don't need to copy any of this into your configuration. The [Java extra page](https://www.lazyvim.org/extras/lang/java) shows the defaults for reference only.

## Completion while you type

Open `CatalogController.java` from module 9 of the companion code. Its one endpoint asks the repository for a page of catalog items:

```java
@GetMapping("/catalog")
PagedModel<CatalogItem> catalog(Pageable pageable) {
    return new PagedModel<>(repository.findCatalog(pageable));
}
```

[CatalogController.java](https://github.com/mnafshin/springuniverse-code/blob/main/module-09-catalog/src/main/java/info/mnafshin/springuniverse/shop/CatalogController.java)

Delete `Catalog(pageable)` so the line ends in `repository.find`, and a completion menu opens. On our test it listed 41 entries, starting with `findAll`, `findCatalog` and `count`: the methods `ProductRepository` declares plus the ones it inherits from `JpaRepository`. Press Enter (or `Ctrl-y`) to accept an entry. LazyVim uses the blink.cmp completion engine, which shows the method's documentation next to the menu.

## Hover and go to definition

Put the cursor on `findCatalog` and press `K`. A small window shows the full signature, `Page<CatalogItem> ProductRepository.findCatalog(Pageable pageable)`, and the module it comes from.

Now press `gd`, for "go to definition". Neovim jumps to `ProductRepository.java`, to the line that declares the method:

```java
@Query("select p.name, c.name from Product p join p.category c order by p.id")
Page<CatalogItem> findCatalog(Pageable pageable);
```

[ProductRepository.java](https://github.com/mnafshin/springuniverse-code/blob/main/module-09-catalog/src/main/java/info/mnafshin/springuniverse/shop/ProductRepository.java)

`Ctrl-o` takes you back to where you were. Two related jumps are worth knowing: `gy` goes to the definition of a variable's type, and `gI` goes to implementations. Try `gI` on `findCatalog`: it lands on the same interface line, because no class in the project implements `ProductRepository`. Spring Data creates that implementation at runtime, so the editor has nothing else to show.

## Find every usage

With the cursor on `findCatalog`, press `gr` for references. A picker lists three places: the controller line above and two tests in `CatalogTest.java`. Type to filter, move with the arrow keys, and press Enter to open one. This is the same list IntelliJ IDEA calls "Find Usages".

## Search symbols by name

Sometimes you know a name but not the file. Two pickers search symbols, which are classes, methods and fields:

- `<leader>ss` searches the symbols of the current file. `<leader>` is the space bar in LazyVim.
- `<leader>sS` searches the whole workspace, including the JDK and your dependencies.

Typing `CatalogItem` in the workspace search finds the record in `info.mnafshin.springuniverse.shop` at once. For files rather than symbols, `<leader><space>` finds files by name and `<leader>/` searches their text.

## Keep the project model in step

jdtls reads your `pom.xml` once, when it imports the project. If you add a dependency or change a version, run `:JdtUpdateConfig` so it reads the build again. If the workspace ever gets confused, for example after you delete your local Maven repository, `:JdtWipeDataAndRestart` throws away jdtls's cached workspace (not your code) and imports the project from scratch.

One side effect surprises many people. While importing, jdtls writes Eclipse metadata files, `.project`, `.classpath` and a `.settings/` folder, into each Maven module. They are harmless, but add them to your `.gitignore` so they don't end up in commits.

## Recap

- jdtls is the Java language server; nvim-jdtls starts it with the workspace and extras it needs, and LazyVim's `lang.java` extra wires both up, including Lombok.
- Completion opens as you type; accept with Enter or `Ctrl-y`.
- `K` shows hover information, `gd` goes to the definition, `gy` to the type, `gI` to implementations and `gr` lists references.
- `<leader>ss` and `<leader>sS` search symbols in the file or the workspace.
- Run `:JdtUpdateConfig` after build changes, and ignore `.project`, `.classpath` and `.settings/` in Git.

**Series: Neovim as a Java IDE.** Previous: [Neovim and LazyVim for Java: installing the editor, a JDK and the starter](/devtools/01-installing-neovim-lazyvim-and-a-jdk/) · Next: [Diagnostics and quick fixes for Java in Neovim](/devtools/03-diagnostics-and-quick-fixes/)

## Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.

- [Eclipse JDT Language Server (eclipse.jdt.ls) README](https://github.com/eclipse-jdtls/eclipse.jdt.ls)
- [nvim-jdtls README](https://github.com/mfussenegger/nvim-jdtls)
- [LazyVim: Java extra](https://www.lazyvim.org/extras/lang/java)
- [LazyVim: LSP keymaps](https://www.lazyvim.org/keymaps#lsp)
- [Neovim: LSP documentation](https://neovim.io/doc/user/lsp.html)
- [Language Server Protocol overview](https://microsoft.github.io/language-server-protocol/)
- [Lorenzo Bettini: Neovim and Java with LazyVim, part 2: IDE mechanisms](https://www.lorenzobettini.it/2024/12/neovim-and-java-with-lazyvim-part-2-ide-mechanisms/)
- [Lorenzo Bettini: Neovim and Java with LazyVim, part 3: Dependencies and Maven](https://www.lorenzobettini.it/2025/01/neovim-and-java-with-lazyvim-part-3-dependencies-and-maven/)
- [Trinity Logic: A Terminal-First Java and Maven Setup — Neovim, jdtls and the Build Loop](https://www.trinitylogic.co.uk/blog/terminal-first-java-maven-neovim-jdtls/)
