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
    path: /opt/eclipse
  register: e

- name: eclipse directory exists
    state: directory
    path: /opt/eclipse

- name: eclipse downloaded
    dest: /opt/eclipse/
    remote_src: True
  when: e.stat.exists is defined and not e.stat.exists

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

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

- name: eclim downloaded
    dest: /tmp/eclim.jar
  when: e.stat.isfile is defined and not e.stat.isfile

- name: eclim downloaded
  become: yes
  become_user: "{{local_account}}"
  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)

(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")
- name: java 8 installed
    name: java-1.8.0-openjdk
    state: installed
  when: ansible_pkg_mgr == "dnf"

- name: java 8 installed
    name: openjdk-8-jdk
    state: installed
  when: ansible_pkg_mgr == "apt"

Emacs-side Integration, Java-mode

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

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


Author: Ryan Rix

Created: 2019-04-23 Tue 16:51

Validate XHTML 1.0