lsp-java icon indicating copy to clipboard operation
lsp-java copied to clipboard

avoid recompile and reimport

Open ST-Saint opened this issue 3 years ago • 4 comments

Is it possible to avoid jdtls recompiling the classes? I am now working on a project which only supports java 8. I noticed that when I start the lsp it gonna import dependencies and compile the class files but I don't want it to do so.

Compiling with java 11 would throw the belowing exception and I could not modify the source codes.

Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;

Thus I am wondering whether lsp could just use the precompiled class files?

Thanks.

ST-Saint avatar Nov 22 '21 05:11 ST-Saint

I think that in this case you have to configure jdtls to use different jdk per project - see https://github.com/emacs-lsp/lsp-java/issues/254

yyoncho avatar Nov 22 '21 06:11 yyoncho

@yyoncho

I think that in this case you have to configure jdtls to use different jdk per project - see #254

I try to add this to my config

  (setq lsp-java-configuration-runtimes '[
                                          (:name "JavaSE-11"
                                           :path "/usr/lib/jvm/java-11-openjdk/")
                                          (:name "JavaSE-1.8"
                                           :path "/usr/lib/jvm/java-8-openjdk/"
                                           :default t)
                                          ]))

However, I saw the jdtls was still compiling the project. I am not sure if it compiled the classes correctly(I compile the project in docker with some legacy dependencies which are not in my local working env). I could only know this doesn't work until I meet the identical exception.

Thanks anyways. Maybe I could have a look to the jdtls project and check whether there is such a configurable property.

ST-Saint avatar Nov 22 '21 07:11 ST-Saint

It is not possible to disable jdtls compiling the files, this is how it works...

yyoncho avatar Nov 22 '21 08:11 yyoncho

@ST-Saint I am not sure if (setq lsp-java-autobuild-enabled nil) is what you want.

huangfeiyu avatar Nov 22 '21 10:11 huangfeiyu