Erlang program Packaging

Source: Internet
Author: User

After writing a set of functional modules (in Erlang, the unit is module), we always hope that this group of modules can be packaged into an application and can be started as a separate module, stop, like
Same as mnesia. And can be referenced in other applications. How can we achieve this. Every application is started through the Application: Start series functions.
Dynamic, application: Stop can stop an application.
An application requires a. app file to describe the files and parameters it contains.
For example
If an application is started when the Erlang VM is started, in fact, we cannot directly start a custom application using VM parameters. Some parameters such as start_sasl can
Start some internal standard build-in applications, but we can give the VM an execution entry, which is like the main function in C or Java language. When the VM is started, execute this process
In order to start the application.

This entry point is specified by the-S parameter. Here is an example:

1. Erl-s erlycomet_demo
This parameter is specified. After the VM is started, the erlycomet_demo: Start () function is called without parameters.

2. In the erlycomet_demo: Start () function, we write the following:Code:
Application: Start (erlycomet_demo ).

In the above sentence, start an erlycomet_demo application. In this case, the VM will find the erlycomet_demo.app file in the search directory. If the file fails, an error is reported.
If yes, start the erlycomet_demo application according to the instructions in this file. For more information about this part, see the relevant documentation. It is simple to use in erlycomet_demo.
There is a parameter {mod, {mod_name_app, []}.
This parameter indicates that the mod_name_app: Start (_ type, argu) function is called. Take erlycomet_demo as an example. This call enters erlycomet_demo_app: Start (_ type, argu,

3. In start (_ type, argu) of erlycomet_demo_app, start a supervisor process and then start the process. As follows:
Erlycomet_demo_sup: start_link (ARGs ).

Now
Solution: We use application as the unit to package the application. How can we share the application ?? For example, how do we use the function of Application 2 in application ?? Yes:
The application is referenced in units. For example, if we want to use the mnesia function, I will call mnesia: Start () or specify in the application of application a to start
Mnesia. In OPT, many applications are independent and referenced. For example, mnesia, crpyto, and inet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.