Compiling and building a project with rebar

Source: Internet
Author: User

Reprinted: http://wiki.erlang-web.org/Rebar

Getting Erlang Web

Before you start, you have to prepare the project directory, and get Erlang Web framework as a dependency.

1. Add a dependency to Erlang web in rebar. config file in your project directory.

{lib_dirs,["deps"]}.{deps, [{'erlang-web', ".*", {git, "git://github.com/esl/erlang-web.git", "rebar"}} ]}.

2. Get project Dependencies

    ./rebar get-deps

Compiling

Before you will be ready to use the framework for the first time, you shoshould compile it.

To do so be sure to have all dependencies, Erlang (base or hype) Erlang-inets, yaws and the Erlang tools, on most packaged distributions they are usually a set of different packages. most of compiling errors are because of missing Erlang
Packages.

1. Add all additional applications to the Section sub_dirs in rebar. config file

{sub_dirs,[    "apps/myapp"]}.

2. compile the project

    ./rebar compile

You shoshould run that command every time you change something in your project.

Building

1. Copy the reltool. config. sample script from Erlang-web directory in deps to the main directory as reltool. config

In reltool. config. sample it is assumed that you store all your dependencies in deps directory, if it's name is different you will have to change appropriet paths

Erlang Web Framework supports now the two main servers implemented in Erlang: inets and yaws. By default it uses inets. To change that switchInetsToYawsInReltool. config.

2. Add project specific applications to the rel tuple in reltool. config file

{sys, [       {lib_dirs, ["apps", "deps", "deps/erlang-web/apps"                  ]},       {rel, "trace-this", "1.0",        [         %% Required applications         ...                  %% Project specific applications                  myapp        ]},

And an app tuple

 {app, myapp, [{incl_cond, include}]}

3. Add copy directive to move project specific configuration files (like dispatch. conf) and templates

           {copy, "apps/myapp/priv/config"},           {copy, "apps/myapp/priv/docroot"},           {copy, "apps/myapp/priv/templates"}

4. Run the following command every time you want to upgrade your project

    ./rebar generate force=1

It will build the project inRELDirectory. Option force = 1 makes rebar ignore the fact that the @ rel @ directory exists, and lets you upgrade your project.

Results

Rebar prepares the structureRELDirectory, that is your project built direcotory:

  • Creates the mandatory directories for the Erlang Web framework, including:

    • Bin
    • Config
    • Docroot
    • Lib
    • Log
    • Pipes
    • Releases
    • Templates
  • Copies the binary executables:
    • Heart
    • Run_erl
    • To_erl
    • ERTs directory
  • Copy start scripts for both: Interactive and embedded Mode
  • CreatesStart_erl.dataConfiguration File

  • Prepare sample framework configuration files (or copy project specific ones ):
    • Dispatch. conf
    • Errors. conf
    • Project. conf
  • Builds simple welcome, 404 and 501 error pages
  • Copies the required AutoComplete wpart files
  • Creates. Rel and SYS. config files
  • Generates boot file
Creating skeleton for a new application in the project

1. Copy '''templates''' directory from Erlang web to Maint project directory

    cp -r deps/erlang-web/templates ./

2. Run

    ./rebar create template=add [app_name=newapp] [app_vsn=0.1]

It puts a template structure for the new application inAppsDirectory

Warning: Rebar looks for template add through all of Project dependencies, and returns an error, bacause it doesn't find it. To solve it commentDepsAndSub_dirsSections
InRebar. config

Running the project

To start the server run inRELDirectory:

    bin/start

Or

    bin/start_interactive

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.