在开发过程中rebar自带模板建立项目,或多或少不能满足自己的开发需求。本人又是那种懒人,所以就要想办法偷懒。查看了priv模板 打造适合自己的项目模板。下面我简单的介绍整个模板的打造过程。

准备过程

 1.创建对应的template 目录

 2.ctrl+h 查看当前用户目录下是否有一个 .rebar 的文件目录 或者 shell 查看

thinkpad@thinkpad:~$ ll -ps | grep .rebar
drwxr-xr-x thinkpad thinkpad 6月 : rebar/
drwxrwxr-x thinkpad thinkpad 6月 : .rebar/

文中 . rebar 就是rebar 存放自定义template 文件的地方

 3 .在.reabr 文件中有一个template的文件夹,如果没有没有请创建一个

 4.进入template文件夹中创建一个 simple_game 文件夹 和一个simple_game.template的文件

 到此为止,创建rebar tempalte 的准备工作我们就做完了。

模板文功能

1.创建一个完成的otp项目

2.开发启动,调试脚本

3.代码更新,编译后自动重新加载。方便调试 这也是erlang热更新的一个特性

4.发布项目,打包镜像

制作模板文件

1.准备模板文件 下面是我准备好的模板文件

 -rw-rw-r--  thinkpad thinkpad    7月   : app.config
-rw-rw-r-- thinkpad thinkpad 12月 erl.script
-rw-rw-r-- thinkpad thinkpad 7月 : game_app.erl
-rw-rw-r-- thinkpad thinkpad 7月 : game.app.src
-rw-rw-r-- thinkpad thinkpad 7月 : game.erl
-rw-rw-r-- thinkpad thinkpad 7月 : game_server.erl
-rw-rw-r-- thinkpad thinkpad 7月 : game_sup.erl
-rw-rw-r-- thinkpad thinkpad 12月 gitignore
-rw-rw-r-- thinkpad thinkpad 12月 Makefile
-rw-rw-r-- thinkpad thinkpad 12月 nodetool
-rw-rw-r-- thinkpad thinkpad 6月 : README.md
-rw-rw-r-- thinkpad thinkpad 7月 : rebar.config
-rw-rw-r-- thinkpad thinkpad 6月 : reloader.erl
-rw-rw-r-- thinkpad thinkpad 6月 : reltool.config
-rwxrwxr-x thinkpad thinkpad 12月 runner*
-rwxrw-r-- thinkpad thinkpad 7月 : start-dev.sh*
-rw-rw-r-- thinkpad thinkpad 12月 vm.args
 2. 提供rebar调用的文件模板
 %% -*- erlang -*-

 %%
