创建OTP项目并且利用脚本运行

By AverageJoeWang
 标签:

一.创建的OTP命令(前提是要有rebar)

  • appname = erlangOTP
    #windows系统下
    rebar create-app appid = appname
    #linux系统下
    ./rebar create-app appid=appname
    

二.修改OTP使得能够在windows下用run运行

%%%-------------------------------------------------------------------
%%% @author Joe
%%% @copyright (C) 2016, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 21. 九月 2016 16:54
%%%-------------------------------------------------------------------
-module(erlangOTP).
-author("Joe").

%% API
-export([start/0, stop/0]).


start()->
  start_app(?MODULE).

stop()->
  application:stop(?MODULE).


-spec start_app(App :: atom()) -> Result when
  Result :: ok | {error, Error},
  Error :: term().
start_app(App) ->
  case application:start(App) of
    ok ->
      ok;
    {error, {already_started, App}} ->
      ok;
    {error, {not_started, Dep}} ->
      case start_app(Dep) of
        ok ->
          start_app(App);
        {error, Error} ->
          {error, Error}
      end;
    {error, Error} ->
      {error, Error}
  end.

三.用bat脚本运行

  • 创建一个run.bat脚本
call rebar compile
werl -name erlangOTP@127.0.0.1 -setcookie erlangOTP -pa ebin -s erlangOTP