I have an Elixir app with two applications inside the lib/ folder:
myproject/lib/app1 myproject/lib/app2
They both have files which use Application:
myproject/lib/app1.exs myproject/lib/app2.exs
They each implement start
and spawn a supervision tree.
In myproject/mix.exs
I tried:
def application do
[
mod: {app1, []},
{app2, []},
applications: [:foo, :bar]
]
end
But all I get are syntax errors on the line with {app2, []}
.
Is such a thing even possible? If not, what is the right way to launch separate applications with supervision trees in Elixir?
You should add app2 as dependency of app1 and call it in applications, like:
mix.exs for app2:
#...
def application do
[
mod: {My.App2, []},
applications: [:logger]
]
end
defp deps do
[
...
]
end
#...
end
mix.exs for app1:
def application do
[
mod: {My.App1, []},
applications: [:logger, :my_app2]
]
end
defp deps do
[
{:my_app2, in_umbrella: true}
]
end
# ...
end
This is the case if both apps are in the same umbrella. If not, just add my_app2 as you would (from hex, path or git).
For more information on dependencies and umbrella projects, take a look @ http://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-apps.html
If it makes sense for app1 to be responsible for starting app2 then another option is to use Application.start(app2)
inside app1
where appropriate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.