在开发过程中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. BZOJ 3689: 异或之

    字典树可以$o(logn)查找第k大$ 使用$可持久化Trie 区间查找第k大,然后首先把每个数异或之后的最小丢进小根堆中,然后一个一个取出,取出后就再丢次小,一共取k次$ 总的时间复杂度为$O(kl ...

  2. SqlHelper简单实现(通过Expression和反射)1.引言

    之前老大说要改变代码中充斥着各种Select的Sql语句字符串的情况,让我尝试着做一个简单的SqlHelper,要具有以下功能: 1.不要在业务代码中暴露DataTable或者DataSet类型: 2 ...

  3. Javascript Array对象 sort()方法,记忆方法,方法扩展

    相信 有很多 同仁们,尤其是初学者,在记住 Array对象 sort() 方法的排序,规则上,有点困难: 其实sort()方法已经在实际工作中用到很多遍了,可当我仔细推敲,这个sort()方法,什么时 ...

  4. [转]毕设- 深入HBase架构解析(二)

    深入HBase架构解析(二) 前言 这是<深入HBase架构解析(一)>的续,不多废话,继续.... HBase读的实现 通过前文的描述,我们知道在HBase写时,相同Cell(RowKe ...

  5. kali安装后配置

    0x00.安装Vmware Tools 由于是在VMware Workstation里面安装的,所以需要首先安装VMware tools工具方便我们Ctrl+C和Ctrl+V,步骤如下: 在VMWar ...

  6. 在Linux系统中使用蓝牙功能的基本方法

    首先确定硬件上有支持蓝牙的设备,然后运行如下命令,就可以开到我们的蓝牙设备了: lsusb 运行hciconfig可以看到:从上图可以看出,我们的蓝牙设备是hci0运行hcitool dev可以看到我 ...

  7. Linux系统中使用netcat命令的奇技淫巧

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...

  8. 制作基于Buildbot的自动化测试系统Docker镜像

    Buildbot in Docker 前言 最近使用Buildbot做了一个自动测试的框架,为了部署方便,可以把测试框架做成Docker镜像,方便部署.这里记录下过程,供大家参考. 项目介绍 项目是一 ...

  9. windchill系统——导航器v1.0:思维导图

    总图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/7b3fc783493788

  10. Flume-NG源码阅读之FileChannel

    FileChannel是flume一个非常重要的channel组件,非常常用.这个channel非常复杂,涉及的文件更多涉及三个包:org.apache.flume.channel.file.org. ...