【问题标题】:Mochiweb: Include and compile other librariesMochiweb:包含和编译其他库
【发布时间】:2012-05-25 05:26:08
【问题描述】:

我的应用使用 Mochiweb。

我注意到 Mochiweb 文件位于 myapp/deps/mochiweb 目录中,当我在 myapp 目录中运行 make 时,rebar 会编译它们。

我想添加 ibrowse 来编写一些向我的应用发出 http 请求的测试。于是我将ibrowse从github克隆到myapp/deps/ibrowse目录下。

但似乎 Erlang 不知道从哪里获取 ibrowse.beam 文件,因此我所有使用 ibrowse 模块的测试都失败了:

myapp
 ebin %%compiled tests reside here, tests which use ibrowse fail (badarg)
 deps
  mochiweb 
  ibrowse
   ebin %%compiled ibrowse module resides here
 src
 tests

如何让基于 Mochiweb 的应用使用其他 Erlang/OTP 外部库?

我应该为此编辑 rebar.config 或 Makefile 吗?或者我应该编辑一个 _app.src 文件?

编辑:也许我应该编辑 myapp_sup.erl 文件中的目录列表? (myapp_deps:local_path(["priv", "www"])

附:我的应用程序如何知道所有 mochiweb.beam 文件所在的位置? (例如,通用的myapp_web.erl 使用了对mochiweb_http 模块的调用,但myapp/ebin 目录中没有mochiweb_http.beam)。

【问题讨论】:

    标签: makefile erlang erlang-otp mochiweb rebar


    【解决方案1】:

    rebar 中的依赖项是通过 rebar.config 文件添加的:

    %% What dependencies we have, dependencies can be of 3 forms, an application
    %% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
    %% an application name, a version and the SCM details on how to fetch it (SCM
    %% type, location and revision). Rebar currently supports git, hg, bzr and svn.
    {deps, [application_name,
            {application_name, "1.0.*"},
            {application_name, "1.0.*",
             {git, "git://github.com/basho/rebar.git", {branch, "master"}}}]}.
    

    然后,您可能想查看 Erlang 版本和使用 rebar 的版本处理。将发布视为分组应用程序的一种方式。

    http://www.erlang.org/doc/design_principles/release_handling.html

    http://learnyousomeerlang.com/release-is-the-word

    https://github.com/basho/rebar/wiki/Release-handling

    【讨论】:

      【解决方案2】:

      将以下代码添加到 myapp_web.erl 解决了我的问题:

      ibrowse:start()
      

      默认情况下,Mochiweb 以相同的功能启动:

      mochiweb_http:start()...
      

      我不确定这是否是正确的方法,但它确实有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-15
        • 1970-01-01
        • 1970-01-01
        • 2016-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多