Is there a way to run (the Erlang version of) Webmachine in an "embedded?" I want to embed the web app in an application I am writing. The web app will just be a front end communicating with a back end I am writing. I want everything (webmachine, mochiweb, custom web app, custom back end) in one code base, running on one virtual machine.
Thanks.
Rebar offers convenient ways to build application releases and manage their dependencies. As the subject is quite complex, I suggest you to have a look at the very good site learnyousomeerlang (I pointed the chapter about releases) to learn about the underlying method used by Rebar. You will need also to have a good knowledge about the way the applications are start in OTP.
In your case, the back-end is the application, all the other applications are dependencies.
[edit] I wouldn't say you have to build an application in Erlang. As there is no link, all the module simply have to be in the code/library search path when the VM need them. It is even possible to modify this path while running.
The OTP define a standard way to organize the different files, and the VM defines a way to organize the libraries. What rebar does, is to help you to create and maintain this organization for your application and the ones it depends on. It helps you to retrieve from repositories the application you need, and simplifies the build of the whole thing. So it helps you to distribute your application to other users/machines.
You can have a look at the webmachine code itself, since it uses rebar to build iteself and get the application it depends on (mochiweb, meck and ibrowse). Here is a copy of some file available at https://github.com/basho/webmachine under Apache License, Version 2.0. The rebar.config file which describes the dependencies and the "compilation" options:
%%-*- mode: erlang -*-
{erl_opts, [warnings_as_errors]}.
{cover_enabled, true}.
{edoc_opts, [{preprocess, true}]}.
{xref_checks, [undefined_function_calls]}.
{deps,
[{mochiweb, "1.5.1*", {git, "git://github.com/basho/mochiweb.git", {tag, "1.5.1p6"}}},
{meck, "0.8.1", {git, "git://github.com/basho/meck.git", {tag, "0.8.1"}}},
{ibrowse, "4.0.1", {git, "git://github.com/cmullaparthi/ibrowse.git", {tag, "v4.0.1"}}}
]}.
And here is the file webmachine.app.src which describes the application that should be running and the starting point of the application (webmachine_app:start/2)
%%-*- mode: erlang -*-
{application, webmachine,
[
{description, "webmachine"},
{vsn, git},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib,
crypto,
mochiweb]},
{mod, {webmachine_app, []}},
{env, []}
]}.
and finally the code which starts everything:
%% @author Justin Sheehy <justin@basho.com>
%% @author Andy Gross <andy@basho.com>
%% @copyright 2007-2008 Basho Technologies
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% @doc Callbacks for the webmachine application.
-module(webmachine_app).
-author('Justin Sheehy <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
-behaviour(application).
-export([start/2,
stop/1]).
-include("webmachine_logger.hrl").
%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for webmachine.
start(_Type, _StartArgs) ->
webmachine_deps:ensure(),
{ok, _Pid} = SupLinkRes = webmachine_sup:start_link(),
Handlers = case application:get_env(webmachine, log_handlers) of
undefined ->
[];
{ok, Val} ->
Val
end,
%% handlers failing to start are handled in the handler_watcher
_ = [supervisor:start_child(webmachine_logger_watcher_sup,
[?EVENT_LOGGER, Module, Config]) ||
{Module, Config} <- Handlers],
SupLinkRes.
%% @spec stop(_State) -> ServerRet
%% @doc application stop callback for webmachine.
stop(_State) ->
ok.