Win10下 Erlang生成依赖项本地副本

    有时候几个不一样的应用程序会用到相同的依赖项,在这种状况下,咱们会在应用程序的外部建立一个依赖项目录结构。对于个人本地项目,我会把全部已下载的rebar依赖项保存在一个地方。例如,我把全部这些依赖项保存在 G:\ErlangWorkSpace\erl_imports 路径下。 我这台机器的组织方式是ErlangWorkSpace 目录下的任何文件都不会有备份。由于这些我感兴趣的文件在Web上处处都是,因此没有必要建立本地备份。

默认你的主机已经安装了rebar和git,在git bash 下分别执行 rebar -Vgit version 指令,以下说明已经安装成功:git

一、在 G:\ErlangWorkSpace\erl_imports路径下新建一个 rebar.config 文件,在rebar.config文件下列出我想要使用的全部依赖项,它的的内容以下:github

{deps,[
       {cowboy,".*",{git,"git://github.com/extend/cowboy.git","master"}},
       {ranch,".*",{git,"git://github.com/extend/ranch.git","master"}},
       {bitcask,".*",{git,"git://github.com/basho/bitcask.git","master"}},
       {mochiweb,".*",{git,"git://github.com/mochi/mochiweb.git","master"}}
     ]}.

二、要获取这些依赖项,能够在保存配置文件的目录里输入命令 rebar get-depsweb

rebar get-deps

三、rebar不只获取了在配置文件里指定的程序,还递归获取了这些程序所依赖的其余程序。获取程序以后,咱们用 rebar compile 命令来编译它们。shell

rebar compile

 

四、最后一步是把这些依赖项的保存位置告诉Erlang,具体作法是把下面这些代码行移至启动文件${HOME}/.erlang里:bash

%%设置路径来让全部依赖就位
%%Home = os:getenv("HOME").
Dir = "h:/ErlangWorkSpace/erl_imports/deps",
{ok,L} = file:list_dir(Dir).
io:format("MyLibHome: ~p\n",[Dir]).
io:format("MyLibLists: ~p\n",[L]).
lists:foreach(fun(I) ->
                Path = Dir ++ "/" ++ I ++ "/ebin",
                io:format("MyLibPath: ~p\n",[Path]),
                code:add_patha(Path)
          end, L).

具体步骤以下:spa

1. 启动erlang shell,输入命令 init:get_argument(home). 查看erlang home目录code

init:get_argument(home).

 

 能够看到erlang的home目录。orm

2. 在home目录下面创建一个.erlang文件,里面内容以下(将Dir后面的路径设置成本身的依赖项路径)。blog

%%设置路径来让全部依赖就位
%%Home = os:getenv("HOME").
Dir = "h:/ErlangWorkSpace/erl_imports/deps",
{ok,L} = file:list_dir(Dir).
io:format("MyLibHome: ~p\n",[Dir]).
io:format("MyLibLists: ~p\n",[L]).
lists:foreach(fun(I) ->
                Path = Dir ++ "/" ++ I ++ "/ebin",
                io:format("MyLibPath: ~p\n",[Path]),
                code:add_patha(Path)
          end, L).

例如个人路径是:h:/ErlangWorkSpace/erl_imports/deps递归

3. 编辑完保存,重启erlang shell,输入 code:get_path(). 指令能够看到搜索路径

code:get_path().

相关文章
相关标签/搜索