默認你的主機已經安裝了rebar和git,在git bash 下分別執行 rebar -V 和 git 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().