Apr 14
Maven and Emacs
This is some lisp code I whipped together I tweaked to compile Java code using Maven, from within emacs. Copy and paste the code into your .emacs file, then from any Java buffer press
ALT+x mvn
...or for quick compiles press...
CTRL+c CTRL+x 5
The code starts here...
(require 'compile)(defvar mvn-command-history nil "Maven command history variable")(defun mvnfast() (interactive) (let ((fn (buffer-file-name))) (let ((dir (file-name-directory fn))) (while (and (not (file-exists-p (concat dir "/pom.xml"))) (not (equal dir (file-truename (concat dir "/.."))))) (setq dir (file-truename (concat dir "/..")))) (if (not (file-exists-p (concat dir "/pom.xml"))) (message "No pom.xml found") (compile (concat "mvn -f " dir "/pom.xml install -Dmaven.test.skip=true"))))))(define-key java-mode-map "\C-c\C-x5" 'mvnfast)(defun mvn(&optional args) "Runs maven in the current project. Starting at the directoy where the file being vsisited resides, a search is made for pom.xml recsurively. A maven command is made from the first directory where the pom.xml file is found is then displayed in the minibuffer. The command can be edited as needed and then executed. Errors are navigate to as in any other compile mode" (interactive) (let ((fn (buffer-file-name))) (let ((dir (file-name-directory fn))) (while (and (not (file-exists-p (concat dir "/pom.xml"))) (not (equal dir (file-truename (concat dir "/.."))))) (setq dir (file-truename (concat dir "/..")))) (if (not (file-exists-p (concat dir "/pom.xml"))) (message "No pom.xml found") (compile (read-from-minibuffer "Command: " (concat "mvn -f " dir "/pom.xml install -Dmaven.test.skip=true") nil nil 'mvn-command-history))))));; String pattern for locating errors in maven output. This assumes a Windows drive letter at the beginning(add-to-list 'compilation-error-regexp-alist '("^\\([a-zA-Z]:.*\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3))Credit where it's due, this code is copied and tweaked from original code provided here ... http://vastusutra.blogspot.com/2007/06/getting-emacs-and-maven-2-to-play.html