如何将 Webmachine 集成到 Erlang 应用程序中?
我读了一遍又一遍的文档和教程,但我对如何创建 Erlang 应用程序和 Rebar 的理解仍然有足够的漏洞,就像瑞士奶酪一样。非常简单的东西让我困惑。
我正在努力开发一个 Erlang 版本,最终将包括我自己的几个应用程序以及 Webmachine,也许还有一种或另一种风格的 nosql 数据库。使用 Rebar,我成功编译并测试了我的应用程序:ZZZ 和 ZZZ_Lib。我的目录结构如下所示。我不确定它是否是最佳的,但它确实有效。
我已将 Webmachine 安装在 ...learn1/apps 目录下。
我的下一步是将 Webmachine 与非常简单的 webmachine_demo_resource 集成,如下所示,名称为 test_resource:erl。
http://webmachine.basho.com/example_resources.html
但是当我尝试编译时,我收到此错误消息:
src/test_resource.erl:3: can't find include lib "webmachine/include/webmachine.hrl"
这是 test_resource.erl 中的违规行:
-include_lib("webmachine/include/webmachine.hrl").
我尝试设置ERL_LIBS(我不完全理解)和 PATH 都没有成功。所以,显然,我不明白如何设置正确的路径或如何最好地集成 Webmachine。
任何和所有指导将不胜感激。
LRP
* 目录结构
learn1$ ls apps rebar rebar.config
learn1/apps$ ls webmachine zzz zzz_lib
learn1/apps/zzz_lib/src$ ls yada yada test_resource.erl yada yada
* rebar.config
{sub_dirs,
["apps/zzz",
"apps/zzz/src",
"apps/zzz_lib",
"apps/zzz_lib/src"
]
}.
* zzz_lib.app.src
{application, zzz_lib,
[
{description, ""},
{vsn, "1"},
{modules, [
yada yada
]},
{applications, [
kernel,
stdlib,
webmachine
]},
{mod, { zzz_lib_app, []}},
{env, []}
]}.
I read and re-read the docs and tutorials, but my understanding of how to create Erlang Applications, and Rebar for that matter, still has enough holes to resemble Swiss cheese. Very simple stuff throws me.
I'm working toward an Erlang Release that will eventually include several applications of my own plus Webmachine and maybe a nosql db of one flavor or another. Using Rebar I've successfully compiled and tested my applications: ZZZ and ZZZ_Lib. my directory structure is shown below. I'm not confident that it's optimal, but it works.
I've installed Webmachine under the ...learn1/apps directory.
My next step has been to integrate Webmachine with the very simple webmachine_demo_resource shown below under the name test_resource:erl.
http://webmachine.basho.com/example_resources.html
But when I try to compile, I get this error message:
src/test_resource.erl:3: can't find include lib "webmachine/include/webmachine.hrl"
Here's the offending line in test_resource.erl:
-include_lib("webmachine/include/webmachine.hrl").
I've tried to set both ERL_LIBS (which I don't fully understand) and PATH with no success. So, clearly, I don't understand how to set the proper path or how best to integrate Webmachine.
Any and all guidance would be gratefully welcomed.
LRP
* Directory structure
learn1$ ls
apps rebar rebar.config
learn1/apps$ ls
webmachine zzz zzz_lib
learn1/apps/zzz_lib/src$ ls
yada yada test_resource.erl yada yada
* rebar.config
{sub_dirs,
["apps/zzz",
"apps/zzz/src",
"apps/zzz_lib",
"apps/zzz_lib/src"
]
}.
* zzz_lib.app.src
{application, zzz_lib,
[
{description, ""},
{vsn, "1"},
{modules, [
yada yada
]},
{applications, [
kernel,
stdlib,
webmachine
]},
{mod, { zzz_lib_app, []}},
{env, []}
]}.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能最终会更高兴将其作为依赖项包含在内,而不是作为包含的应用程序。例如,请参阅 Riak Core 如何做到这一点: https://github.com/basho/ riak_core/blob/master/rebar.config
要获得更多见解,您可能会发现询问邮件列表是值得的:
http://lists.therestfulway.com/mailman/listinfo/webmachine_lists.therestfulway.com
http://lists.basho.com/mailman/listinfo/rebar_lists.basho.com
You most likely will end up happier including it as a dependency, not as a contained app. See for example how Riak Core does it: https://github.com/basho/riak_core/blob/master/rebar.config
For more insight, you might find asking the mailing lists to be worthwhile:
http://lists.therestfulway.com/mailman/listinfo/webmachine_lists.therestfulway.com
http://lists.basho.com/mailman/listinfo/rebar_lists.basho.com
在您的情况下使用
ERL_LIBS
,您需要将其设置为/.../learn1/apps
。编译时,还可以添加 {i, Dir} 选项。
然而,根据 文档,它只提到 -include 和 -include_dir,而不是 - include_lib。
Using
ERL_LIBS
in your case, you'd need to set it to/.../learn1/apps
.When compiling, you may also add a {i, Dir} option.
According to the documentation however, it only mentions -include and -include_dir, not -include_lib.