Stuff Goes Bad:Erlang In Anger

OTP Applications

Figuring out OTP applications is usually rather simple. They usually all share a directory structure that looks like:

 搞清楚 OTP applications通常都非常简单,他们通常在同一个目录下, 目标结构如下:

doc/;
ebin/
src/
test/
LICENSE.txt
README.md
rebar.config

There might be slight differences, but the general structure will be the same. Each OTP application should contain an app file, either ebin/.app or more often, src/.app.src 2. There are two main varieties of app files:

具体的项目可能会有轻微差异,但通用结构都是一样的。 每个OTP application 会包含一个app文件,放在 ebin/.app 或更常见放在src/.app.src 2, 以下是2类app文件的结构:

library application:
{application, useragent, [
{description, "Identify browsers & OSes from useragent strings"},
{vsn, "0.1.2"},
{registered, []},
{applications, [kernel, stdlib]},
{modules, [useragent]}
]}.
regular application:
{application, dispcount, [
{description, "A dispatching library for resources and task "
"limiting based on shared counters"},
{applications, [kernel, stdlib]},
{registered, []},
{mod, {dispcount, []}},
{modules, [dispcount, dispcount_serv, dispcount_sup,
dispcount_supersup, dispcount_watcher, watchers_sup]}
]}.

[2] A build system generates the final file that goes in ebin. Note that in these cases, many src/.app.src files do not specify modules and let the build system take care of it.

[注2]:最终会用构建系统生成.app文件放到ebin/下,而且大部分的src/.app.src不会列模块列表,构建系统会自动加上去的。