rebar自定义template
在开发过程中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
%% -*- 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的更多相关文章
- Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接
在文章 Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接(一) 中我们成功的为/feedback/feedback_stats/路径自定义了使用tem ...
- 自定义Template,向其中添加新的panel
参考网站:https://www.devexpress.com/Support/Center/Example/Details/E2690 思路: 新建一个DefaultTemplate: ...
- 自定义template
今天写代码写的有点烦了,感觉天天写new String(); new HashMap<String,String>()等,感觉写烦了,有没有快速的方法了.就你输入syso然后按atl+/就 ...
- rebar工具使用备忘录
http://cryolite.iteye.com/blog/1159448 rebar是一个开源的erlang应用自动构建工具.basho的tuncer开发.它实际上是一个erlang脚本(escr ...
- 在Windows用Rebar来构建,编译,测试,发布Erlang项目
rebar是一个遵循 Erlang/OTP 原则的 Erlang 项目构建工具,使用它可以减少构建标准 Erlang/OTP 项目架构配置的工作量,并且可以很容易的编译.测试.发布 Erlang 应用 ...
- IntelliJ下使用Code/Live Template加快编码速度:程序员的工作不是写程序,而是写程序解决问题
程序员的工作不是写程序,而是写程序解决问题. --- 某不知名程序员 我们每天都在写代码,有些代码有结构性的相似,但不是所有的代码都可以被抽成方法.在这种情况下,我们应该考虑使用template的方式 ...
- Android Studio自定义注释模板及生成JavaDoc
刚开始学习Android,使用了Android Studio IDE.为了将来生产JavaDoc,学习一下如何自定义注释模板. . 自定义注释模板 1. 通过 File –>Settings 或 ...
- 用 rebar 来构建、编译、测试、发布 Erlang 应用程序
转自:http://dhq.me/build-compile-eunit-release-erlang-application-with-rebar rebar 是一个遵循 Erlang/OTP 原则 ...
- Django自定义过滤器中is_safe和need_autoescape两个参数的理解
自定义template过滤器的方法参考文档,不再赘述 is_safe 文档说明过滤的两种最终形态,其中一种是设置register.filter(is_safe=True),但是对is_safe的具体作 ...
随机推荐
- cf100989b
http://codeforces.com/gym/100989/my B. LCS (B) time limit per test 0.25 seconds memory limit per tes ...
- java实验一报告
北京电子科技学院(BESTI) 实 验 报 告 课程:Java 班级: 1352 姓名:黄晓妍 学号:20135227 成绩: 指导教师:娄嘉 ...
- git 强制放弃本地修改(新增、删除文件)【转】
本文转载自:https://blog.csdn.net/u012672646/article/details/56676804 本地修改了一些文件,其中包含修改.新增.删除的,不需要了想要丢弃,于是做 ...
- 深入理解JVM 垃圾收集器(上)
HotSpot虚拟机中的垃圾收集器 GC评价标准 GC调优 响应时间 吞吐量 1.新生代收集器 Serial收集器 ParNew收集器 Parallel Scavenge收集器 2.老年代收集器 Se ...
- idea中如何debug本地maven项目
方法一:使用maven中的jetty插件调试本地maven项目 1.打断点 2.右击“jetty:run”,选择Debug运行 3.浏览器发送http请求,开始调试 方法二:利用远程调试功能调试本地m ...
- Linux 一键安装最新内核并开启 BBR 脚本
原文链接 https://teddysun.com/489.html 请到原文链接仔细阅读后操作.建议查看过脚本内容后操作,方便理解运行过程. 使用root用户登录,运行以下命令: wget -- ...
- orecle触发器
一.触发器简介 触发器的定义就是说某个条件成立的时候,触发器里面所定义的语句就会被自动的执行.因此触发器不需要人为的去调用,也不能调用.然后,触发器的触发条件其实在你定义的时候就已经设定好了.这里面需 ...
- JSP报错01
ZC: 创建一个JSP之后,就报如下错误. 1.错误: 1.1. 2.处理: Exlipse for JEE --> Project Explorer 中选择项目 --> 右击项目名 -- ...
- LeetCode第[69]题(Java):Sqrt(x)
题目:求平方根 难度:Easy 题目内容: Compute and return the square root of x, where x is guaranteed to be a non-neg ...
- centos下tomcat自启动
一.在指定目录创建脚本并赋予755权限 vim /etc/init.d/tomcat #!/bin/bash # # kenny kenny.zhou@tom.com # /etc/rc.d/init ...