Java LSP Configuration

The details below describe how to install and configure the Eclipse JDT LS language server found here.

Java Runtime

For this language server to work the machine must have a version of the Java runtime installed and correctly configured.
To check for the Java runtime open a command prompt and run the java --version command, which should result in output similar to the following:
java 10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
If that output is not produced check to make sure the Java runtime is installed and the installation folder is located in the system PATH environment variable.
If runtime is not installed download and install the Java SE Runtime Environment found here.

Installing the Eclipse JDT Language Server

The Eclipse JDT LS page contains details on how to build the language server from source and also contains a link to the milestone builds page where pre-built version of the language server can be downloaded.
In this example the latest version of the language server was downloaded from the milestone builds page and the zip file extracted to the folder C:\Java\ location as shown below:
 Directory of C:\Java\jdt-language-server

04/09/2018  07:26 PM    <DIR>          .
04/09/2018  07:26 PM    <DIR>          ..
04/09/2018  06:50 PM    <DIR>          config_linux
04/09/2018  06:50 PM    <DIR>          config_mac
04/09/2018  07:26 PM    <DIR>          config_win
04/09/2018  06:50 PM    <DIR>          features
04/09/2018  06:50 PM    <DIR>          plugins
NOTE: For the language server to work correctly the installed folder needs to be writable and fully accessible.

Server Batch File

The language server is run using the Java runtime environment by passing in a large number of command line arguments. Because of this large argument count a batch file is required to run the server.
Save the following batch details to the C:\Java\jLSP.cmd batch file:
@echo off

set CacheDirctory=%~1

if NOT "%CacheDirctory%" == "" goto test_data
set CacheDirctory=%~2

if NOT "%CacheDirctory%" == "" goto test_data
echo Error: No cache directory was provided.
goto usage


if EXIST %CacheDirctory% goto run_server
echo Error: The cache directory provided does not exist: '%CacheDirctory%'
goto usage


:: language server installation folder (adjust to suit)
set Directory=C:/Java/jdt-language-server

:: language server jar file (update based on version file of jar)
set JarFile=%Directory%/plugins/org.eclipse.equinox.launcher_1.5.100.v20180827-1352.jar

:: language server config folder location
set Config=%Directory%/config_win

echo Directory: %Directory%
echo   JarFile: %JarFile%
echo    Config: %Config%

:: java
::      -Dosgi.bundles.defaultStartLevel=4
::      -Dlog.level=ALL
::      -noverify
::      -Xmx1G
::      -jar %JarFile%
::      -configuration %Congfig%
::      --add-modules=ALL-SYSTEM
::      --add-opens java.base/java.util=ALL-UNNAMED
::      --add-opens java.base/java.lang=ALL-UNNAMED
::      -data %CacheDirctory%

:: echo the command for debugging
echo java -Dosgi.bundles.defaultStartLevel=4 -Dlog.level=ALL -noverify -Xmx1G -jar %JarFile% -configuration %Config% --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -data %CacheDirctory%

:: run the language server using stdio communications
java -Dosgi.bundles.defaultStartLevel=4 -Dlog.level=ALL -noverify -Xmx1G -jar %JarFile% -configuration %Config% --add-modules=ALL-SYSTEM --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED -data %CacheDirctory%
goto complete

echo   Usage: jLSP.cmd WorkspaceDirectory FileDirectory
echo Example: jLSP.cmd "$wdd" "$fdd"

NOTE: The details found in this batch file may need to be adjusted to suit the local machine. For example the location of the language server, the version number of the language server or the folder location used for data cache may all need to be adjusted.


Edit the Java document type and in the Language Server configuration panel apply the following configuration settings:
Program Type: Batch
     Program: jLSP.cmd
   Directory: C:\Java\
   Arguments: "$wdd"
NOTE: The "$wdd" and "$fdd" are two arguments passed ot the batch file and represent the current workspace directory and the directory of the current file. The batch file uses these two details to define the location of the language server cache folder.

Using the Language Server

To test the configuration, create a simple file and fire off an auto-complete request:
lsp Java

Latest Version: Zeus 3.98y
Released: 11th March 2021