我正在关注此博客:http : //maplekeycompany.blogspot.se/2012/03/very-basic-cowboy-setup.html
简而言之,我正尝试像博客中的人一样使用rebar编译应用程序。一切顺利,直到我想运行命令:
./rebar get-deps compile generate
这会给我以下错误和警告,
> User@user-:~/simple_server/rebar$ ./rebar get-deps compile generate
> ==> rebar (get-deps)
> ==> rebar (compile) Compiled src/simple_server.erl Compiled src/simple_server_http.erl src/simple_server_http_static.erl:5:
> Warning: behaviour cowboy_http_handler undefined Compiled
> src/simple_server_http_static.erl
> src/simple_server_http_catchall.erl:2: Warning: behaviour
> cowboy_http_handler undefined Compiled
> src/simple_server_http_catchall.erl WARN: 'generate' command does not
> apply to directory /home/harri/simple_server/rebar Command 'generate'
> not understood or not applicable
我发现了类似的帖子,但有相同的错误:
我认为问题出在reltool.config中,但不知道如何继续,我将路径更改为以下内容:{lib_dirs,[“ home / user / simple_server / rebar”]}
路径有问题吗?钢筋如何获得对所有src文件以及必要的钢筋文件的访问权限,以编译和构建应用程序?
您需要确定目录结构及其内容的排列方式,以便钢筋知道如何在系统中构建所有内容并为其生成发行版。您的目录结构应如下所示:
project
|
-- rel
|
-- deps
|
-- apps
|
-- myapp
| |
| -- src
| -- priv
|
-- another_app
该rel
目录包含生成发行版所需的所有信息,该apps
目录是组成项目的应用程序所在的位置。应用程序依赖项位于deps
目录中。每个应用程序如myapp
和another_app
下apps
目录可以拥有自己的rebar.config
文件。尽管这里可以使用两个或多个这样的应用程序,但是通常您只有一个,而所有其他应用程序都是依赖项。
在顶级project
目录中,还有一个rebar.config
文件,其内容如下所示:
{sub_dirs, ["rel", "apps/myapp", "apps/another_app"]}.
{lib_dirs, ["apps"]}.
如有必要,您可以使用钢筋从应用程序框架生成应用程序:
cd apps
mkdir myapp another_app
( cd myapp && rebar create-app appid=myapp )
( cd another_app && rebar create-app appid=another_app )
如果应用程序具有依赖关系,则必须rebar.config
在其目录中添加一个,并在其中声明每个依赖关系。例如,如果myapp
依赖于应用程序foo
版本1.2,则apps/myapp/rebar.config
使用以下内容创建:
{deps,
[{foo, "1.*", {git, "git://github.com/user/foo.git", {tag, "foo-1.2"}}}]
}.
运行时rebar get-deps
,rebar将填充顶级deps
目录以容纳所有依赖项,并deps
在必要时进行创建。rebar.config
如有必要,顶层还可以声明依赖项。
您还需要生成发布所必需的节点:
cd ../rel
rebar create-node nodeid=project
然后,您需要修改reltool.config
上一步生成的文件。你需要改变
{lib_dirs, []},
到
{lib_dirs, ["../apps", "../deps"]},
并在该行之后{incl_cond, derived},
添加,{mod_cond, derived},
以便发行版仅包含正确执行所需的应用程序。
接下来,无论原子'project'
出现在何处,都需要将其替换为apps
目录下的应用程序。对于我们的示例,我们将更改此部分:
{rel, "project", "1",
[
kernel,
stdlib,
sasl,
project
]},
对此:
{rel, "project", "1",
[
kernel,
stdlib,
sasl,
myapp,
another_app
]},
并更改此部分:
{app, project, [{mod_cond, app}, {incl_cond, include}]}
对此:
{app, myapp, [{mod_cond, app}, {incl_cond, include}]},
{app, another_app, [{mod_cond, app}, {incl_cond, include}]}
您可能还需要添加以下行:
{app, hipe, [{incl_cond, exclude}]},
排除hipe
应用程序,因为有时它会在发行版生成期间或尝试运行发行版时导致错误。首先尝试不使用它,但是如果您看到与hipe
生成发行版相关的错误,或者尝试运行生成的发行版导致此类错误,请添加它:
{"init terminating in do_boot",{'cannot load',elf_format,get_files}}
您需要添加它。
完成所有这些操作后,您现在可以执行以下操作:
rebar get-deps compile generate
并且您应该能够成功生成发行版。请注意,rebar generate
在顶层而不是在rel
目录中运行将导致这样的无害警告,您可以忽略此警告:
WARN: 'generate' command does not apply to directory /path/to/project
最后,您可以运行发行版。以下是通过交互式控制台运行它的方法:
$ ./rel/project/bin/project console
Exec: /path/to/project/rel/project/erts-6.2/bin/erlexec -boot /path/to/project/rel/project/releases/1/project -mode embedded -config /path/to/project/rel/project/releases/1/sys.config -args_file /path/to/project/rel/project/releases/1/vm.args -- console
Root: /path/to/project/rel/project
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]
Eshell V6.2 (abort with ^G)
([email protected])1>
或者您可以运行./rel/project/bin/project start
在后台启动它。./rel/project/bin/project
不带参数运行以查看所有可用选项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句