doomemacs/modules/lang/java
Henrik Lissner 1f8bf7accb
merge: rewrite-docs
I've omitted docs/*.org from this merge, as there is still work left to
do there, but I am pushing the module docs early so folks can benefit
from the new docs sooner.
2022-08-03 03:27:50 +02:00
..
autoload Rename Groovy REPL command 2021-04-16 23:22:30 +07:00
+eclim.el Refactor localleader keybinds #1270 2019-10-04 22:04:47 -04:00
+lsp.el tweak(:lang,:tools): start eglot/lsp-mode later 2022-03-30 17:32:47 +02:00
+meghanada.el refactor: rename orig-fn arg in advice to fn 2021-08-04 01:53:12 -04:00
config.el refactor(:lang): move tree-sitter init 2022-07-25 17:34:44 +02:00
doctor.el docs(tree-sitter): add doctor checks for flag 2022-05-22 21:26:00 +01:00
packages.el bump: :lang 2022-03-31 21:09:38 +02:00
README.org fix(docs): set mode in file-local vars 2022-08-03 02:46:33 +02:00

:lang java

Description   unfold

This module adds Java support to Doom Emacs, including android-mode and groovy-mode.

Maintainers

This module has no dedicated maintainers. Become a maintainer?

Module flags

+lsp
Enable LSP support for java-mode. Requires :tools lsp and a langserver (supports eclipse.jdt.ls). Incompatible with +meghanada.
+meghanada
Enable meghanada-mode. Incompatible with +lsp.
+tree-sitter
Leverages tree-sitter for better syntax highlighting and structural text editing. Requires :tools tree-sitter.

Hacks

No hacks documented for this module.

TODO Changelog

This module does not have a changelog yet.

Installation

Enable this module in your doom! block.

This module requires:

OpenJDK 11

Ubuntu

#+begin-src sh apt-get install openjdk-11-jdk-headless

#+end_src

Fedora

dnf install java-11-openjdk

Oracle JDK 11

Ubuntu

add-apt-repository ppa:linuxuprising/java
apt update
apt install oracle-java11-installer
apt install oracle-java11-set-default

Fedora

curl -O https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
tar zxvf openjdk-11.0.2_linux-x64_bin.tar.gz
sudo mv jdk-11.0.2/ /usr/local/

Open /etc/profile.d/jdk11.sh as root and add:

export JAVA_HOME=/usr/local/jdk-11.0.2
export PATH=$PATH:$JAVA_HOME/bin

Save the file and source it:

source /etc/profile.d/jdk11.sh
java -version

Multiple Java Versions

It is common to need support for multiple Java versions. You can use a generic tool like jabba to install and manage multiple Java versions on any OS.

To have a different version of Java per-project, it is recommended you use direnv and :tools direnv; create a .envrc in the root of the project pointing to the Java installation:

PATH_add ~/.jabba/jdk/adopt@1.11.0-3
JAVA_HOME=~/.jabba/jdk/adopt@1.11.0-3

And then run $ direnv allow . in the project directory. The :tools direnv module will automatically source this environment before activating LSP servers.

TODO Usage

🔨 This module's usage documentation is incomplete. Complete it?

+lsp features

According to https://github.com/emacs-lsp/lsp-java, you get:

  • As you type reporting of parsing and compilation errors (via flycheck or lsp-ui)
  • Code completion (company-lsp or complete-at-point)
  • Javadoc hovers (lsp-ui)
  • Code actions (lsp-ui)
  • Code outline (imenu)
  • Code navigation (xref)
  • Code lens for references/implementations (xref)
  • Highlights
  • Code formatting
  • Maven pom.xml project support
  • Limited Gradle support
  • Visual debugger (dap-mode)
  • Test runner (dap-mode)
  • Project explorer integration (treemacs)
  • Integration with Spring Initializr

+meghanada features

According to https://github.com/mopemope/meghanada-emacs/, you get:

  • Auto-update server module
  • Gradle and Maven and Eclipse project support
  • No need build tool's plugin
  • Run build tool task
  • Compile your project
  • Syntax check and analyze java source (flycheck-meghanada)
  • Support Generic Types
  • Code completion with company-mode (company-meghanada)
  • Optimize import and sort
  • Jump declaration
  • Run JUnit test (include test runner)
  • Diagnostic reporting with flycheck (flycheck-meghanada)
  • Show symbol's type info with eldoc
  • Search references
  • Full-featured text search

TODO Configuration

🔨 This module's configuration documentation is incomplete. Complete it?

+lsp

Install the eclipse server by executing M-x lsp-install-server and selecting jdtls. After that any newly opened java files should start the LSP server automatically.

To update the server, perform SPC u M-x lsp-install-server.

Note that if you change Java version you may need to remove the LSP server and install it again. You can do this with M-x +lsp/uninstall-server followed by M-x lsp-install-server.

Enable the :tools debugger +lsp module to get test runner support.

Troubleshooting

There are no known problems with this module. Report one?

Frequently asked questions

This module has no FAQs yet. Ask one?

TODO Appendix

🔨 This module has no appendix yet. Write one?