0%

rebar3配置使用

rebar3erlang下的配置管理工具.

编译安装rebar3

1
2
3
4
5
6
7
8
9
10
git clone https://github.com/erlang/rebar3.git
cd rebar3
## linux
./bootstrap
rebar3 local install
## 按照提示,增加$PATH

## windows
bootstrap.bat
## 将生成的rebar3, rebar3.cmd放到path目录下

创建项目

1
2
## new template my_project_name
rebar3 new release myapp

目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$tree 
.
├── apps
│   └── myapp
│   └── src
│   ├── myapp_app.erl
│   ├── myapp.app.src
│   └── myapp_sup.erl
├── config
│   ├── sys.config applications配置
│   └── vm.args 启动参数
├── LICENSE
├── README.md
├── rebar.config 项目开发配置参数
└── rebar.lock

添加依赖

1
2
## rebar.config
{deps, [{cowboy, "1.0.1"}]}.
1
2
## myapp.app.src
{applications, [kernel, stdlib, cowboy]}

编译

1
2
## compile自动get依赖
rebar3 compile

配置applications

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## sys.config
[
{ myapp, []},
{sasl,[
%% minimise shell error logging
{sasl_error_logger,false},
%% only report errors
{errlog_type,error},
%% the log file directory
{error_logger_mf_dir,"./erl_logs"},
%% bytes per logfile
{error_logger_mf_maxbytes,10485760}, % 10MB
%% max mumber of log files
{error_logger_mf_maxfiles,10}
]},
{kernel,[
{inet_dist_listen_min, 4370},
{inet_dist_listen_max, 5370}
]}
].

启动

1
rebar3 shell

发布

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
%% 发布选项
{relx, [
...
{include_erts, false},
{include_src, false},
{system_libs, false}
...
]}.
{profiles, [
{prod, [
{relx, [
{include_erts, false}
]}
]}
]}.
1
2
rebar3 release
rebar3 as prod tar