When using lsp-java with a 3 file project and one external jar, I am not using gradle or maven. I put the jar into a lib directory, open a Java file and everything works. Then I follow find-definitions and "only" see de-compiled code, not the source. Of course, I need to add a source jar. But how?

I experimented with putting a source jar into the lib directory and, like magic, the file ~/.emacs.d/workspace/project_hex/.classpath shows the source jar attached to the library jar and it works.

Now the questions which I couldn't so far answer, even without some digging through the lsp code:

  1. Which piece of software actually generates the directories in ~/.emacs.d/workspace/, is it the java language server or is it lsp-java in some way not easily found in the sources?

  2. While magic is nice, I wonder if there are configuration options which let me configure the .classpath manually? I found lsp-java-import-generates-metadata-files-at-project-root and lsp-java-configuration-update-build-configuration which seem to be related, but could not figure out what they are doing.

Why am I not using gradle? Curiosity to figure out how things work.

  • One question per post, please. Post separate questions separately. Thx.
    – Drew
    Commented Feb 18 at 15:48

1 Answer 1


Which piece of software actually generates the directories in ~/.emacs.d/workspace/,

This is the language server. The file workspace/.metadata/.log contains lines like

!MESSAGE Finished creating the Java project foo
!MESSAGE Successfully created a workspace invisible project foo

I wonder if there are configuration options which let me configure the .classpath manually

This does not seem to be possible, as can be seen from the language server source code. The file org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ProjectUtils.java contains

  private static final String JAR_SUFFIX = ".jar";
  private static final String SOURCE_JAR_SUFFIX = "-sources.jar";

and org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectBuildSupport.java has

  public static final String LIB_FOLDER = "lib";

So this looks like what happens for a non-gradle, non-maven project as far as a quick look through the code reveals. The server

  • picks up source files by searching for .java files, looks at their package definitions and derives source roots from it
  • looks into ./lib for files ending in .jar and -sources.jar to add them as libraries or sources of the libraries.

The latter looks like being customizable by lsp-java-project-referenced-libraries, though I did not try this yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.