At first, I had to manually create several modules when writing the application. Recently I found a good thing Basho-rebar. Using rebar to create an application can automatically generate three files:
Lqg_app.erl
Lqg_sup.erl
LQG. App. SRC
Then, add the personal logic business, and an application will soon be released ......
Specific practice: ====== here Basho-Lager (Erlang's log application) is used as an instance.
1. Create an application folder (a simple step)
mkdir lapp
2. Go to the created application folder and download the rebar file.
cd lapp/wget http://cloud.github.com/downloads/basho/rebar/rebar && chmod u+x rebar
3. Use rebar to create an application
./rebar create-app appid=lager
This shows that three files are generated under the path Lapp/src /.
lqg@lqg:~/lapp$ ./rebar create-app appid=lager==> lapp (create-app)Writing src/lager.app.srcWriting src/lager_app.erlWriting src/lager_sup.erl
4. Because lager has dependent applications, we need to solve this problem. Here we can use the rebar configuration file to complete automatic download of dependencies. Of course, the premise is that the configuration file rebar. config has been written.
Here, the rebar. config content is as follows:
{erl_opts, [debug_info]}.{deps, [ {lager_amqp_backend, ".*", {git, "https://github.com/jbrisbin/lager_amqp_backend.git", "master"}}, {amqp_client, ".*", {git, "https://github.com/jbrisbin/amqp_client.git", {tag,"rabbitmq_2.7.0"}}}]}.
Run./Rebar get-deps to download the dependency. The path is Lapp/deps /*
lqg@lqg:~/lapp$ ./rebar get-deps==> lapp (get-deps)Pulling lager_amqp_backend from {git,"https://github.com/jbrisbin/lager_amqp_backend.git", "master"}Cloning into 'lager_amqp_backend'...Pulling amqp_client from {git,"https://github.com/jbrisbin/amqp_client.git", {tag,"rabbitmq_2.7.0"}}Cloning into 'amqp_client'...==> Entering directory `/home/lqg/lapp/deps/lager_amqp_backend'==> Entering directory `/home/lqg/lapp/deps/amqp_client'==> amqp_client (get-deps)Pulling rabbit_common from {git,"git://github.com/jbrisbin/rabbit_common.git", {tag,"rabbitmq_2.7.0"}}Cloning into 'rabbit_common'...==> Entering directory `/home/lqg/lapp/deps/rabbit_common'==> rabbit_common (get-deps)==> Leaving directory `/home/lqg/lapp/deps/rabbit_common'==> Leaving directory `/home/lqg/lapp/deps/amqp_client'==> lager_amqp_backend (get-deps)Pulling lager from {git,"https://github.com/basho/lager.git",{tag,"0.9.4"}}Cloning into 'lager'...==> Entering directory `/home/lqg/lapp/deps/lager'==> lager (get-deps)==> Leaving directory `/home/lqg/lapp/deps/lager'==> Leaving directory `/home/lqg/lapp/deps/lager_amqp_backend'
5. At this time, the test code is basically completed. You can write test. erl at will.
-Module (test ). -compile ([{parse_transform, lager_transform}]). % lager compilation requirements-Export ([t/0]). T ()-> lager: Info ("LQG ").
6. Compile after the files are ready. makefile is not required for compilation here. You can use rebar to execute./Rebar compile.
7. Start ERL for testing
erl -sname lqg -pa ebin/ -pa deps/*/ebin/
Add startup command parameters and include dependencies together...
LQG @ LQG :~ /Lapp $ Erl-sname LQG-pa Ebin/-pa deps/*/Ebin/Erlang r15b01 (erts-5.9.1) [Source] [64-bit] [SMP: 2: 2] [async-threads: 0] [hipe] [kernel-Poll: false] eshell v5.9.1 (abort with ^ g) (LQG @ LQG) 1> application: start (compiler ). % This is the dependent application of lager. You need to start it first. OK (LQG @ LQG) 2> application: Start (syntax_tools ). % same as OK (LQG @ LQG) 3> application: Start (lager ). ok16: 39: 31.020 [info] Application lager started on node LQG @ LQG (LQG @ LQG) 4> test: T (). 16:39:39. 491 [info] LQG % log output OK (LQG @ LQG) 5>
Looking back, it's easy to publish an application =. =
Here, by the way, some features of lager
1. Six log levels are defined internally: Debug <info <notice <warning <error <critcal <alert <emergency
2. Support Dynamic Setting of log output level lager: set_loglevel/2, set_loglevel/3
3. Support for log summary lager_amqp_backend