I'm building a system that needs to use a previously built OTP application (lets call it X). If I want to build a new OTP application / module, how can I use the application that already exists from a module, for instance?
I assumed I could call start
, since it follows the application
behaviour, and so I built a minimalistic application Y that has the following code:
y.erl:
-module(y).
-behaviour(application).
start(_StartType, _StartArgs) ->
io:format("going to call x_app~n"),
{ok, _} = x_app:start([]),
io:format("called x_app~n"),
y:start_link().
stop(_State) ->
ok = x_app:stop([]),
ok.
Rebar compiles this code successfully and generates no warnings.
rel/y/bin/y start
outputs nothing at all (I hoped to get the output of at least one io:format
)
rel/y/bin/y stop
outputs Node is not running!
You need to list application
x
as a dependent application in your application's.app
resource file, or since you're usingrebar
, in your.app.src
file:Note in the very last line that
x
is listed as an application dependency. This results in the Erlang application controller ensuring thatx
is started before it starts your application. And if you're starting your application interactively in an Erlang shell viaapplication:ensure_all_started/1,2
this declaration will ensure thatx
is started first before your app starts.