我一直在使用 rebar3 (3.15.0),只是为了让它与基本模板一起运行,并且在尝试运行一个简单的 Hello World 类型示例程序时遇到了问题。我从模板命令开始构建新版本:
rebar3 new release myfirstproj
。
当我运行
rebar3 shell
时工作正常,但在运行发布命令时出现以下错误: myfirstproj.cmd console
使用 rebar3 release
构建后。
我添加到基本模板中的唯一东西是主管中的
io:format("Hello world!")
。看起来下面的undef表明它找不到myfirstproj_app:start
函数..任何想法为什么它没有'不能在这里工作,但可以在 rebar3 shell 中工作?
OTP 23 [erts-11.0] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:30]
=CRASH REPORT==== 21-Apr-2021::22:39:52.740000 ===
crasher:
initial call: application_master:init/4
pid: <0.85.0>
registered_name: []
exception exit: {bad_return,
{{myfirstproj_app,start,[normal,[]]},
{'EXIT',
{undef,
[{myfirstproj_app,start,[normal,[]],[]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,277}]}]}}}}
in function application_master:init/4 (application_master.erl, line 138)
ancestors: [<0.83.0>]
message_queue_len: 1
messages: [{'EXIT',<0.85.0>,normal}]
links: [<0.83.0>,<0.44.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 376
stack_size: 28
reductions: 224
neighbours:
=INFO REPORT==== 21-Apr-2021::22:39:21.439000 ===
application: myfirstproj
exited: {bad_return,
{{myfirstproj_app,start,[normal,[]]},
{'EXIT',
{undef,
[{myfirstproj_app,start,[normal,[]],[]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,277}]}]}}}}
type: permanent
我的应用程序代码尚未从模板更改:
%%%-------------------------------------------------------------------
%% @doc myfirstproj public API
%% @end
%%%-------------------------------------------------------------------
-module(myfirstproj_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
myfirstproj_sup:start_link().
stop(_State) ->
ok.
%% internal functions
与我的 app.src 相同:
{application, myfirstproj,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, {myfirstproj_app, []}},
{applications,
[kernel,
stdlib
]},
{env,[]},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.
模板中的 rebar.config 尚未修改。
myfirstproj_sup.erl:
%%%-------------------------------------------------------------------
%% @doc myfirstproj top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(myfirstproj_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
start_link() ->
io:format("Hey, we started!"),
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
init([]) ->
SupFlags = #{strategy => one_for_all,
intensity => 0,
period => 1},
%ChildSpecs = [{worker1,
%{file_watcher, start_link, []}, permanent, 1000, worker, [file_watcher]}],
ChildSpecs = [],
{ok, {SupFlags, ChildSpecs}}.
%% internal functions
我在 Windows 上使用 rebar3 3.22.1 遇到了这个问题。使用默认设置(对生成的 rebar.config 没有更改)
rebar3 release
创建一个 dev 模式 版本,这意味着它会创建指向已编译文件的符号链接而不是复制它们,以便该版本自动使用您编译的任何更改(重新启动后,但不重新发布)。然而,事实证明这些符号链接在 Windows 下不能很好地工作。即使访问权限正确排序,运行 <releasename> console
或 <releasename> start
也会出现与 OP 描述的相同的错误 (undef releasename:start/2
)。
就我而言,通过将 rebar.config
修改为
{mod, prod}
(或 {dev_mode, false}
),有助于切换到 生产版本。进行此更改后,
<releasename> console
和 <releasename> start
都可以正常工作。