在开发过程中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-036. A乘以B 【水】

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

  2. HDU - 3829 Cat VS Dog (二分图最大独立集)

    题意:P个小朋友,每个人有喜欢的动物和讨厌的动物.留下喜欢的动物并且拿掉讨厌的动物,这个小朋友就会开心.问最多有几个小朋友能开心. 分析:对于每个动物来说,可能既有人喜欢又有人讨厌,那么这样的动物实际 ...

  3. 筛选最新生成的报告——sort

    筛选出最新报告发送,返回报告路径 import os def filePath(path): return os.path.join(os.path.abspath(os.path.dirname(o ...

  4. Spring中的定时调度(Scheduling)和线程池(Thread Pooling)

    使用triggers和SchedulerFactoryBean来包装任务 我们已经创建了job details,jobs.我们同时回顾了允许你调用特定对象上某一个方法的便捷的bean. 当然我们仍需要 ...

  5. Linux工作管理 jobs、fg、bg、nohup命令

    概述 在Linux 中我们登陆了一个终端,已经在执行一个操作,可以通过一定的操作或命令在不关闭当前操作的情况下执行其他操作. 例如,我在当前终端正在 vi 一个文件,在不停止 vi 的情况下,如果我想 ...

  6. Centos 7 Sublime 安装 package control

    1. 修改installed Packages 下的package Control.sublime-package(原文件是个空的文件) 2. 下载channel_v3.json 可放在任何位置并在s ...

  7. Java集合类初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  8. 检索并打印一个DNS主机条目

    检索并打印一个DNS主机条目的 C 程序 --- Linux/Unix /*************************************************************** ...

  9. 本地存储(localStorage、sessionStorage、web Database)

    一.sessionStorage和localStorage sessionStorage和localStorage两种方法都是当用户在inPut文本框中输入内容并点击保存数据按钮时保存数据,点击读取数 ...

  10. 分布式链路监控与追踪系统Zipkin

    1.分布式链路监控与追踪产生背景2.SpringCloud Sleuth + Zipkin3.分布式服务追踪实现原理4.搭建Zipkin服务追踪系统5.搭建Zipkin集成RabbitMQ异步传输6. ...