Mochiweb: Include and compile other libraries

北城余情 提交于 2019-12-13 08:32:20

问题


My app uses Mochiweb.

I have noticed that Mochiweb files reside in the myapp/deps/mochiweb directory and rebar compiles them when I run make in the myapp directory.

I wanted to add ibrowse to write a few tests which make http requests to my app. So I cloned ibrowse from github to myapp/deps/ibrowse directory.

But it seems that Erlang does not know where to get the .beam files for ibrowse and therefore all my tests that use the ibrowse module fail:

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

How can I make my Mochiweb-based app use other Erlang/OTP external libraries?

Should I edit rebar.config or Makefile for that? Or maybe I should edit an _app.src file?

Edit: Maybe I should edit the list of directories in the myapp_sup.erl file? (myapp_deps:local_path(["priv", "www"])

P.S. How does my app know where all the mochiweb.beam files reside? (for example, the generic myapp_web.erl uses a call to mochiweb_http module, but there is no mochiweb_http.beam in the myapp/ebin directory).


回答1:


Dependencies in rebar are added via the rebar.config file:

%% 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"}}}]}.

Then, you probably want to look at Erlang releases and release handling with rebar. Think to a release as a way of grouping applications.

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:


Adding the following code to myapp_web.erl solved my problem:

ibrowse:start()

By default Mochiweb is started in the same function:

mochiweb_http:start()...

I am not sure if it the proper way to do this, but it works.



来源:https://stackoverflow.com/questions/10639051/mochiweb-include-and-compile-other-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!