Up and Running with JDE
In my copious spare time since I last posted, I’ve managed to get JDE set up and usable. JDE is pretty complex- it essentially turns Emacs into a full Java IDE- so I’m just going to outline the details of how to quickly get set up and exploring the environment. Check the User Guide for the full story.
These procedures were tested on Emacs 22 running on Ubuntu Linux. The next step is to all this set up on the Windows laptop I use at my job.
Installation
Artur Hefczyc has created a shell script that downloads and sets up JDE and all it’s dependencies. If you want it to install the libraries somewhere other than your system default site-lisp directory, define it as a global variable when you run the script.
SITE_LISP_DIR=/.emacs.d/site-lisp/ ./install-jde.sh
I discovered that putting these newly created directories under version control with subversion will break them- you’ll get an error along the lines of “jde-.svn.el does not exist”. In order to keep my emacs environment as mobile as I can, I simply zipped up the libraries and put the zip files under version control instead. Yes, I have to go through the extra step of unzipping the archive in any new environment, but given that these files probably won’t change that much, it’s not a huge disadvantage.
Next, drop the following in your .emacs (assuming you installed the JDE libraries in ~/.emacs.d/site-lisp/):
(load-file “~/.emacs.d/site-lisp/cedet/common/cedet.el”)
(add-to-list ‘load-path “~/.emacs.d/site-lisp/jde/lisp”)
(require ‘jde)
Project Setup
To get the Eclipse-like features of JDE working, you need to setup a project file. Drop a file named prj.el somewhere in the directory tree of the project you’re working on, and JDE will automatically load it when you open a Java file associated with the project. At minimum, you need something like the following:
(jde-project-file-version “1.0″)
(jde-set-variables
‘(jde-sourcepath ‘(”./path/to/source”))
‘(jde-global-classpath (”./relative/entry/on/classpath/”
“./another/relative/entry/on/classpath/”
)))
On the sample project I was testing all this upon, I had all my compiled classes set up in build/classes and a bunch of jars I needed linked in lib. I avoided listing each jar independently by using the directory-files function to expand out a list of all files matching /.*jar$/ in the lib directory.
(jde-set-variables
‘(jde-global-classpath (cons
(expand-file-name “~/magic-project/build/classes/”)
(directory-files “~/magic-project/lib” t “.*jar$”))
))
Unfortunately, I haven’t been able to get this working using relative paths yet.
Nifty Things
So, what about those neat IDE-ish things that were the whole point of this exercise? There’s a metric ton of useful stuff in JDE, but here’s how get to equivalents to the killer features in Eclipse:
- jde-complete: Expands the expression where your cursor lies. If there’s a single completion, it’ll get filled in. Otherwise, you’ll get a menu with all the possible completions. It’s very much like hitting Control-Space in Eclipse.
- jde-open-class-at-point: Jumps to the definition of whatever symbol- class, variable, whatever- that the cursor is on. Note that you have to set jde-sourcepath in prj.el for this work.
- jde-ant-build: Ant build script integration. It’s a simple as (jde-ant-build â€path/to/build.xml†“target-nameâ€)
The default keybindings for most of the jde functions seem to have been created by classical guitarists hell-bent on avoiding conflicts (C-c C-v C-. is mapped to jde-complete, for example). You probably want to rebind them using global-set-key calls in your .emacs.
Posted: June 1st, 2007 under Emacs, Programming.
Comments: 5
Comments
Comment from Nick
Time: June 2, 2007, 3:33 am
Nice Overview…gonna have to hack that into my emacs this weekend… :D
Comment from Matt
Time: November 26, 2007, 2:56 pm
I was keeping my jde setup under svn too – and having the same problem. However, I recently switched to git which keeps only a top-level .git dir, not a .svn dir in each subdirectory. Now jde doesn’t give the “jde-.svn.el does not exist” error.
Here’s my jde setup code from .emacs. I find it useful to autoload the jde-mode function instead of require-ing it — emacs startup time is faster.
(setq semantic-load-turn-useful-things-on t)
(setq semanticdb-default-save-directory “~/.semantic.cache”)
(setq semanticdb-persistent-path nil)
(load-file “~/elisp/cedet-1.0pre3/common/cedet.el”)
(add-to-list ‘load-path “~/local/share/emacs/site-lisp/elib”)
(add-to-list ‘load-path “~/elisp/ecb-2.32″)
(add-to-list ‘load-path “~/elisp/jde-2.3.5.1/lisp”)
(if t ;; t => defer loading jde
(progn
(autoload ‘jde-mode “jde” “JDE mode.” t)
(setq auto-mode-alist
(append
‘((”\\.java\\’” . jde-mode))
auto-mode-alist)))
(require ‘jde))
(defun my-jde-mode-hook ()
(global-set-key [f5] ‘jde-compile)
(require ‘ecb))
(add-hook ‘jde-mode-hook ‘my-jde-mode-hook)
(add-hook ‘java-mode-hook ‘(lambda () (setq c-basic-offset 4)))
Thanks for a nice article.
-Matt
Comment from mlb
Time: February 13, 2009, 10:22 am
You can get rid of the svn problem by telling jde not to ignore certain directories in jde-plugins.el
— jde-plugins.el 2009-02-13 11:11:59.000000000 +0100
+++ jde-plugins.el 2009-02-13 11:11:17.000000000 +0100
@@ -100,7 +100,7 @@
(not (string= file-name “CVS”))
(not (string= file-name “RCS”)))
file-name)))
- (directory-files jde-plugins-directory t)))))
+ (directory-files jde-plugins-directory t “^[^\\.]” nil)))))
(loop for plugin in plugins do
(jde-pi-load-plugin plugin)))))
Comment from mlb
Time: February 13, 2009, 10:23 am
I meant “to ignore” not “not to ignore” :).
Comment from achim
Time: November 7, 2009, 10:58 pm
You wrote: “Unfortunately, I haven’t been able to get this working using relative paths yet.”
I had the same problem and found the solution yesterday:
Q: How to find the current executing program’s name?
A: (or load-file-name buffer-file-name)
Write a comment