%% project template
%%
%% Sets up boilerplate for a distributed erlang application that
%% supports hot upgrades.
%%
%% Example:
%%
%% rebar create template=project projectid=superfly
%%
% App Files
{variables, [{projectid, "myproj"}]}. %readme
{template, "simple_game/README.md", "{{projectid}}/README.md"}.
% Build Files
{template, "simple_game/Makefile", "{{projectid}}/Makefile"}.
{template, "simple_game/gitignore", "{{projectid}}/.gitignore"}.
{template, "simple_game/rebar.config", "{{projectid}}/rebar.config"}.
{template, "simple_game/start-dev.sh", "{{projectid}}/start-dev.sh"}.
{chmod, #, "{{projectid}}/start-dev.sh"}. % App Files
{template, "simple_game/game.app.src", "{{projectid}}/apps/{{projectid}}/src/{{projectid}}.app.src"}.
{template, "simple_game/reloader.erl", "{{projectid}}/apps/{{projectid}}/src/reloader.erl"}.
{template, "simple_game/game.erl", "{{projectid}}/apps/{{projectid}}/src/{{projectid}}.erl"}.
{template, "simple_game/game_app.erl", "{{projectid}}/apps/{{projectid}}/src/{{projectid}}_app.erl"}.
{template, "simple_game/game_sup.erl", "{{projectid}}/apps/{{projectid}}/src/{{projectid}}_sup.erl"}.
{template, "simple_game/game_server.erl", "{{projectid}}/apps/{{projectid}}/src/{{projectid}}_server.erl"}. % Release files
{template, "simple_game/README.md", "{{projectid}}/deps/README.md"}.
{template, "simple_game/vm.args", "{{projectid}}/rel/files/vm.args"}.
{template, "simple_game/reltool.config", "{{projectid}}/rel/reltool.config"}.
{template, "simple_game/app.config", "{{ projectid}}/rel/files/app.config"}. {file, "simple_game/erl.script", "{{projectid}}/rel/files/erl"}.
{chmod, #, "{{projectid}}/rel/files/erl"}. {file, "simple_game/nodetool", "{{projectid}}/rel/files/nodetool"}.
{chmod, #, "{{projectid}}/rel/files/nodetool"}. {file, "simple_game/runner", "{{projectid}}/rel/files/{{projectid}}"}.
{chmod, #, "{{projectid}}/rel/files/{{projectid}}"}.

3.模板的主要制作过程是替换对已文件我恩需要替换的参数。

在rebar文件模板中我们可以看到 这一行 {variables, [{projectid, "myproj"}]}. projectid 就是在rebar中我们传入的参数。在准备好的文件中 我们需要替换或者插入我们参数的地方 使用 {{projectid}} rebar 就会给予替换为我们传入的参数。

4. 模板文件说明  

 app.config           整个系统启动配置参数,可覆盖app.src 参数
erl.script erlang 发布后启动脚本
game_app.erl application
game.app.src app.src
game.erl 调试启动文件 不用每次 application:start(game).
game_server.erl server
game_sup.erl sup
gitignore
Makefile make 模板
nodetool
README.md
rebar.config rebar对应配置文件
reloader.erl 开发中重新加载编译代码文件来自mochiweb
reltool.config 发布打包构建项目配置
runner*
start-dev.sh* 开发启动文件
vm.args erl erlang 启动参数文件

创建发布项目

1 .创建项目 rebar create template=simple_game projectid=game_demo

thinkpad@thinkpad:~/demo$ rebar create template=simple_game projectid=game_demo
==> demo (create)
Writing game_demo/README.md
Writing game_demo/Makefile
Writing game_demo/.gitignore
Writing game_demo/rebar.config
Writing game_demo/start-dev.sh
Writing game_demo/apps/game_demo/src/game_demo.app.src
Writing game_demo/apps/game_demo/src/reloader.erl
Writing game_demo/apps/game_demo/src/game_demo.erl
Writing game_demo/apps/game_demo/src/game_demo_app.erl
Writing game_demo/apps/game_demo/src/game_demo_sup.erl
Writing game_demo/apps/game_demo/src/game_demo_server.erl
Writing game_demo/deps/README.md
Writing game_demo/rel/files/vm.args
Writing game_demo/rel/reltool.config
Writing game_demo/rel/files/app.config
Writing game_demo/rel/files/erl
Writing game_demo/rel/files/nodetool
Writing game_demo/rel/files/game_demo

2 . 发布项目 make

thinkpad@thinkpad:~/demo/game_demo$ make
rebar clean
==> game_demo (clean)
rebar compile
==> game_demo (compile)
Compiled src/game_demo.erl
Compiled src/game_demo_sup.erl
Compiled src/game_demo_server.erl
Compiled src/game_demo_app.erl
Compiled src/reloader.erl
==> rel (compile)
==> game_demo (compile)
rebar generate -f
==> rel (generate)

3 . 调试发布项目 make console

thinkpad@thinkpad:~/demo/game_demo$ make console
rebar compile
==> game_demo (compile)
==> rel (compile)
==> game_demo (compile)
rebar generate -f
==> rel (generate)
WARN: 'generate' command does not apply to directory /home/thinkpad/demo/game_demo
rel/game_demo/bin/game_demo console
Exec: /home/thinkpad/demo/game_demo/rel/game_demo/erts-6.1/bin/erlexec -boot /home/thinkpad/demo/game_demo/rel/game_demo/releases/0.1./game_demo -embedded -config /home/thinkpad/demo/game_demo/rel/game_demo/etc/app.config -args_file /home/thinkpad/demo/game_demo/rel/game_demo/etc/vm.args -- console
Root: /home/thinkpad/demo/game_demo/rel/game_demo
Erlang/OTP [erts-6.1] [source] [-bit] [smp::] [async-threads:] [hipe] [kernel-poll:true] Eshell V6. (abort with ^G)
(game_demo@127.0.0.1)>

4. 开发项目 ./start-dev.sh

thinkpad@thinkpad:~/demo/game_demo$ ./start-dev.sh
==> game_demo (clean)
==> game_demo (compile)
==> rel (compile)
==> game_demo (compile)
Erlang/OTP [erts-6.1] [source] [-bit] [smp::] [async-threads:] [hipe] [kernel-poll:false]

制作好的文件在这 猛点下载 放入 .rebar template 下即可

文件下载

												

rebar自定义template的更多相关文章

  1. Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接

    在文章 Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接(一) 中我们成功的为/feedback/feedback_stats/路径自定义了使用tem ...

  2. 自定义Template,向其中添加新的panel

    参考网站:https://www.devexpress.com/Support/Center/Example/Details/E2690 思路: 新建一个DefaultTemplate:       ...

  3. 自定义template

    今天写代码写的有点烦了,感觉天天写new String(); new HashMap<String,String>()等,感觉写烦了,有没有快速的方法了.就你输入syso然后按atl+/就 ...

  4. rebar工具使用备忘录

    http://cryolite.iteye.com/blog/1159448 rebar是一个开源的erlang应用自动构建工具.basho的tuncer开发.它实际上是一个erlang脚本(escr ...

  5. 在Windows用Rebar来构建,编译,测试,发布Erlang项目

    rebar是一个遵循 Erlang/OTP 原则的 Erlang 项目构建工具,使用它可以减少构建标准 Erlang/OTP 项目架构配置的工作量,并且可以很容易的编译.测试.发布 Erlang 应用 ...

  6. IntelliJ下使用Code/Live Template加快编码速度:程序员的工作不是写程序,而是写程序解决问题

    程序员的工作不是写程序,而是写程序解决问题. --- 某不知名程序员 我们每天都在写代码,有些代码有结构性的相似,但不是所有的代码都可以被抽成方法.在这种情况下,我们应该考虑使用template的方式 ...

  7. Android Studio自定义注释模板及生成JavaDoc

    刚开始学习Android,使用了Android Studio IDE.为了将来生产JavaDoc,学习一下如何自定义注释模板. . 自定义注释模板 1. 通过 File –>Settings 或 ...

  8. 用 rebar 来构建、编译、测试、发布 Erlang 应用程序

    转自:http://dhq.me/build-compile-eunit-release-erlang-application-with-rebar rebar 是一个遵循 Erlang/OTP 原则 ...

  9. Django自定义过滤器中is_safe和need_autoescape两个参数的理解

    自定义template过滤器的方法参考文档,不再赘述 is_safe 文档说明过滤的两种最终形态,其中一种是设置register.filter(is_safe=True),但是对is_safe的具体作 ...

随机推荐

  1. PAT 天梯赛 L1-008. 求整数段和 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-008 AC代码 #include <iostream> #include <cstdio&g ...

  2. $python包管理工具pip的安装和使用

    pip是python的一个非常好用的包管理工具,可以用来很方便地安装和管理各种三方库,本文对其基本用法进行介绍. 安装pip Windows系统上安装 python 2.7.9及以上版本的window ...

  3. redis 系列文章推荐

    推荐博客: Redis在linux上的安装: http://www.open-open.com/lib/view/open1426468117367.html Redis的三种启动方式: http:/ ...

  4. h5打开App的方法。

    在浏览器中: 法1: location.href = `${scheme}`;//location跳转App是几乎所以情况都支持的. 法2: var ifr = document.createElem ...

  5. 【Head First Servlets and JSP】笔记23:Expression Language(EL) 完全攻略

    基本上是<Head First Servlets and JSP>内容的整理.扩充.顺便推荐一个供参考的JSP教程:JSP Tutorial内容很全面,还有一些有趣的实例. 完整代码参考 ...

  6. Appium+eclipse+python环境配置

    1.安装安卓开发环境(教程很多,不细写) 2.安装eclipse 下载eclipse,解压即可   3.安装python 下载地址:https://www.python.org/downloads/r ...

  7. 用maven创建web工程

    1.打开eclipse,选择File->New->Other菜单,弹出下面的对话框,在Wizards中输入maven,会过滤出和maven相关的菜单,选中Maven Project菜单,然 ...

  8. sql报字段过大的错误解决方法

    set global max_allowed_packet = 2*1024*1024*10

  9. spring的AOP动态代理--JDK代理和CGLIB代理区分以及注意事项

    大家都知道AOP使用了代理模式,本文主要介绍两个代理模式怎么设置以及区别,对原文一些内容进行了引用后加入了自己的理解和更深入的阐述:   一.JDK代理和CGLIB代理的底层实现区别* JDK代理只能 ...

  10. node 模块部分介绍

    chai  断言框架 mocha mochawesome  对mocha 定制报告,生成完整成熟的报告. node-fetch  服务器版fetch superagent  是node 客户端请求代理 ...