Complete Computing Environment: Java Programming in Emacs

Table of Contents

(provide 'cce-java)

Eclim, the brain of the integration

Java development is generally done in an IDE, mostly because of the verbose design patterns requiring a really good autocomplete system, jump-to-definition, auto-building, inline debugging, and other fairly heavy systems that are tightly integrated in to the Java ecosystem.

The hack here, famously done for Vim users wanting to use a full Vim experience for Java development, is Eclim1, a plugin for Eclipse to expose Eclipse's view of a project and a daemon that runs a headless Eclipse with that plugin enabled.

I tried to get it to work with Fedora's Eclipse but of course was getting some opaque error message about something going wrong, so I opt to just install Eclipse to /opt

# Most of these can be done by root since they get chown'd
- name: check eclipse is installed
  stat:
    path: /opt/eclipse
  register: e

- name: eclipse downloaded
  unarchive:
    src: http://mirror.cc.columbia.edu/pub/software/eclipse/technology/epp/downloads/release/neon/3/eclipse-java-neon-3-linux-gtk-x86_64.tar.gz
    dest: /opt/eclipse/
    remote_src: True
  when: e.stat.isdir is defined and not e.stat.isdir

- name: eclipse owned by rrix
  shell: chown -cR  rrix.rrix /opt/eclipse
  register: chown
  changed_when: "chown.stdout != \"\""

- name: check eclim is installed
  stat:
    path: /opt/eclipse/eclim
  register: e

- name: eclim downloaded
  get_url:
    url: https://github.com/ervandew/eclim/releases/download/2.6.0/eclim_2.6.0.jar
    dest: /tmp/eclim.jar
  when: e.stat.isfile is defined and not e.stat.isfile

- name: eclim downloaded
  become: yes
  become_user: rrix
  shell: java -jar -Dvim.skip=true -Declipse.home=/opt/eclipse/ /tmp/eclim.jar install
  when: e.stat.isfile is defined and not e.stat.isfile
(install-pkgs '(eclim))

(add-hook 'java-mode-hook (lambda ()
                            (require 'eclim)
                            (eclim-mode)))

(setq eclimd-executable "/opt/eclipse/plugins/org.eclim_2.6.0/bin/eclimd"
      eclim-executable "/opt/eclipse/plugins/org.eclim_2.6.0/bin/eclim")

Emacs-side Integration, Java-mode

(defun cce/java-test ()
  (interactive)
  (eclim-maven-run "test"))

(define-key java-mode-map (kbd "C-c C-c") #'cce/java-test)

Footnotes:

Author: Ryan Rix

Created: 2017-10-03 Tue 10:06

Validate XHTML 1.0