坦率地说,现在在 Erlang 中执行此操作的标准工具是不必要的烦人。我倾向于将以下样板放在我的应用程序回调模块中:
-module(myapp_app).
-export([start/0]).
start() -> a_start(myapp, permanent).
a_start(App, Type) ->
start_ok(App, Type, application:start(App, Type)).
start_ok(_App, _Type, ok) -> ok;
start_ok(_App, _Type, {error, {already_started, _App}}) -> ok;
start_ok(App, Type, {error, {not_started, Dep}}) ->
ok = a_start(Dep, Type),
a_start(App, Type);
start_ok(App, _Type, {error, Reason}) ->
erlang:error({app_start_failed, App, Reason}).
然后您可以将-s myapp_app 添加到您的erlang 命令行中,这将递归地启动应用程序及其所有依赖项。为什么这个功能不在我不知道的应用程序模块中:)
在我的 Erlang Factory 2012 SFBay 示例应用程序中有一个 custom erlang app startup code 的工作示例。