有时候需要项目依赖其他的开源项目(比如lager),这时候我们回到example目录下,编辑rebar.config文件:
%%-*- mode: erlang -*- {erl_opts, [{parse_transform, lager_transform}]}. {sub_dirs, ["rel"]}. {deps, [{lager, ".*", {git, "git://github.com/basho/lager.git", "master"}}]}.
修改rel目录下reltools.config,为:
{sys, [ {lib_dirs, ["http://www.cnblogs.com/", "../deps/"]}, {rel, "example", "1", [ kernel, stdlib, sasl, example ]}, {rel, "start_clean", "", [ kernel, stdlib ]}, {boot_rel, "example"}, {profile, embedded}, {excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)"]}, {app, sasl, [{incl_cond, include}]} ]}. {target_dir, "example"}. {overlay, [ {mkdir, "log/sasl"}, {copy, "files/erl", "{{erts_vsn}}/bin/erl"}, {copy, "files/nodetool", "{{erts_vsn}}/bin/nodetool"}, {copy, "files/example", "bin/example"}, {copy, "files/app.config", "etc/app.config"}, {copy, "files/vm.args", "etc/vm.args"} ]}.
注意将lib_dirs添加了对deps目录的查找。
修改src/example.app.src为:
{application, example, [ {description, ""}, {vsn, "1"}, {registered, []}, {applications, [ kernel, stdlib, lager ]}, {mod, { example_app, []}}, {env, []} ]}.
将 lager添加进applications中
这时候,我们
[admin@localhost example]$ make clean [admin@localhost example]$ make rel
ok,我们运行:
[admin@localhost example]$ rel/example/bin/example console Exec: /opt/example/rel/example/erts-5.10.1/bin/erlexec -boot /opt/example/rel/example/releases/1/example -embedded -config /opt/example/rel/example/etc/app.config -args_file /opt/example/rel/example/etc/vm.args -- console Root: /opt/example/rel/example Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:2:2] [async-threads:5] [hipe] [kernel-poll:true] 08:00:45.209 [info] Application lager started on node 'example@127.0.0.1' 08:00:45.209 [info] Application example started on node 'example@127.0.0.1' Eshell V5.10.1 (abort with ^G) (example@127.0.0.1)1>
可以看到lager也已经启动了,我们查看一下
./rel/example/lib下,可以看到lager已经出现在lib中了。