I have added the junit jar file in my ${CLASSPATH} environment variable, but when I use the lsp for neovim it doesn't recognize the functions and imports from the JAR file.
import static org.junit.Assert.assertEquals; ■ The import org.junit cannot be resolved
1 import static org.junit.Assert.assertTrue; ■ The import org.junit cannot be resolved
2 import static org.junit.Assert.fail; ■ The import org.junit cannot be resolved
3
4 import java.util.Comparator;
5 import java.util.Arrays;
6 import java.util.List;
7 import java.util.ArrayList;
8
9 import org.junit.Test; ■ The import org.junit cannot be resolved
10 import org.junit.Before; ■ The import org.junit cannot be resolved
Does anyone know a way to add the ${CLASSPATH} to the imports and "stuff" that jdtls recognizes?
One has to specify the correct plugin to initialize the (Eclipse)language server within the JDK. We can do this by creating a shell script that is called by your nvim LSP plugin/config.
First you have to locate the equinox_launcher jar file, which is located in the eclipse/jdt-language-server/plugin folder and add it to your script.
Linux shell script should look something like this:
Win batch script should look something like this:
After the agentlib line, you can add the modules you need. For further conveniences, the java_lsp.sh or java_lsp.bat can be included in a environment path.
The jdtls target directories can vary if you build from source, or (recommended) use a Milestone build.
https://download.eclipse.org/jdtls/milestones/
For more detailed information you can check out:
Neovim built in LSP documentation:
Guide + documentation regarding JDTLS:
Guide + Examples Regarding JDTLS client plugin for nvim written in lua: