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 2022-04-22
Java(TM) SE Runtime Environment (build
Java HotSpot(TM) 64-Bit Server VM (build, mixed mode, sharing)
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 jdt-language-server-1.9.0-202203031534.tar.gz package was downloaded from that milestone builds page and the contents 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>          bin
04/09/2018  06:50 PM    <DIR>          config_linux
04/09/2018  06:50 PM    <DIR>          config_mac
04/09/2018  06:50 PM    <DIR>          config_ss_linux
04/09/2018  06:50 PM    <DIR>          config_ss_mac
04/09/2018  07:26 PM    <DIR>          config_ss_win
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_cache
set CacheDirctory=%~2

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


set CacheDirctory="%CacheDirctory%"

if EXIST %CacheDirctory% goto check_server
echo Error: The cache directory provided does not exist: %CacheDirctory%
goto complete


:: 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.6.400.v20210924-0641.jar

if EXIST %JarFile% goto run_server
echo Error: The following Jar file was not found:
echo            '%JarFile%'
echo Check the folder above to see if the version number of the Jar has changed and update the jLSP.cmd file to suit.
goto complete


:: 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.

For more details refer to the 'adjust to suit' and 'update based on version file of jar' comments found in the batch file.


Start Zeus and use the Options, Document Types menu to edit the Java document type and in the Language Server panel apply the following configuration settings:
Program Type: Batch
     Program: C:\Java\jLSP.cmd
   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.99b
Released: 29th January 2024