我创建了一个Erlang应用程序,一个小的calendar_server。哪些插入事件,检索它们以及编辑和删除事件。它在提示符上运行时正常工作(使用erl)。我插入了事件(生日,会议等),然后在目录上创建了数据库( Mnesia.nonode@nohost )。并且可以检索事件。但是当使用rebar / rebar3创建相同的应用程序时,不会创建任何数据库。我真的很想知道我遇到了什么问题,或者我做了什么错误。
下面给出了reltool.config和calendarApp.app.src ..
reltool.config
{sys, [
{lib_dirs, ["../apps"]},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "calendarApp", "1",
[
kernel,
stdlib,
sasl,
mnesia,
calendarApp
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
{boot_rel, "calendarApp"},
{profile, embedded},
{incl_cond, exclude},
{excl_archive_filters, [".*"]}, %% Do not archive built libs
{excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
"^erts.*/(doc|info|include|lib|man|src)"]},
{excl_app_filters, ["\.gitignore"]},
{app, sasl, [{incl_cond, include}]},
{app, stdlib, [{incl_cond, include}]},
{app, kernel, [{incl_cond, include}]},
{app, mnesia, [{incl_cond, include}]},
{app, calendarApp, [{incl_cond, include}]}
]}.
{target_dir, "calendarApp"}.
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/calendarApp", "bin/calendarApp"},
{copy, "files/calendarApp.cmd", "bin/calendarApp.cmd"},
{copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
{copy, "files/install_upgrade.escript", "bin/install_upgrade.escript"},
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
]}.
calendarApp.app.src
{application, calendarApp,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib,
mnesia
]},
{mod, { calendarApp_app, []}},
{env, []}
]}.
如果有人知道为什么没有创建数据库,请帮我找出错误。
答案 0 :(得分:1)
要创建基于光盘的Mnesia,您可以使用mnesia:create_schema/1
函数(我认为您在代码中的某处)。此功能要求Mnesia 停止。
在您reltool.config
应用程序之前的mnesia
calendarApp
应用程序中,您可能在该应用程序中创建了基于mnesia光盘的架构。这意味着mnesia在创建模式之前就已启动,因此无法创建模式。
如果您更改了mnesia
文件中calendarApp
键下的rel
和reltool.config
的顺序,那么一切都应该正确。
{sys, [
{lib_dirs, ["../apps"]},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "calendarApp", "1",
[
kernel,
stdlib,
sasl,
calendarApp,
mnesia
]},
...
答案 1 :(得分:0)
是的,我首先启动了myApp(dumperl_sync):
{relx, [{release, { dumperl_sync, "0.1.0" },
[dumperl_sync,
sasl,
mnesia
]},
...
}.
然后,在应用程序行为中:
start(_Application, _Type) ->
application:set_env(mnesia, dir,"/path/to/Mnesia.node"),
mnesia:create_schema([node()])
...
end.
然后,在handle_info中的gen_server行为中:
handle_info(_, State) ->
mnesia:start(),
mnesia:create_table(dates,
[
{disc_only_copies, [node()]},
{attributes,record_info(fields, dates)}
]
)
....
{noreply, State}.
日期是一个记录:
-record(dates,{}).
一切都应该是正确的!