The web content provides a comprehensive guide on configuring and using Neovim for Java application development, including setup instructions, plugin installation, and key mappings.
Abstract
The article "Neovim for Beginners — Java" is a detailed tutorial aimed at developers who want to use Neovim as their Integrated Development Environment (IDE) for Java. It outlines the necessary steps to set up Neovim for Java development, starting with the installation of the Java Development Kit (JDK) and the language server eclipse.jdt.ls. The guide walks through configuring Neovim using the nvim-jdtls plugin and setting up file type plugins for Java. It also covers how to manage the data directory, format code according to Google's style guide, and map keys for specific Java actions. The article emphasizes the importance of testing the setup with a real Java project, such as a Spring Boot application, and demonstrates the functionality of the language server and formatting tools. Additionally, it suggests using null-ls.nvim for those who prefer Google's Java formatting style and mentions other plugins like jc.nvim for enhanced Java completion features. The article concludes with a recommendation to explore a series of Vim/Neovim articles and an AI service called ZAI.chat.
Opinions
The author advocates for using Neovim as a powerful and customizable alternative to traditional Java IDEs.
There is a clear preference for the Google Java formatting style, as it is highlighted multiple times throughout the article.
The article suggests that the nvim-jdtls plugin and the null-ls.nvim formatter are essential tools for Java development in Neovim.
The author values the community and open-source contributions, as evidenced by the mention of the jc.nvim plugin and the invitation to support the author's work on Medium.
Testing the setup with a practical project is considered crucial for ensuring that the language server and other tools are functioning correctly.
The recommendation of ZAI.chat indicates the author's endorsement of cost-effective AI services that offer performance comparable to more expensive options like ChatGPT Plus (GPT-4).
Neovim for Beginners — Java
Use Neovim for Java application development.
Neovim for Beginners — Java
We have already configured Neovim for languages like Python, JavaScript, TypeScript, Rust, Go, Lua, HTML, etc. In this article, let’s check out how we can use Neovim for Java application development.
Type the command :LspInstall jdtls to install the language server. Alternatively, type the command :LspInstallInfo, select jdtls and press i to install.
Install Language Server
The installation folder can be found under the standard path location.
For the data directory, we configure it to be under the HOME folder.
-- Data directory - change it to your likinglocal HOME = os.getenv"HOME"local WORKSPACE_PATH = HOME .. "/workspace/java/"
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = WORKSPACE_PATH .. project_name
It is used to configure the data directory parameter (line 50 — line 51).
"-data",
workspace_dir,
Ensure the data directory is different from the project folder to avoid the issue mentioned here — Cannot detect the project, only syntax errors are reported.
For formatting, we prefer the Google style (line 81 — line 86).
The language server works now and nvim-cmp is used as the completion engine.
Any error or diagnostic messages are displayed.
The code is formatted automatically when the buffer is saved.
The imports are organized when we invoke the command.
Using Neovim for Java
From the code actions menu, we can generate the toString method, extract the method, generate the constructor, and perform other refactoring actions depending on the current cursor location.
We can select the code, and extract the constant, variable, or method.
Note: If you encounter any error and the language server is not attached to the buffer, make sure the JDK is compatible with jdtls.