Reprint: EMACS-JDE Development environment settings

Source: Internet
Author: User

Using Emacs-jde for Java development

(Hacking Java with Emacs-jde)

Java development Friends are generally using some kind of IDE to develop, more commonly used are JBuilder, Visual cafe,visual age. Using IDE development is a good way for beginners. But for those familiar with the Linux/unix development habits, the disadvantages and limitations of using such an IDE for development are obvious, first of all, you have to understand the different uses of each IDE and have to accept the code that the various wizard imposes on you. This code, especially after it has been altered, is often ugly and confusing. (I often get sick of the ugly code produced by JBuilder). Second, these Ides are generally more or less using proprietary tools or libraries, and the portability of software is hidden. Finally, the most unacceptable thing to me is that on my machine (PIII500,128M,NT4), the speed of jbuilder is simply not satisfying (perhaps other Ides are better).

Using Emacs (This article using Emacs to represent GNU Emacs or XEmacs) is obviously a good choice, with its efficiency, high degree of configuration, and extremely powerful features enough for anyone to put it down, I am a standard hardcore-xemacs-fan. Due to some characteristics of Java features, using a pure editor such as Emacs for Java Development also has its inconvenient, for larger projects, the source files are often distributed in a wide range of directories (/com/foo/bar/... , if you use Emacs for development, it's a big inconvenience to have to frequently knock in lengthy directory names. Second, in Java compile and run debugging, we need to pass some parameters to the compiler, the virtual machine, of course, can be implemented using makefile, but these parameters are mostly not complex, the use of make such a powerful tool is a bit expensive. Also, for some frequently used functions or statements such as (System.out. println,implements) Each use of their own knocking is obviously too cumbersome. Finally, for an OO language, it is convenient to have a class browser.

Now, using JDE can basically overcome all of these drawbacks, combining the IDE's functionality with the benefits of Emacs perfectly. JDE is an IDE software package written using Emacs-lisp, the main part of which is the development of Paul Kinnucan, which basically implements the functionality provided by most commercial IDE systems after installing JDE in Emacs. The main features are:

    • Syntax highlighting and indenting for Java.
    • Automatic completion of keywords and class methods (Sourceinsight, not very mature yet).
    • Compile error targeting.
    • Automatic frame code generation (LISTENER,PRINTLN, etc.)
    • Project files (compile and run debug parameters)
    • Tree-like and file browser display
    • Integrated Help (Javadoc) and debug Functions (Jdb+gud)
    • In addition to these features, JDE certainly has all the excellent features of Emacs, such as portability (almost everything OS), configurable (almost unlimited, Hacker's life,:-)). The installation and use of JDE will be described in detail below.
Installation

Since JDE is a Emacs-lisp language pack, its installation is very convenient and, of course, requires the basic knowledge of Emacs configuration. First, it needs to meet its installation requirements,

  1. Emacs,gnu Emacs or XEmacs 19 version above, hardware and software platform Unlimited.
  2. Verify that you have installed some of the Emacs-lisp packages (package) required for JDE, Speedbar (class browser), semantic (parsing), Eieio (OO lisp), Elib (Emacs lisp Utilities), and Some features require BeanShell (what is beanshell?www.beanshell.org), run under XEmacs need to install Fsf-compat package
  3. To unpack the JDE package to a directory, modify your. Emacs configuration file to add the following content:
        ;; Set the debug option to enable a backtrace when a;;     Problem occurs. ;; When there is a problem appear error message, easy to debug (setq debug-on-error t);; Update the Emacs Load-path to include the path to;; The JDE and its require packages. This code assumes;; That's installed the packages in the Emacs/site;     subdirectory of your home directory. ;; Load the required package (Add-to-list ' Load-path (expand-file-name "~/emacs/semantic-1.3.3")) (Add-to-list ' Load-path (expand- File-name "~/emacs/speedbar-0.13")) (Add-to-list ' Load-path (expand-file-name "~/emacs/eieio-0.16")) (add-to-list ' Load-path (expand-file-name "~/emacs/jde/lisp")) (Add-to-list ' Load-path (expand-file-name "~/emacs/elib-1.0")); ; If you want Emacs to defer loading the JDE until you open a;; Java file, edit the following line;; does not automatically load Jde-mode (setq defer-loading-jde t);;     to read:;;  ;;     (setq defer-loading-jde t);; ;;   When you edit a. java file, load JDE (if Defer-loading-jde     (Progn (autoload ' Jde-mode "JDE" "JDE Mode" T) (setq auto-mode-alist (append (("\\.java\\ '". Jde-mode))))) (Require ' JDE))

If the installation is correct, using Emacs to open the Java file will automatically enter Jde-mode, the process may take a few seconds, because JDE will call semantic to parse the entire file.

Using JDE

After entering the Jde-mode, we can naturally find some differences with ordinary java-mode, first of all, the syntax highlighting is more "Java", at a glance. XEmacs at the top of the menu also has some changes three menu items, "JDE", "Classes", "Senator", JDE menu includes all the features JDE provides, the following will be described in detail, "Classes" is the JDE of Java files generated after parsing , including all the classes, variables, and methods in the current file, which can be accessed by selecting the menu to access the appropriate code. While the Senator menu is generated by the semantic package, the source file can be searched and positioned by token. Let's take a look at what features Emacs-lisp offers us:

Javadoc Support: Javadoc is a document generation tool provided by the JDK, and the source code is annotated by following certain specifications, Javadoc can generate Java-style documents for the entire program. In JDE, we only need to position the cursor at the beginning of a method, press C-c c-v J,jde will automatically generate Javadoc frame comments, after the corresponding section to write a description, you can use the Javadoc tool to generate Java-style documents.

Automatic completion: The variable Jde-enable-abbrev-mode variable is set to T,jde can realize the function of automatic completion, to avoid our manual input cumbersome and error-prone, complement the main there are three types, the first key word completion, that can automatically complement the entire Java language keyword, such as we typed " Impl ", JDE will automatically complete become implements (a I often misspelled keyword). Other as abstract can use" AB "to complement, of course, this is only emacs-lisp tricks, but it is important that You can define the key words by modifying the variable jde-mode-abbrevations variables, how to complement them (this is too convenient!).

The following describes the control flow structure of the completion, that is, if-else, such as the completion of the structure, you can avoid the structure of the control structure after the error, but I realize as long as you have good programming habits, this thing is not too big. More useful is the variable name of the completion, such as we have defined in a Java file name of a long variable, called "Variablenametoolong", in the later need to reference, we do not have to remember the name of the variable, after entering the first few letters, press the m-/key, JDE will automatically fill in the corresponding variable name, if there are multiple choices, press m-/multiple times to find what you need. Sourceinsight-type global method complement function is now JDE through BeanShell implementation, is not mature enough.

Code framework: JDE can automatically generate specific classes and code snippets of the framework code, do not require users to repeat the input, currently supported by:

Import is automatically generated, that is, do not need to know what the class is in what package, after typing its name and pressing C-C c-v C-Z,JDE will automatically call BeanShell find the appropriate package and automatically add Import;method reload automatically generated, That is, the framework of overloaded functions can be generated automatically based on the classes currently inherited;

Interface Auto-generated, according to the implements interface, automatically generate the required overloaded functions (too convenient, do not need to implement the document one by one); According to the template to generate a particular type of class framework, there are currently windowlistener, Actionlistener,get/set and so on. These templates can be modified according to their own needs, great!

Project files: All compile, run parameters are stored once, set good Classpath,sourcepath, MainClass ... After that we can press C-c c-v c-c to compile the current file in buffer of either file, press C-c c-v C-r to run the project automatically, or press C-c c-v c-d to Debug.

Integration help: After setting the URL of the Help file, you can use the C-c c-v c-n to automatically run the start browser to see Help, preferably install emacs-w3m, so it is very convenient to see help, and more convenient is to set up a class Help file can implement context-sensitive help. Call Jde-help-symbol on a symbol to automatically display Help for that symbol.

Class and file browsing: JDE provides three methods, the first is the class menu we've mentioned, the second is the use of etags, and the third most powerful is a tree-like browser that uses Speedbar implementations. There is almost no difference between the use of the commercial IDE, the ability to graphically access files, the methods and variables of classes, the packages they depend on, and so on.

Debug: JDE provides support for jdb through GUD, and in order to better play JDE's function, JDE authors have written a debugger jdebug. Unfortunately, I do not have enough research on this.

Configuration

JDE has almost unlimited configurable, the most basic can be modified with JDE-related variables and key-binding, etc., in-depth some can modify the template, of course, the most in-depth is directly hack its source.

Back to top of page

Summarize

This paper briefly introduces the installation and basic functions of Java Ide-jde under Emacs, hoping that more friends will like Emacs and JDE. Above is just one of the most concise introduction, the specific functions and beauty also need to be realized in the use. A point to note is that the use of JDE first must have the basic knowledge of Emacs, followed by a little hack spirit, if you need a quick-start idiot-style IDE, that JDE may not meet the requirements. Information about JDE, maillist and other information, can be accessed JDE home http://jde.sunsite.dk.

Reprint: EMACS-JDE Development environment settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.