It's easy to build your own app in Erlang, and you can customize the app yourself, but it's just a simple record of typical practices under Erlang.
That is to build the OTP application.
Build custom A application can be Xxx.app file, you can put the app file in config folder
Eg:config/gs.app
First look at the app file:
App files are all called application resource file
Used to specify the purpose of application && how to start ...
[CPP]View PlainCopy
- {application,"app name",
- [
- {description,"app description"},
- {VSN,"version number"},
- {ID, Id},%%app ID with Erl-id ID
- {Modules,[modules]},%%app contains the module that the SysTools module uses to generate script, tar files
- {maxp,num},%% Process Maximum value
- {Maxt,time},%%app run-time unit milliseconds
- {registered,[mod]},%% Specifies the app name module, SysTools is used to resolve name collisions
- {included_applictions, [xx]},%% Specifies the child app, loads only, but does not start
- {applictions,[xxxx]},%% launches your app before it starts, the app will start this list first
- {env,[xxxx]},%% Configure the app's env, you can use application:get_env to get
- {mod,{xxx,args}},%% Specifies the app launch module, parameters, corresponding to your app's application behavior
- {start_phases,[{xxx,xxx}]]%% Specifies some actions for the start phase, corresponding to the OTP application Start_phase function
- ]
- }
Customize the app files to your needs, here my app files are:
[CPP]View PlainCopy
- {
- Application, GS,
- [
- {description, "Just GS."},
- {VSN, "1.0a"},
- {modules, [Gs_app,gs_sup]},
- {registered, [Gs_sup]},
- {mod, {gs_app, []}},
- {APPLICTIONS,[KERNEL,STDLIB,SASL]},
- {env,[{author,"JJ"}]},
- {start_phases, []}
- ]
- }.
OK, next to the custom OTP application:
and put the code file under SRC.
[CPP]View PlainCopy
- %%src/gs_app.erl
- -module (Gs_app).
- -behaviour (application).
- -export ([start/2,start/0, STOP/1]).
- Start ()
- Application:start (GS).
- Start (_, [])
- Io:format ("GS start ... ~n"),
- {OK, Pid} = Gs_sup:start_link (),
- Io:format ("GS Main PID is ~p ~n", [PID]),
- {OK, Pid}.
- Stop (_state),
- Io:format ("GS stop ... ~n").
One of the gs_sup here is in the app registered module, a typical OTP in supervisor, of course, you can also implement a module ...
[CPP]View PlainCopy
- %%SRC/GS_SUP.ERL  
- -module (gs_sup) .
- -behaviour (supervisor).
- -export ([START_LINK/0,INIT/1]) .
-   
- start_link () ->
- supervisor:start_link ({local,? module}, ? Module, []).
-
-   
- init ([]) - >
- {ok, {
- {one_for_one, 3, 10 },
- []
- }}.
To do this, you can simply write a emakefile to implement Erl-make, and put the beam file
Output to Ebin folder
[CPP]View PlainCopy
- {["src/*"]
- , [
- {OutDir, "./ebin"}
- ]
- }.
OK, basically, in order to manage the need, you can simply write a script file to launch the app, under Windows
You can do this:
[CPP]View PlainCopy
- Start.bat
- CD config/
- Erl-pa. /ebin/-name [email protected]-setcookie abc-boot start_sasl-s gs_app start
- Cmd
Finally execute the bat file ...
The app is running and can be application:loaded_applications ().
[CPP]View PlainCopy
- GS start ....
- GS Main Pid is <0.48.0>
- =progress report==== 28-dec-2012::15:51:46 = = =
- Application:gs
- STARTED_AT: [Email protected]
- Eshell V5.9 (abort with ^g)
- ([email protected]) 1>
- Eshell V5.9 (abort with ^g)
- ([email protected]) 1> application:loaded_applications ().
- [{kernel,"ERTS CXC 138","2.15"},
- {SASL,"SASL CXC 138","2.2"},
- {GS,"just GS.","1.0a"},
- {stdlib,"ERTS CXC 138","1.18"}]
- ([email protected]) 2>
In this way, the simple app is complete ....
Of course, it's just a very, very simple app. Only the parent supervisor is implemented.
Build an app for Erlang