Emacs开发Java之安装
Emacs开发Java
前言
笔者把多年Ubuntu上用Emacs和Maven开发Java应用(包括TestNG和Web application)的技巧总结出来,希望对有志于Linux开发的朋友有帮助。我并不反对用IDE开发,但是很多时候,Emacs能够带来更快的速度(同时对机器硬件要求也很小),对Java工程的更透彻了解,更容易和开源领域的工程师交流。我还不怎么喜欢用鼠标,Emacs让我能够解放我的右手。
安装
1.确保你已经安装了JDK
2.确保你安装了Maven
3.安装Emacs:sudo apt-get install emacs
4.下载jdee-bin-2.4.0.1.zip和依赖文件elib-1.0.zip,地址在这里:http://sourceforge.net/projects/jdee/files/
5.将两个文件解压到/opt/emacs_plugins/目录下面
6.还需要下载ecb-2.40和ecb.el,也放在emacs_plugins目录下
7.下载javadoc-help的javadoc-help.el文件放在/opt/emacs_plugins/java目录下面 http://javadochelp.sourceforge.net/
配置.emacs
配置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))))
查看API文档
可惜的是javadoc-helper不能检索jdk文档。自己在浏览器里面保留一个书签代替吧。
;; 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
注意,上面的文档目录都是自己从互联网上下载的,如果使用maven构建项目,可以很方便的用一个脚本文件将文件jar包下载下来,并且复制到/opt/java_docs/目录下。
mvn clean
mvn dependency:resolve -Dclassifier=javadoc
rm -rf /opt/java_docs
mkdir /opt/java_docs
cp $(find ~/.m2/repository/ -name *javadoc.jar) /opt/java_docs/
下面这个脚本可以帮助我把所有jar文件解压到同名目录下。
#!bin/sh
path=/opt/java_docs
for 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/$name
done
rm -f *.jar
这个脚本可以生成需要配置的目录路径,用在.emacs中。
path=/opt/java_docs
for f in $(ls $path/);
do
name=`basename $f`
echo \"/opt/java_docs/$name\"
done
推荐阅读: