rebar 使用有感

  Rebar是一个独立的erlang脚本,所以使用Rebar发布程序非常简单,甚至可以直接集成在项目文件夹中。

默认的情况下,Rebar会按照 Erlang/OTP来组织项目的结构,这样一来,构建时的配置工作量就会大大减少。

Rebar同时提供了依赖库(包)管理机制,方便程序员重用已存在的 模块。Rebar的依赖管理机制支持的方式非常多,甚至包括Git, Hg等少见的方式。

下载地址:https://github.com/basho/rebar

官方介绍:https://github.com/basho/rebar/wiki

mochiweb 这个开源项目,也是使用 rebar 来构建的。

  期望的是 emacs + Makefile + rebar 能完美的结合起来,感谢有朋友写的插件 http://emacswiki.org/emacs/erlang-dired-mode.el

  最新下载:https://raw.github.com/jixiuf/erlang-dired-mode/master/erlang-dired-mode.el

  目前这个插件还是能比较方便的创建项目工程,这个插件应该是参考 mochiweb 中的方法,提取出来的 emacs插件。

  .emacs 配置

;;erlang-dired-mode
(load-file "~/.emacs.d/plugins/erlang-dired-mode.el")
(defun my-erlang-mode-hook ()
(define-key erlang-mode-map (kbd "C-c C-p") 'erlang-create-project) ;defined in erlang-dired-mode C-cC-p
(define-key erlang-mode-map (kbd "C-z s") 'erlang-compile-dwim) ;compile
(define-key erlang-mode-map (kbd "C-c C-k") 'erlang-compile-dwim) ;compile
(define-key erlang-mode-map (kbd "C-z C-s") 'erlang-compile-dwim) ;compile
)

(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)
(add-hook 'erlang-shell-mode-hook 'my-erlang-mode-hook)

  但是我目前本地使用,存在几个问题:

  一个是 make test 无法使用,提示目录已经是最新,这个解决办法是,在

  REBAR=./rebar 这行下,增加一行
  .PHONY : test

  另一个是 make app 的模板,需要从 Rebar 拷贝一份 priv 到项目根目录下,因为我们要用的一般的 OTP模板就可以了。

  但是 erlang-dired-mode.el 它使用的是 mochiwebapp 模板,所以需要修改,

  (insert "    @$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)\n")

  注意这句话,使用到模板是 mochiweb中的,我适当修改了这行

  (insert "    @$(REBAR) create-app dest=$(DEST) appid=$(PROJECT)\n")

  这样就使用默认到模板了。

  C+u C+ c C+k  然后 make app PROJECT=project_name 这个就跟 mochiweb 应该是一样的了。

  注意:如果是第一次创建项目,则使用 M-x:erlang-create-project,而不是 C+c C+p。这个很容易犯错。

  

  这篇文章,详细介绍了 Rebar的使用 http://www.cnblogs.com/panfeng412/archive/2011/08/14/compile-erlang-with-rebar.html

  

你可能感兴趣的:(rebar)