help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Editing Java (with LSP)


From: Pankaj Jangid
Subject: Re: Editing Java (with LSP)
Date: Thu, 16 Jun 2022 08:59:19 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Alessandro Bertulli
<alessandro.bertulli96@gmail.com> writes:

> Can you please give me your feedback? Does any of you write Java code?
> How is it? Do you have the same problems too? If yes, have you found a
> solution? Do you use LSP? Or some other package?
>

I use eglot+eclipse.jdt.ls. There is a bit of struggle in setting this
up.

Although, eglot tries to download latest eclipse.jdt.ls but it is not
always perfect. There are CLASSPATH issues and all those things which
are typical of Java. And even after full setup I face issues here and
there. Sometimes.

My setup is like this (assuming you have cloned eclipse.jdt.ls
repository inside ~/.emacs.d and built using ‘./mvnw clean package’),

--8<---------------cut here---------------start------------->8---
(unless (package-installed-p 'eglot)
  (package-install 'eglot))
(custom-set-variables
 '(eglot-connect-timeout nil))
(declare-function eglot-ensure "eglot")
(add-hook 'java-mode-hook
                  #'eglot-ensure)                               ; eclipse.jdt.ls


(defun my/add-to-classpath (item)
  "Add ITEM to CLASSPATH."
  
  (let ((class-path (getenv "CLASSPATH")))
    
    (defvar class-path-list (if class-path
                                (split-string class-path ":")))
    (cl-pushnew item class-path-list)
    (setenv "CLASSPATH"
            (mapconcat 'identity class-path-list ":"))))

(when (file-exists-p (expand-file-name "eclipse.jdt.ls" user-emacs-directory))
  (my/add-to-classpath
   (substring
    (shell-command-to-string
     (format
      "find %s -name 'org.eclipse.equinox.launcher_*jar'"
      (expand-file-name
       "eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins"
       user-emacs-directory)))
    0 -1)))
--8<---------------cut here---------------end--------------->8---

Also I use ‘exec-path-from-shell’ package to setup PATHs in GUI Emacs.

~Pankaj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]