spacemacs/layers/+lang/java
2019-09-30 00:34:26 -04:00
..
img Use + instead of ! for layer categories 2015-09-11 00:13:51 -04:00
config.el [java] Fix various issue introduced by dropping ensime support 2019-09-18 22:00:05 +02:00
funcs.el [java] Fix various issue introduced by dropping ensime support 2019-09-18 22:00:05 +02:00
layers.el Make layers request lsp dependency if lsp has been selected as backend 2019-09-10 22:00:56 +02:00
packages.el [java] Remove unconfigured eldoc package 2019-09-30 00:34:26 -04:00
README.org [java] Make lsp the default backend and drop eclim support 2019-09-18 21:21:55 +02:00

Java layer

/TakeV/spacemacs/media/commit/6f6497d3c901611e293c612d3e5631cd3216b256/layers/+lang/java/img/java.png

Description

This layer adds support for the Java language.

Features:

  • Support for the following backends:

  • Each provides:

    • Auto-completion using company
    • Linting using flycheck integration
    • Maven and Gradle integration
  • LSP also provides:

    • Full graphical debugging support via DAP mode

Layer Installation

Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add java to the existing dotspacemacs-configuration-layers list in this file.

Choosing a backend

To choose a default backend set the layer variable java-backend:

  (java :variables java-backend 'lsp)

Backend can be chosen on a per project basis using directory local variables (files named .dir-locals.el at the root of a project), an example to use the lsp backend:

  ;;; Directory Local Variables
  ;;; For more information see (info "(emacs) Directory Variables")

  ((java-mode (java-backend . lsp)))

Note: you can easily add a directory local variable with SPC f v d.

Backends

LSP Java

LSP Java is the Java adapter for LSP Mode which is the Emacs client for Language Server Protocol.

It integrates with company and flycheck. In addition it also provides full graphical debugging support via DAP mode.

LSP is the default backend used by this layer, see Choosing a backend in order to lean how to select a different backend.

Installation

The lsp server will be installed automatically whenever a Java file is opened.

Meghanada

Meghanada is composed of a lightweight server and an Emacs minor mode. It is unintrusive and integrates with company and flycheck.

Both Gradle and Maven projects are compatible with Meghanada.

Installation

The Meghanada server will be installed automatically whenever a Java file is opened.

If you get issues with the auto-installation you can either download the last version of the server manually there or build from source hosted on the GitHub repository and copy the jar file to .emacs.d/.cache/meghanada folder.

No additional configuration is necessary!

About Maven

Maven is not fully supported by Meghanada (but should still work fine for most projects). If you encounter disconnection from the server then run mvn install at the root of your project first.

Key bindings

LSP Java

Code completion

Key binding Description
SPC m g g Go to definition
SPC m g r Find references
SPC m g R Peek references using lsp-ui
SPC m g d Goto type definition
SPC m g a Search type in project
SPC m g A Search type in project using lsp-ui
SPC m h h Describe thing at point
SPC m e l List project errors/warnings
SPC m p u Refresh user settings
SPC m e a Execute code action
SPC m q r Restart workspace
SPC m r o i Organize imports
SPC m r r Rename symbol
SPC m r a i Add import
SPC m r a m Add unimplemented methods
SPC m r c p Create parameter
SPC m r c f Create field
SPC m r e c Extract constant
SPC m r e l Extract local
SPC m r e m Extract method
SPC m r c i Convert to static import
SPC m r a t Add throws exception
SPC m r a a Assign all parameters to fields
SPC m r a f Assign parameter to field
SPC m r g g Generate getters/setters
SPC m r g e Generate equals and hashCode methods
SPC m r g t Generate toString method
SPC m r g o Generate method overrides
SPC m c c Build project
SPC m c p Create spring boot project
SPC m a n Actionable notifications
SPC m = Format code

Debugger

Key binding Description
SPC m d t t Debug test method
SPC m d t c Debug test class
SPC m d j Debug java class(main method).
SPC m t t Run test method
SPC m t c Run test class
SPC m d d d start debugging
SPC m d d l debug last configuration
SPC m d d r debug recent configuration
SPC m d c continue
SPC m d i step in
SPC m d o step out
SPC m d s next step
SPC m d v inspect value at point
SPC m d r restart frame
SPC m d . debug transient state
SPC m d a abandon current session
SPC m d A abandon all process
SPC m d e e eval
SPC m d e r eval region
SPC m d e t eval value at point
SPC m d S s switch session
SPC m d S t switch thread
SPC m d S f switch frame
SPC m d I i inspect
SPC m d I r inspect region
SPC m d I t inspect value at point
SPC m d b b toggle a breakpoint
SPC m d b c change breakpoint condition
SPC m d b l change breakpoint log condition
SPC m d b h change breakpoint hit count
SPC m d b a add a breakpoint
SPC m d b d delete a breakpoint
SPC m d b D clear all breakpoints
SPC m d '_ Run debug REPL
SPC m d w l list local variables
SPC m d w o goto output buffer if present
SPC m d w s list sessions
SPC m d w b list breakpoints

Meghanada

Server

Key binding Description
SPC m D c Connect to server
SPC m D d Disconnect from server
SPC m D i Install server (should be done automatically
SPC m D k Kill server
SPC m D l Clear server cache
SPC m D p Ping server
SPC m D r Restart server
SPC m D s Start server
SPC m D u Update server
SPC m D v Print version of the server

Navigation

Key binding Description
SPC m g b Jump back to previous location
SPC m g g Jump to declaration

Compilation

Key binding Description
SPC m c b Compile file (buffer)
SPC m c c Compile project

Tests (junit)

Key binding Description
SPC m t a Run all tests
SPC m t c Run test class around point
SPC m t l Run last tests
SPC m t t Run test cause around point

Refactoring

Key binding Description
SPC m = Beautify code
SPC m r i Optimize imports
SPC m r I Import all
SPC m r n Create a new class, interface, or enum

Tasks

Key binding Description
SPC m x : Run task

Maven

Key binding Description
SPC m m c c Compile
SPC m m c C Clean
SPC m m c r Clean and compile
SPC m m g a Switch between class and test file
SPC m m g A Switch between class and test file in another window
SPC m m t a Run all tests
SPC m m t C-a Clean and run all tests
SPC m m t b Run current buffer tests
SPC m m t i Test and install
SPC m m t t Run a specific test

Gradle

Key binding Description
SPC m l c c Compile
SPC m l c C Clean
SPC m l c r Clean and compile
SPC m l t a Run all tests
SPC m l t b Run current buffer tests
SPC m l t t Run a specific test
SPC m l x Execute a Gradle task