简体   繁体   English

我用Erlang和rebar构建了一个gen_server。 现在我该如何运行它?

[英]I've build a gen_server with Erlang and rebar. Now how do I run it?

Rebar included the framework, [blah]_sup.erl and so on. Rebar包括框架, [blah]_sup.erl等等。 I added my one external dependency to rebar.config . 我将一个外部依赖项添加到rebar.config I added a file to src/ , which is a gen_server that handles most of the work. 我在src/添加了一个文件,这是一个处理大部分工作的gen_server。 I've added that gen_server file to [blah]_sup.erl so the gen_server starts as a child, and starts when the app starts. 我已经将gen_server文件添加到[blah]_sup.erl因此gen_server作为子项启动,并在应用程序启动时启动。 Of course I've compiled everything with rebar compile . 当然我用rebar compile编译了所有东西。

What do I do now? 现在我该怎么做? I don't know how to start the app! 我不知道如何启动应用程序!

As Jr0 suggests in the comment you run: 正如Jr0在评论中建议的那样:

application:start(blah).

However, you need to make sure you add the dependency path first: 但是,您需要确保首先添加依赖关系路径:

code:add_patha("../deps/<dependency name goes here>/ebin").

and make sure it' started: 并确保它'开始:

{ok, _} = application:ensure_all_started(<dependency name goes here>).

Personally I tend to make a stand-alone module called blah.erl that does the above for me and just call that. 就个人而言,我倾向于创建一个名为blah.erl的独立模块,它为我做了上述操作并且只是调用它。

In your local instance, the easiest way is to just run: 在本地实例中,最简单的方法是运行:

rebar3 shell

This will run your application correctly. 这将正确运行您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM