在开发过程中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-014. 简单题 【水】

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

  2. cart_购物车小程序

    #author:leon product_list= [ ('iphone',5800), ('mac pro',9800), ('bike',800), ('watch',6000), ('coff ...

  3. 20145201《Java程序设计》第7周学习总结

    20145201 <Java程序设计>第七周学习总结 教材学习内容总结 本周学习了课本第十二.十三章内容,即Lambda.时间与日期 第十二章 Lambda 12.1 认识Lambda语法 ...

  4. Easy-RSA 3快速入门自述文件

    Easy-RSA 3快速入门自述文件 这是使用Easy-RSA版本3的快速入门指南.运行./easyrsa -h可以找到有关使用和特定命令的详细帮助.可以在doc /目录中找到其他文档. 如果您从Ea ...

  5. DATASTAGE中ODBC连接的配置

    修改2个配置文件: cat /mistel/IBM/InformationServer/Server/DSEngine/.odbc.ini cat /mistel/IBM/InformationSer ...

  6. Floyd算法--一个人的旅行

    2017-07-27 22:37:32 writer:pprp 题目如下: 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人 ...

  7. PAT1042. Shuffling Machine (20)

    #include <iostream> #include <vector> using namespace std; int n; string card[54]={" ...

  8. CNI:容器网络接口

    CNI 简介 不管是 docker 还是 kubernetes,在网络方面目前都没有一个完美的.终极的.普适性的解决方案,不同的用户和企业因为各种原因会使用不同的网络方案.目前存在网络方案 flann ...

  9. xml、json的序列化与反序列化

    xml数据 : XmlSerializer.Serialize   与  XmlSerializer.Deserialize,使用起来稍有些复杂,需要对 “实体模型” 的“对应属性”  进行  节点特 ...

  10. ArcGIS API For Silverlight使用在线地图的多种方法总结

    引自:http://www.cnblogs.com/meimao5211/p/3283969.html ArcGIS API For Silverlight使用在线地图的多种方法总结 本人也正在学习A ...