Erlang: how can I automatically start all necessary applications to app?

You can either issue a series of -eval "application:start(coucnbeam)" commands to erl, or do it the proper OTP way and use reltool to generate a new boot file for you.

See info on reltool, also rebar does an excellent job at doing much of the heavy lifting for you so you might want to look into rebar3.

There is also a great chapter, from LYSE, on making releases.


If you are just messing around in the console and want to not have to type in all these 'application:start(...).' lines, just put these things in the .erlang file in your current working directory. Here's an example for what I'm working on right now:

$ cat .erlang 
application:start(crypto).
application:start(public_key).
application:start(ssl).
application:start(ibrowse).
application:start(foo).

This starts all my dependencies, and then the app I'm working on right now, foo.


If you want to generate a reltool release with rebar, this link might help:

When to use erlang application:start or included_applications and a supervisor?

Specifically, this gist:

https://gist.github.com/3728780

-Todd


In your application callback module, just write:

-module(st_db_app).
-behaviour(application).
-export([start/2, stop/1]).

start(_StartType, _StartArg) ->
    %% Get application name
    {ok, AppName} = application:get_application(),
    %% Start all dependencies that are not yet started for application name
    {ok, _StartedApps} = application:ensure_all_started(AppName),
    %% start application's root supervisor or do other initialization here
    %% and return root supervisor's pid.

Tags:

Erlang