2022-03-28 15:03:21 +02:00
|
|
|
#+title: :lang java
|
|
|
|
#+subtitle: The poster child for carpal tunnel syndrome
|
|
|
|
#+created: January 16, 2017
|
|
|
|
#+since: 1.3
|
2021-10-16 01:28:32 +02:00
|
|
|
|
|
|
|
* Description :unfold:
|
|
|
|
This module adds [[https://www.java.com][Java]] support to Doom Emacs, including ~android-mode~ and
|
|
|
|
~groovy-mode~.
|
|
|
|
|
|
|
|
** Maintainers
|
|
|
|
/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]]
|
|
|
|
|
|
|
|
** Module flags
|
|
|
|
- +lsp ::
|
2022-09-26 02:19:42 +08:00
|
|
|
Enable LSP support for ~java-mode~. Requires [[doom-module::tools lsp]] and a langserver
|
|
|
|
(supports eclipse.jdt.ls). *Incompatible with [[doom-module:+meghanada]].*
|
2021-10-16 01:28:32 +02:00
|
|
|
- +meghanada ::
|
2022-09-26 02:19:42 +08:00
|
|
|
Enable [[doom-package:meghanada-mode]]. *Incompatible with [[doom-module:+lsp]].*
|
2022-04-09 18:38:04 +03:00
|
|
|
- +tree-sitter ::
|
|
|
|
Leverages tree-sitter for better syntax highlighting and structural text
|
2022-09-26 02:19:42 +08:00
|
|
|
editing. Requires [[doom-module::tools tree-sitter]].
|
2021-10-16 01:28:32 +02:00
|
|
|
|
|
|
|
** Packages
|
2022-09-26 02:19:42 +08:00
|
|
|
- [[doom-package:android-mode]]
|
|
|
|
- [[doom-package:groovy-mode]]
|
|
|
|
- [[doom-package:meghanada]] if [[doom-module:+meghanada]]
|
|
|
|
- if [[doom-module:+eclim]]
|
|
|
|
- [[doom-package:eclim]]
|
|
|
|
- [[doom-package:company-emacs-eclim]] if [[doom-module::completion company]]
|
|
|
|
- if [[doom-module:+lsp]] and not [[doom-module::tools lsp +eglot]]
|
|
|
|
- [[doom-package:lsp-java]]
|
2021-10-16 01:28:32 +02:00
|
|
|
|
|
|
|
** Hacks
|
|
|
|
/No hacks documented for this module./
|
|
|
|
|
|
|
|
** TODO Changelog
|
|
|
|
# This section will be machine generated. Don't edit it by hand.
|
|
|
|
/This module does not have a changelog yet./
|
|
|
|
|
|
|
|
* Installation
|
|
|
|
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]
|
|
|
|
|
|
|
|
This module requires:
|
|
|
|
- [[https://www.oracle.com/java/technologies/downloads/][Java SDK]]
|
2022-09-26 02:19:42 +08:00
|
|
|
- The LSP test runner requires [[doom-module::tools debugger +lsp]] (requires [[doom-package:dap-mode]])
|
2020-04-29 06:05:13 +02:00
|
|
|
|
|
|
|
** OpenJDK 11
|
|
|
|
*** Ubuntu
|
2021-10-16 01:28:32 +02:00
|
|
|
#+begin-src sh
|
|
|
|
apt-get install openjdk-11-jdk-headless
|
|
|
|
#+end_src
|
|
|
|
|
2020-04-29 06:05:13 +02:00
|
|
|
*** Fedora
|
2021-10-16 01:28:32 +02:00
|
|
|
#+begin_src sh
|
|
|
|
dnf install java-11-openjdk
|
|
|
|
#+end_src
|
2020-04-29 06:05:13 +02:00
|
|
|
|
|
|
|
** Oracle JDK 11
|
|
|
|
*** Ubuntu
|
2021-10-16 01:28:32 +02:00
|
|
|
#+begin_src sh
|
|
|
|
add-apt-repository ppa:linuxuprising/java
|
|
|
|
apt update
|
|
|
|
apt install oracle-java11-installer
|
|
|
|
apt install oracle-java11-set-default
|
|
|
|
#+end_src
|
|
|
|
|
2020-04-29 06:05:13 +02:00
|
|
|
*** Fedora
|
2021-10-16 01:28:32 +02:00
|
|
|
#+begin_src sh
|
2020-04-29 06:05:13 +02:00
|
|
|
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/
|
2021-10-16 01:28:32 +02:00
|
|
|
#+end_src
|
2020-04-29 06:05:13 +02:00
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
Open =/etc/profile.d/jdk11.sh= as root and add:
|
|
|
|
#+begin_src sh
|
2020-04-29 06:05:13 +02:00
|
|
|
export JAVA_HOME=/usr/local/jdk-11.0.2
|
|
|
|
export PATH=$PATH:$JAVA_HOME/bin
|
2021-10-16 01:28:32 +02:00
|
|
|
#+end_src
|
2020-04-29 06:05:13 +02:00
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
Save the file and source it:
|
|
|
|
#+begin_src sh
|
2020-04-29 06:05:13 +02:00
|
|
|
source /etc/profile.d/jdk11.sh
|
|
|
|
java -version
|
2021-10-16 01:28:32 +02:00
|
|
|
#+end_src
|
2020-04-29 06:05:13 +02:00
|
|
|
|
2020-05-08 10:54:54 +01:00
|
|
|
** Multiple Java Versions
|
|
|
|
It is common to need support for multiple Java versions. You can use a generic
|
|
|
|
tool like [[https://github.com/shyiko/jabba][jabba]] to install and manage multiple Java versions on any OS.
|
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
To have a different version of Java per-project, it is recommended you use
|
2022-09-26 02:19:42 +08:00
|
|
|
[[https://github.com/direnv/direnv][direnv]] and [[doom-module::tools direnv]]; create a =.envrc= in the root of the project pointing
|
2021-10-16 01:28:32 +02:00
|
|
|
to the Java installation:
|
|
|
|
#+begin_src sh
|
2020-05-08 10:54:54 +01:00
|
|
|
PATH_add ~/.jabba/jdk/adopt@1.11.0-3
|
|
|
|
JAVA_HOME=~/.jabba/jdk/adopt@1.11.0-3
|
2021-10-16 01:28:32 +02:00
|
|
|
#+end_src
|
|
|
|
|
2022-09-26 02:19:42 +08:00
|
|
|
And then run ~$ direnv allow .~ in the project directory. The [[doom-module::tools direnv]]
|
2021-10-16 01:28:32 +02:00
|
|
|
module will automatically source this environment before activating LSP servers.
|
|
|
|
|
2022-11-19 10:46:08 +00:00
|
|
|
** Formatter
|
|
|
|
|
|
|
|
[[doom-module::editor format]] uses [[https://github.com/google/google-java-format][google-java-format]] to handle formatting.
|
|
|
|
|
|
|
|
To install, grab the latest =all-deps.jar= release from the above, put it
|
|
|
|
somewhere and create a script similar to the below:
|
|
|
|
|
|
|
|
=/usr/local/bin/google-java-format=
|
|
|
|
#+begin_src shell
|
|
|
|
java -jar /path/to/google-java-format-all-deps.jar
|
|
|
|
#+end_src
|
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
* TODO Usage
|
|
|
|
#+begin_quote
|
|
|
|
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
|
|
|
|
#+end_quote
|
|
|
|
|
2022-09-26 02:19:42 +08:00
|
|
|
** [[doom-module:+lsp]] features
|
2021-10-16 01:28:32 +02:00
|
|
|
According to [[https://github.com/emacs-lsp/lsp-java]], you get:
|
2022-09-26 02:19:42 +08:00
|
|
|
- As you type reporting of parsing and compilation errors (via [[doom-package:flycheck]] or
|
|
|
|
[[doom-package:lsp-ui]])
|
|
|
|
- Code completion ([[doom-package:company-lsp]] or complete-at-point)
|
|
|
|
- Javadoc hovers ([[doom-package:lsp-ui]])
|
|
|
|
- Code actions ([[doom-package:lsp-ui]])
|
|
|
|
- Code outline ([[doom-package:imenu]])
|
|
|
|
- Code navigation ([[doom-package:xref]])
|
|
|
|
- Code lens for references/implementations ([[doom-package:xref]])
|
2021-10-16 01:28:32 +02:00
|
|
|
- Highlights
|
|
|
|
- Code formatting
|
|
|
|
- Maven pom.xml project support
|
|
|
|
- Limited Gradle support
|
2022-09-26 02:19:42 +08:00
|
|
|
- Visual debugger ([[doom-package:dap-mode]])
|
|
|
|
- Test runner ([[doom-package:dap-mode]])
|
|
|
|
- Project explorer integration ([[doom-package:treemacs]])
|
2021-10-16 01:28:32 +02:00
|
|
|
- Integration with [[https://start.spring.io/][Spring Initializr]]
|
2020-04-29 06:05:13 +02:00
|
|
|
|
|
|
|
** =+meghanada= features
|
2021-10-16 01:28:32 +02:00
|
|
|
According to [[https://github.com/mopemope/meghanada-emacs/]], you get:
|
|
|
|
- Auto-update server module
|
|
|
|
- [[https://gradle.org/][Gradle]] and [[http://maven.apache.org/][Maven]] and Eclipse project support
|
|
|
|
- No need build tool's plugin
|
|
|
|
- Run build tool task
|
|
|
|
- Compile your project
|
2022-09-26 02:19:42 +08:00
|
|
|
- Syntax check and analyze java source ([[doom-package:flycheck-meghanada]])
|
2021-10-16 01:28:32 +02:00
|
|
|
- Support =Generic Types=
|
2022-09-26 02:19:42 +08:00
|
|
|
- Code completion with [[doom-package:company-mode]] ([[doom-package:company-meghanada]])
|
2021-10-16 01:28:32 +02:00
|
|
|
- Optimize import and sort
|
|
|
|
- Jump declaration
|
|
|
|
- Run [[http://www.junit.org/][JUnit]] test (include test runner)
|
2022-09-26 02:19:42 +08:00
|
|
|
- Diagnostic reporting with [[doom-package:flycheck]] ([[doom-package:flycheck-meghanada]])
|
|
|
|
- Show symbol's type info with [[doom-package:eldoc]]
|
2021-10-16 01:28:32 +02:00
|
|
|
- Search references
|
|
|
|
- Full-featured text search
|
|
|
|
|
|
|
|
* TODO Configuration
|
|
|
|
#+begin_quote
|
|
|
|
🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
|
|
|
|
#+end_quote
|
|
|
|
|
2022-09-26 02:19:42 +08:00
|
|
|
** [[doom-module:+lsp]]
|
2021-10-16 01:28:32 +02:00
|
|
|
Install the eclipse server by executing ~M-x lsp-install-server~ and selecting
|
2020-05-08 10:54:54 +01:00
|
|
|
=jdtls=. After that any newly opened =java= files should start the LSP server
|
|
|
|
automatically.
|
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
To update the server, perform ~SPC u M-x lsp-install-server~.
|
2020-05-08 10:54:54 +01:00
|
|
|
|
|
|
|
Note that if you change Java version you may need to remove the LSP server and
|
2021-10-16 01:28:32 +02:00
|
|
|
install it again. You can do this with ~M-x +lsp/uninstall-server~ followed by
|
|
|
|
~M-x lsp-install-server~.
|
|
|
|
|
2022-09-26 02:19:42 +08:00
|
|
|
Enable the [[doom-module::tools debugger +lsp]] module to get test runner support.
|
2021-10-16 01:28:32 +02:00
|
|
|
|
|
|
|
* Troubleshooting
|
|
|
|
/There are no known problems with this module./ [[doom-report:][Report one?]]
|
|
|
|
|
|
|
|
* Frequently asked questions
|
|
|
|
/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]]
|
2020-05-08 10:54:54 +01:00
|
|
|
|
2021-10-16 01:28:32 +02:00
|
|
|
* TODO Appendix
|
|
|
|
#+begin_quote
|
|
|
|
🔨 This module has no appendix yet. [[doom-contrib-module:][Write one?]]
|
|
|
|
#+end_quote
|