Introduction to Emacs Java Development
I have summarized the skills for developing Java applications (including testng and Web applications) with Emacs and maven on Ubuntu over the years. I hope this will help my friends who are interested in Linux development. I am not opposed to IDE development, but many times, emacs can bring faster speed (and have little requirements on machine hardware) and have a better understanding of Java engineering, it is easier to communicate with engineers in the Open Source Field. I still don't like to use the mouse very much. emacs allows me to free my right hand.
Install
1. Make sure that you have installed JDK
2. Make sure you have installed Maven
3. Install Emacs: sudo apt-Get install Emacs
4.download jdee-bin-2.4.0.1.zipand the dependent file elib-1.0.zip, address here: http://sourceforge.net/projects/jdee/files/
5. Extract the two files to the/opt/emacs_plugins/directory.
6. You also need to download the ecb-2.40 and ECB. El, also in the emacs_plugins directory
7. Download The javadoc-help javadoc-help.el file and put it under the/opt/emacs_plugins/Java directory http://javadochelp.sourceforge.net/
Configure. emacs configure jdee
;;JDEE configuration(add-to-list 'load-path (expand-file-name "/opt/emacs_plugins/jdee-2.4.0.1/lisp"))(load-file "/opt/emacs_plugins/cedet-1.0pre7/common/cedet.el")(add-to-list 'load-path (expand-file-name "/opt/emacs_plugins/elib-1.0"))(add-to-list 'load-path (expand-file-name "/opt/emacs_plugins/ecb-2.40"));;(add-to-list 'load-path (expand-file-name "/opt/emacs_plugins/jde-jalopy"))(load-file (expand-file-name "/opt/emacs_plugins/ecb-2.40/ecb.el"))(require 'font-lock)(require 'ecb)(require 'ecb-autoloads)(require 'jde)(custom-set-variables '(browse-url-browser-function (quote browse-url-generic)) '(browse-url-generic-program "chromium-browser") '(column-number-mode t) '(jde-complete-function (quote jde-complete-menu)) '(jde-debugger (quote ("jdb"))) '(jde-jdk-registry (quote (("1.6.0_35" . "/usr/jdk1.6")))) '(jde-resolve-relative-paths-p t) '(jde-run-option-debug (quote ("Server" "Socket" "javadebug" nil "5005" t))))
View API documentation
Unfortunately, javadoc-helper cannot retrieve JDK documents. Keep a bookmarks in your browser instead.
;; Java document support(add-to-list 'load-path (expand-file-name "/opt/emacs_plugins/java"))(require 'javadoc-help)(javadoc-set-predefined-urls '("/opt/java_docs/common-cache-1.0.0-javadoc" "/opt/java_docs/commons-codec-1.4-javadoc" "/opt/java_docs/commons-logging-1.1.1-javadoc" "/opt/java_docs/ehcache-server-1.0.0-javadoc" "/opt/java_docs/gson-1.7.1-javadoc" "/opt/java_docs/jcommander-1.12-javadoc" "/opt/java_docs/jersey-apache-client-1.9.1-javadoc" "/opt/java_docs/jersey-client-1.9.1-javadoc" "/opt/java_docs/jersey-core-1.9.1-javadoc" "/opt/java_docs/joda-time-1.6.2-javadoc" "/opt/java_docs/junit-4.8.2-javadoc" "/opt/java_docs/logback-classic-1.0.0-javadoc" "/opt/java_docs/logback-core-1.0.0-javadoc" "/opt/java_docs/lombok-0.10.4-javadoc" "/opt/java_docs/mongo-java-driver-2.7.2-javadoc" "/opt/java_docs/mybatis-3.0.5-javadoc" "/opt/java_docs/slf4j-api-1.6.4-javadoc" "/opt/java_docs/snakeyaml-1.6-javadoc" "/opt/java_docs/testng-6.1.1-javadoc"))(global-set-key [(f1)] 'javadoc-lookup) ; F1 to lookup(global-set-key [(shift f1)] 'javadoc-help) ; Shift-F1 to bring up menu
Note: The above document directories are all downloaded from the Internet. If you use Maven to build a project, you can easily use a script file to download the file jar package, and copy it to the/opt/java_docs/directory.
mvn cleanmvn dependency:resolve -Dclassifier=javadocrm -rf /opt/java_docsmkdir /opt/java_docscp $(find ~/.m2/repository/ -name *javadoc.jar) /opt/java_docs/
The following script can help me extract all jar files to a directory with the same name.
#!bin/shpath=/opt/java_docsfor f in $(ls $path/*.jar);do name=`basename $f` name2=`echo $name | sed 's/\.jar//g'` echo $name2 mkdir $path/$name2 cd $path/$name2 jar xvf $path/$namedonerm -f *.jar
This script can generate the directory path to be configured and used in. emacs.
path=/opt/java_docsfor f in $(ls $path/);do name=`basename $f` echo \"/opt/java_docs/$name\"done
Configuration project file
Create a prj. El file for each Maven project directory. The following is an example. The jdksource code file of/opt/jdk_srcis extracted from the src.zip file in the jdkdirectory.
Jde-global-classpath lists the jar packages used in this project. Note that it is an absolute path.
'(Jde-db-Option-connect-socket (Quote (nil "5005") refers to the connection port for remote debugging, which will be detailed later in the debugging section.
'Jde-sourcepath specifies the source code path
Manual configuration of these things is indeed a little troublesome. In the future, you can learn some lisp programming and automatically generate this file in Emacs. Let's use it together.
(jde-project-file-version "1.0")(jde-set-variables '(jde-db-source-directoiries "/opt/jdk_src") '(jde-global-classpath (quote ("./target/classes" "./target/test-classes" "/home/chenshu/.m2/repository/joda-time/joda-time/1.6.2/joda-time-1.6.2.jar" "/home/chenshu/.m2/repository/com/sun/jersey/jersey-client/1.9.1/jersey-client-1.9.1.jar" "/home/chenshu/.m2/repository/org/testng/testng/6.0.1/testng-6.0.1.jar"))) '(jde-db-option-connect-socket (quote (nil "5005"))) '(jde-sourcepath (quote ("./src/main/java/com/freebird/business" "./src/test/java/com/freebird/test" ))))The last configuration of Windows 7 is attached to the configuration of Windows 7. After a long time, no error is reported for cedet.
(setq debug-on-error t)(global-set-key [f5] (lambda() (interactive) (revert-buffer t t)))(setq c-basic-offset 4)(show-paren-mode);;JDEE configuration(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/jdee-2.4.0.1/lisp"))(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/cedet-1.0/common"))(load-file "c:/emacs_plugins/cedet-1.0/common/cedet.el")(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/cedet-1.0/semantic"))(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/cedet-1.0/eieio"))(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/cedet-1.0/speedbar"))(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/elib-1.0"))(add-to-list 'load-path (expand-file-name "c:/emacs_plugins/ecb-2.40"))(load-file (expand-file-name "c:/emacs_plugins/ecb-2.40/ecb.el"))(require 'font-lock)(require 'ecb)(require 'ecb-autoloads)(require 'jde)(custom-set-variables '(browse-url-browser-function (quote browse-url-generic)) '(browse-url-generic-program "chromium-browser") '(column-number-mode t) '(jde-gen-buffer-boilerplate (quote (nil "//////////////////////////////////////////////////////////////////////////////////Copyright (c) 2011-2012 Esri// Esri (Beijing) Software Research and Development Center//// All rights reserved under the copyright laws of the United States.////////////////////////////////////////////////////////////////////////////////"))) '(jde-complete-function (quote jde-complete-menu)) '(jde-debugger (quote ("jdb"))) '(jde-db-option-connect-socket (quote (nil "9009"))) '(jde-jdk-registry (quote (("1.6.0_29" . "C:/Program Files/Java/jdk1.6.0_29")))) '(jde-resolve-relative-paths-p t) '(jde-run-option-debug (quote ("Server" "Socket" "javadebug" nil "5005" t))))(setq tab-width 4)(setq c-basic-offset 2)
According to company regulations, the descriptions of development headers are added.