The Application Specification File
Understand the application specification file in Elixir.
We'll cover the following
So far in our quick tour of Elixir and OTP, we’ve looked at server processes and the supervisors that monitor them. There’s one more stage in our journey: the application.
A different kind of application
Because OTP comes from the Erlang world, it uses Erlang names for things. And unfortunately, some of these names aren’t terribly descriptive. The name application is one of these. When most of us talk about applications, we think of a program we run to do something, maybe on our computer or phone or via a web browser. An application is a self-contained whole.
But in the OTP world, that’s not the case. Instead, an application is a bundle of code that comes with a descriptor. That descriptor tells the runtime what dependencies the code has, what global names it registers, and so on. In fact, an OTP application is more like a dynamic link library or a shared object than a conventional application.
It might help to see the word application in our head but think of it as a component or service.
For example, back when we were fetching GitHub issues using the HTTPoison library, what we actually installed was an independent application containing HTTPoison. Although it looked like we were just using a library, mix
automatically loaded the HTTPoison application. When we then started it, HTTPoison started a couple of other applications that it needed (SSL and Hackney), which in turn kicked off their own supervisors and workers. And all of this was unseen by us.
We’ve said that applications are components, but some applications are at the top of the tree and are meant to be run directly. In this chapter, we’ll look at both types of application components. In reality, they’re virtually the same, so let’s cover the common ground first.
Application specification file
We probably noticed that every now and then, mix
will talk about a file called name.app
, where name
is our application’s name.
This file is called an application specification and is used to define our application to the runtime environment. Mix creates this file automatically from the information in mix.exs
combined with information it gleans from compiling our application.
When we run our application, this file is consulted to get things loaded. Our application doesn’t need to use all the OTP functionality. This file will always be created and referred to. However, once we start using OTP supervision trees, stuff we add to mix.exs
will get copied into the .app file
.
Get hands-on with 1400+ tech skills courses.