Rebar is a follow ERLANG/OTP principle Erlang Project builder, using it to reduce the build standard ERLANG/OTP Project architecture configuration, and can be easily compiled, tested, published Span style= "font-family:arial; Background-color:white; " > Erlang application. More powerful, Provides a dependency management mechanism that makes it easy for developers to pass   Git,Hg Reuse common third-party Erlang module or library.
Installing rebar
You can download the zip package or the source code in https://github.com/rebar/rebar to compile it yourself.
There is a file bootstrap.bat under the root directory. Execute, you will generate two files Rebar.cmd and rebar These two files to be used in future project development. (BAT file execution, double-click or execute under CMD can, preferably have administrator permission.) )
Or you can copy these two files to a place where your system variables can access them, or add the paths you've generated to your own system variables. This way you can use the rebar command from anywhere.
Build a project with rebar
First you will create a working directory of your own. Then copy the two files you have just generated to your working directory, or if you have added system variables, you do not need one.
Here we create a work path D:\myapp, and then execute the following command to build an Erlang project with the project name called MyApp
Rebar Create-app Appid=myapp
This command creates a SRC folder and generates 3 files below:
- MYAPP.APP.SRC The resource description file for the application, which affects the content in the Rebarapp.app generated by the subsequent compilation
- Application behaviour code files for Myapp_app.erl applications
- Supervisor Behaviour code files for Myapp_sup.erl applications
The rebar also incorporates opt-related other document magic boards, which you can automatically generate with the appropriate framework code:
- Rebar Create Template=simplesrv Srvid=myapp_server
- Rebar Create TEMPLATE=SIMPLEFSM FSMID=MYAPP_FSM
- Rebar Create Template=simpleapp Appid=myapp_app
After execution, the corresponding magic plate file is generated in the SRC directory. Here gen_server corresponds to SIMPLESRV,GEN_FSM corresponding simplefsm,application corresponding Simpleapp, the corresponding magic plate ID is srvid,fsmid,appid respectively.
Compiling a project with rebar
You can use the following command to compile the entire project:
Rebar Compile
After compiling, a Ebin folder is generated that contains the application's resource file Myapp.app and the corresponding beam file.
Rebar clean can be used to clear the project of compiling and playing
Rebar Doc can use this command to generate the corresponding DOC document, will generate a Doc folder, open the inside of the index.html can see all the module API description, of course, you have to conform to the Edoc description format. Refer to here: http://www.erlang.org/doc/apps/edoc/chapter.html
Test project with rebar with Eunit
There is a rebar.config file under the Rebar folder where you can configure the Eunit option to test. First we copy the Rebar.config into our project directory. Then change the contents of the Rebar.config file into the following:
%%-*-Mode:erlang-*-
Percent Erlang Compiler options
{erl_opts, [Debug_info,
{i, "test"},
{src_dirs, ["SRC"]}]}.
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, '. '} '}}]}.
{cover_enabled, true}.
The above configuration will load the test file under the tests file, so we need to create a testing folder ourselves.
Then you generate the appropriate test case file. First we create a file Myapp_test.hrl test case file with the following content
-include_lib ("Eunit/include/eunit.hrl").
my_test ()
? assert (1 + 2 =:= 3).
simple_test ()
OK = Application:start (MyApp),
assertnot (undefined =:= whereis (myapp_sup)).
Then add the following code at the end of the Myapp_server.erl file:
-ifdef (TEST).
-include ("Myapp_test.hrl").
-endif.
If necessary, you need to add the above code to the file at the end of each module, and then execute the following command to perform the Eunit test:
Rebar Compile Eunit
If there is no problem, you should be able to see the following information, will tell you eunit test situation:
======================== Eunit ========================
Module ' Rebarapp_server '
Rebarapp_server:my_test...ok
Rebarapp_server:simple_test ... [0.015 S] Ok
[Done in 0.047 s]
Module ' MYFSM '
Module ' Myapp_sup '
Module ' Myapp_app '
=======================================================
All 2 tests passed.
Cover analysis:d:/mongodb/projects/.eunit/index.html
This way you can open the. eunit/index.html to view the test results.
Use rebar to publish apps
If you want to publish an app, we need to create a folder named Rel in the app directory, which is used as a folder for publishing. Then we go to the new Rel folder below and use the following command to create a separate Erlang VM node named MyApp:
Rebar Create-node Nodeid=myapp
Modify the value of the Lib_dirs in Rel/reltools.config, the default is an empty list, and change to the directory structure where the application is located. /.. /]"。
Then apply the root directory, add a line in the Rebar.config, the new Rel folder into the rebar can access subfolders, as the application content of the publishing folder:
{sub_dirs, ["Rel"]}
Then you need to compile the project:
Rebar Compile
If there are no errors, then you can publish them:
Rebar Generate
If no errors are found on the terminal, then it proves that the release was successful. We will be able to execute and test our release content. We will find a bunch of files generated under the Publishing folder, and a series of bat files are generated below Rel\myapp\bin to control and manipulate the application's condition, using the following:
MyApp [Install|uninstall|start|stop|restart|console|ping|query|attach|upgrade]
MyApp Install: A service will be installed to the local services so that the node will be able to execute when your computer starts up.
MyApp Uninstall: Uninstalling this service
MyApp start: Start service stop: Stop service restart: Restart Service
MyApp console: Used to start an Erlang shell to execute this node
The latter few are useless, and so on, I will add the content here.
Other platforms use rebar
Other platforms use rebar, in fact, the command is the same, but in the installation of a little bit different, there is the executable program is not the same. Everyone is interested in experimenting on their own.
Build, compile, test, and publish Erlang projects in Windows with rebar