9.5.4 Installing the JDEE
Five basic steps are required to install the JDEE on your system:
1. Get the necessary prerequisites downloaded and installed.
2. Update the load path ( .emacs ).
3. Set theJDEE to load at startup ( .emacs ).
4. Compile JDEE .el files (optional).
5. Register your JDKs (optional).
The previous section covered the first step. Make sure you take care of those prerequisites before continuing. The next steps can be handled in your .emacs file. The JDEE site proposes the following entries as a minimal setup; we excerpt them here (with one or two small tweaks) for easy reference.
;; This .emacs file illustrates the minimal setup
;; required to run the JDEE.
;; Set the debug option to enable a backtrace when a
;; problem occurs.
(setq debug-on-error t)
;; Update the Emacs load-path to include the path to
;; the JDEE and its require packages. This code assumes
;; that you have installed the packages in the
;; /usr/local/emacs/site-lisp directory. Adjust appropriately.
(add-to-list 'load-path
(expand-file-name "/usr/local/emacs/site-lisp/jde/lisp"))
(add-to-list 'load-path
(expand-file-name "/usr/local/emacs/site-lisp/semantic"))
(add-to-list 'load-path
(expand-file-name "/usr/local/emacs/site-lisp/speedbar"))
(add-to-list 'load-path
(expand-file-name "/usr/local/emacs/site-lisp/eieio"))
(add-to-list 'load-path
(expand-file-name "/usr/local/emacs/site-lisp/elib"))
;; If you want Emacs to defer loading the JDEE until you open a
;; Java file, edit the following line
(setq defer-loading-jde nil)
;;
to read:
;;
;; (setq defer-loading-jde t)
;;
(if defer-loading-jde
(progn
(autoload 'jde-mode "jde" "JDE mode." t)
(setq auto-mode-alist
(append
'(("\\.java\\'" . jde-mode))
auto-mode-alist)))
(require 'jde))
;; Set the basic indentation for Java source files
;; to two spaces.
(add-hook 'jde-mode-hook
'(lambda ( )
(setq c-basic-offset 2)))
;; Include the following only if you want to run
;; bash as your shell.
;; Set up Emacs to run bash as its primary shell.
(setq shell-file-name "bash")
(setq shell-command-switch "-c")
(setq explicit-shell-file-name shell-file-name)
(setenv "SHELL" shell-file-name)
(setq explicit-sh-args '("-login" "-i"))
(if (boundp 'w32-quote-process-args)
(setq w32-quote-process-args ?\")) ;; Include only for MS Windows.
Of course, you'll need to make sure the paths in the add-to-list 'load-path
lines match the actual directories you're using.
Compiling the JDEE Lisp files is not required, but as noted in "Byte-Compiling Lisp Files" in Chapter 11, it's a good idea and speeds up several operations including general startup times. The JDEE makes this step simple. After you have it installed, start Emacs and run M-x jde-compile-jde. You run this command only once, so it is definitely worthwhile.
9.5.5 Registering Your Java Tools
The last step we need to cover is registering your Java development kits. This is not strictly necessary, but you don't want to skip this step. It is especially handy if you work in an environment where you have to test multiple versions of the JDK. With all of your kits registered in the JDEE, you can switch between versions with a simple variable change.
To register a JDK, use the M-x customize-variablecommand. The variable you need to customize is jde-jdk-registry. That will land you in the interactive customization screen. You can select the INS(insert) button to add the version number and path of your JDK. You can repeat that process for as many JDKs as you want to register. See Figure 9-2for a list of such entries on a Mac OS X system.
Figure 9-2. Inserting JDK entries in a Custom list
Be sure to hit the State button and save this state for future sessions. You can click the Finish button when you're done or just close the buffer.
After you have your JDKs registered, you can switch to the active version using that same M-x customize-variablecommand. This time, edit the jde-jdkvariable. You'll be prompted to choose one of the registered versions. You may or may not want to save this decision for future sessions. In any case, this variable can be edited at any time.
9.5.5.1 JDK tools.jar problems
The compilation feature requires access to the tools.jar file (or the equivalents built-in to some JDKs). If the JDEE compile command fails with an error message about not being able to find the tools.jar file, your best bet is to customize the JDEE variable jde-global-classpath. Make sure that variable includes the tools.jar file.
For some systems that do not have a tools.jar file [66], you can steal that file from another machine, but usually you just need to get your classpath and registry entries set up correctly. Customizing the variables in Table 9-6should get you compiling and running without too much effort.
Table 9-6. JDEE variables to customize
JDEE variable |
Sample values |
jde-global-classpath |
/usr/local/j2se:. |
jde-jdk-registry |
Version = 1.4.2 |
Path = /usr/local/j2se |
Whew! That was a lot of work. But the good news is that once you've made it through the installation process, you have all the spiffy features of the JDEE forever at your command. So let's get on with the features!
9.5.6 Editing with the JDEE
First off, you're still in Emacs, so the usual motion commands described for Java mode (and C mode) still apply. But the JDEE adds two really great features to your editing cycle: command completion and class browsing.
The idea behind command completion is that the JDEE can (usually) predict which methods and variables are valid choices to make at certain points in your Java program. For example, if you start typing System. in your program, there are a finite number of choices for what follows that period. JDEE can display a list of those choices.
The command to show your list of completions is C-c C-v C-. (for jde-complete), which defaults to showing you a menu of completions. (You can change that behavior by customizing the jde-complete-functionvariable.) The completions are generated by looking at all of the classes listed in the jde-global-classpathvariable (or the CLASSPATH environment variable if no global classpath was defined).
The class browser can be accessed quickly from the JDE menu and launches a BeanShell browser for the class your cursor was on. It's like a context-sensitive documentation tool, but a bit more powerful. Figure 9-3shows what you get when starting the browser while your cursor is on the word System .
Читать дальше