如何将 Webmachine 集成到 Erlang 应用程序中?

发布于 2024-12-04 23:08:29 字数 1518 浏览 1 评论 0原文

我读了一遍又一遍的文档和教程,但我对如何创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぇ气 2024-12-11 23:08:29

您很可能最终会更高兴将其作为依赖项包含在内,而不是作为包含的应用程序。例如,请参阅 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

眉黛浅 2024-12-11 23:08:29

在您的情况下使用ERL_LIBS,您需要将其设置为/.../learn1/apps

编译时,还可以添加 {i, Dir} 选项。
然而,根据 文档,它只提到 -include 和 -include_dir,而不是 - include_lib。

{i,Dir} 将 Dir 添加到要搜索的目录列表中
包括一个文件。当遇到 -include 或 -include_dir 时
指令,编译器在以下位置搜索头文件
目录:

“.”,文件服务器当前工作目录;

编译文件的基本名称;

使用 i 选项指定的目录。指定的目录
首先搜索最后一个。

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.

{i,Dir} Add Dir to the list of directories to be searched when
including a file. When encountering an -include or -include_dir
directive, the compiler searches for header files in the following
directories:

".", the current working directory of the file server;

the base name of the compiled file;

the directories specified using the i option. The directory specified
last is searched first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文