After we have finished writing a set of functional modules (in Erlang, in module), we always want this set of modules to be packaged into an application, as a single whole that can be started, stopped, like Mnesia. And can be referenced in other applications. How to do that. Each application is started with the Application:start series function, and Application:stop can stop an application.
An application needs an. app file to describe it, mainly describing what files, parameters, etc. it includes.
If you start an app when you start an Erlang VM, in fact, there is no way to start a custom application directly with the parameters of the VM, some parameters such as: START_SASL can launch some internal standard build-in applications, but we can give the VM an execution portal, This is like the C language or the Java language main function, when the VM starts, execute the entry point of the program, so that you can start the application in this portal operation.
This entry point is specified by the parameter-S. Let's look at an example:
1. Erl-s Erlycomet_demo
This parameter specifies that after the VM is started, the Erlycomet_demo:start () parameterless function is called
2. In the Erlycomet_demo:start () function, we write the following code:
Application:start (Erlycomet_demo).
Above this sentence, start a erlycomet_demo application, here, the VM will find in the search directory Erlycomet_demo.app this file, if not, error, if found, then follow the instructions in this file to start the Erlycomet_demo application. This section can refer to the relevant documentation, simple, in the Erlycomet_demo with a parameter {mod,{mod_name_app,[]}}
This parameter indicates that the function is called Mod_name_app:start (_type,argu). Take Erlycomet_demo as an example, this call goes into Erlycomet_demo_app:start (_type,argu),
3. In Erlycomet_demo_app start (_type,argu), start a supervisor process to start the child process. As shown below:
Erlycomet_demo_sup:start_link (Args).
Now that we've packaged the app through application, how can we share the app?? For example, how do we use the function of application 2 in application a?? The promise is: to use the application as a unit for the reference, for example: if we want to mnesia function, I will call Mnesia:start () or in the application of a application specified, to start Mnesia. In OPT, there are many applications that are independent and mutually quoted. For example: Mnesia, Crpyto,inet and so on.
Create application for Erlang