5

I've been trying to get my Emacs config for Java development working. It's pretty good - I've gotten malabar-mode working and have GNU Global working for tag browsing. The one thing I can't get working is getting semanticdb to use gnu global properly. None of my imports are found.

First, this is a Maven multi-module project with all sources checked out from the top-level root project folder. All other projects are below this one in the directory tree. There is a single GTAGS database in this root folder covering everything.

Things that work:

  • M-x gtags-find-tag RET symbol RET works fine, so the database is good and global can find it.
  • M-x cedet-gnu-global-version-check works and reports that my version is good.
  • M-x cedet-gnu-global-expand-filename works
  • M-x semanticdb-find-test-translate-path shows a "GNU Global Search Table" when in a Java buffer
  • I have the JDK source folder set as a system include folder, so core Java imports are parsed properly.

My java config is as follows (cedet initialization is earlier in the file):

(add-local-load-path "malabar/lisp")

(require 'malabar-mode)
(setq malabar-groovy-lib-dir (concat emacs-local-site-lisp "malabar/lib"))
(add-to-list 'auto-mode-alist '("\\.java\\'" . malabar-mode))

;; enable semanticdb support for gnu global
(when (cedet-gnu-global-version-check t)
  (semanticdb-enable-gnu-global-databases 'java-mode))

(add-hook 'java-mode-hook
    (lambda ()
    (gtags-mode 1)))

(add-hook 'java-mode-hook 'flymake-mode-on)

(defun my-java-flymake-init ()
  (list "javac" (list (flymake-init-create-temp-buffer-copy
                   'flymake-create-temp-with-folder-structure))))

(add-to-list 'flymake-allowed-file-name-masks
         '("\\.java$" my-java-flymake-init flymake-simple-cleanup))

(add-hook 'java-mode-hook
      '(lambda ()
         (semantic-add-system-include (getenv "JAVA_HOME") 'java-mode)))
4

1 回答 1

3

答案与您的项目的设置方式以及您是否使用 EDE 有关。EDE 是 Emacs 开发环境(在 IDE 上运行),它是 CEDET 跟踪哪些文件属于您的项目的方式。该限制器与性能(搜索更少的东西)和防止配置从一个项目渗入另一个项目有关。

不幸的是,CEDET/EDE 还不支持 Maven。但是,您可以只标记项目的根目录,我猜 ede-cpp-root(通常用于 C++ 项目)可能就足够了。我们可能应该制作一个Java版本。

无论如何,可以将 EDE 配置为使用 GNU Global 快速查找文件(请参阅使用 EDE 和语义的 GNU Global 支持手册),但您的 GTAGS 文件需要位于项目根目录下。

如果您在 project-1 中,并希望跳转到 project-2 中的文件,而 GTAGS 是 project-1 的根目录,那么它将无法正常工作。您必须将 GTAGS 文件和 EDE 项目移动到一个公共父目录。

在您当前的设置中,如果所有内容都已经在 GTAGS 的公共目录下,那么您很可能只需要设置一个 EDE 项目来挂起 GTAGS 文件查找功能。

cedet-devel 邮件列表存档中有几个在这方面取得了一些成功的人的主题。

于 2012-05-24T23:15:34.910 回答