Create an application for Erlang

Source: Internet
Author: User

Reprinted: http://www.cnblogs.com/samis/articles/1770029.html

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 mnesia. And can be referenced in other applications. How can we achieve this. Each application is started through the Application: Start series functions. Application: Stop can stop an application.

An application requires a. app file to describe the files and parameters it contains.

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 include: start_sasl can start some internal standard build-in applications, but we can give the VM an execution entry, just like the C language or the main function of the Java language. When the VM is started, execute thisProgramTo 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. Here, the VM will find the erlycomet_demo.app file in the search directory. If the file fails to be found, an error will be reported. If yes, follow the instructions in this file, start the erlycomet_demo application. For this part, see the relevant documentation. In simple terms, there is a parameter {mod, {mod_name_app, []} In erlycomet_demo.

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 ).

We have learned that 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 ?? The promise is: Reference is made by application. For example, if we want to use the mnesia function, I will call mnesia: Start () or specify it in the application of application, 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.