I am new to Erlang world and currently can't figure out how to start my dummy erlang application. Probably, I am just missing something... So, I created an application with rebar (rebar create-app appid=dummys).
Currently I have
- rebar.config
- src/dummys.app.src
- src/dummys_app.erl
- src/dummys_sup.erl
I have found that in order to run an application during a development it is better to create an additional start method which should call application:start(module).
I added some basic logging to my start methods..
start() ->
error_logger:info_msg("Starting app(dev)..~n"),
application:start(dummys_app).
start(_StartType, _StartArgs) ->
error_logger:info_msg("Starting app..~n"),
dummys_sup:start_link().
If I try
erl -noshell -pa ebin -s application start dummys
erl -noshell -pa ebin -s application start dummys_app
there are no output..
If I try
erl -noshell -pa ebin -s dummys start
erl crashes with an error..
If I try
erl -noshell -pa ebin -s dummys_app start
it outputs just "Starting app(dev).." and that's all. But I also expect to see "Starting app.."
What I am missing or doing wrong??
And another question: How to add a new module to my dummy application correctly? For example I have an additional module called "dummys_cool" which has a "start" method. How to tell my application to run that "dummys_cool#start" method?
Thank you!
4条答案
按热度按时间lyfkaqu11#
For quick development, if you just want to ensure your appliction can start, start a shell, then start the application:
That will give you a clean indication of what is wrong and right without the shell bombing out after.
Since you're making an application to run, rather than just a library to share, you'll want to make a release. Rebar can get you most of the way there:
After you've compiled your application, you can create a release:
This will build a portable release which includes all the required libraries and even the erlang runtime system. This is put by default in the rel/ directory; in your case rel/dummys.
Within that directory there will be a control script that you can use to start, stop, and attach to the application:
a7qyws3x2#
Have a look at your
dummys.app.src
file. The meaning of all the directives is explained in the 'app' manpage , but the one I suspect is missing here ismod
, which indicates the name of your application callback module. So make sure that this line is present:The empty list in there will be passed as the
StartArgs
argument todummys_app:start/2
.To make a new module start along with your application, add it to the supervision tree in
dummys_sup:init
. This function should look something like:This is described in the 'supervisor' manpage , but basically this means that on startup, this supervisor will start one child process.
dummys_cool:start_link()
will be called, and that function is expected to spawn a new process, link to it, and return its process id. If you need more processes, just add more child specifications to the list.hfsqlsce3#
上面的代码将无法工作,因为将调用
application:start([dummys])
。详情请参考Erlang documentation。
对于你的案子,
jyztefdp4#
我遇到了这个问题,这是谷歌上的第一个答案。
如果使用rebar3,标准配置将包含一个
shell
命令,用于编译项目并打开shell: