我尝试获取用于打印的vsn信息。但返回值是[]。
app文件如下:
{application,john,
[{description,[]},
{vsn,"0.1.2.3"},
{registered,[john]},
{applications,[kernel,stdlib]},
{mod,{john_app,[]}},
{env,[]},
{modules,[john_app,john_basic_rule,john_basic_sup,john_client,
john_cookie,john_env,john_file,john_framing_0_0_1,
john_framing_tests,john_group_sup,john_guid,john_ldap,
john_ldap_tests,john_local_message,john_log,
john_log_tests,john_message,john_mnesia,john_model,
john_rabbitmq,john_reader,john_reader_2_sup,
john_reader_sup,john_reader_tests,john_reader_tests_2,
john_store,john_store_tests,john_sup,john_upgrade,
john_version,john_worker,john_worker_tests]}]}.
xxx_app.erl文件如下:
start(normal, []) ->
lager:md(?OP_ST),
lager:debug("john_app_start_1"),
case erts_version_check() of
ok ->
lager:debug("john_start_2"),
try
%% 是否需要启动john_sup依赖的服务器??
true = register(john, self()),
[ok = run_boot_step(Step) || Step <- boot_steps()],
{ok,Sup_pid} = john_basic_sup:start_link(),
ok = john_basic_sup:start_basic(),
print_banner(),
{ok, Sup_pid}
catch Error_a:Reason_a->
lager:error("john_app_start_normal_3:~p,~p,~n~p",
[Error_a,Reason_a,erlang:get_stacktrace()]),
Reason_a
end;
Error ->
lager:error("john_start_error:~p",[Error]),
Error
end.
print_banner() ->
{ok, Product} = application:get_key(john,id),
{ok, Version} = application:get_key(john,vsn),
ProductLen = string:len(Product),
lager:info("~n"
"john--------------~n"
"~s~n~s~n~s~n~s~n~s~n",
[Product, string:right([$v|Version], ProductLen),
?PROTOCOL_VERSION,
?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]),
然后我尝试了application:get_all_key(),然后返回[]。
为什么?
我尝试了application:loaded_applications()
和application:get_all_keys()
。但结果不是预期的:
(zarah_john_slave_21@yus-iMac.local)3> application:loaded_applications().
[{goldrush,[],"0.1.0"},
{kernel,"ERTS CXC 138 10","2.16.2"},
{lager,"Erlang logging framework","2.0.0"},
{friar,[],"0.1.2"},
{amqp_client,"RabbitMQ AMQP Client","2.8.2"},
{mnesia,"MNESIA CXC 138 12","4.9"},
{inets,"INETS CXC 138 49","5.9.5"},
{john,[],"0.1.2.3"},
{jotham,"pgsql jacob install","0.1.1"},
{sasl,"SASL CXC 138 11","2.3.2"},
{stdlib,"ERTS CXC 138 10","1.19.2"}]
(zarah_john_slave_21@yus-iMac.local)4> application:get_all_key().
[]
(zarah_john_slave_21@yus-iMac.local)5>
我尝试了应用程序:get_all_key(john)。
{ok,[{description,[]},
{id,[]},
{vsn,"0.1.2.3"},
{modules,[john_app,john_basic_rule,john_basic_sup,
john_client,john_cookie,john_env,john_file,
john_framing_0_0_1,john_framing_tests,john_group_sup,
john_guid,john_ldap,john_ldap_tests,john_local_message,
john_log,john_log_tests,john_message,john_mnesia,john_model,
john_rabbitmq,john_reader|...]},
{maxP,infinity},
{maxT,infinity},
{registered,[john]},
{included_applications,[]},
{applications,[kernel,stdlib]},
{env,[{db_host,"xxx.xxx.com"},
{db_port,5432},
{ldap_options,[{timeout,7000},{anon_auth,true}]},
{mq_username,<<"john_2">>},
{link_exchange,<<"exchange_john_2">>},
{included_applications,[]},
{ldap_password,"helloworld"},
{ldap_user,"admin"},
{mq_port,5672},
{db_password,<<"xxxx">>},
{is_direct_link,false},
{db_database,"db_jotham"},
{cluster_nodes,[...]},
{mq_address,...},
{...}|...]},
{mod,{john_app,[]}},
{start_phases,undefined}]}
另外,当get_key功能可用时? {ok,Product} = application:get_key(john,id), {ok,Version} = application:get_key(john,vsn),
在上面的start(normal,[])
中,get_key
功能不可用,但在服务器启动完成后,get_key(john,vsn)
可用。我仍在努力寻找原因。
问题已经解决,它与“复制 - 不思考”有关。该代码最初来自rabbitmq的rabbit.erl
文件。
以下代码导致了问题:
[Product, string:right([$v|Version], ProductLen),
rabbitmq的“ProductLen”键不为0.但我的ProductLen为0,字符串:right(xxx,0)返回“”。所以出现了问题。
感谢您提供调试的线索。
答案 0 :(得分:2)
应用程序资源文件应该称为Application.app,其中Application是应用程序的名称。该文件应位于应用程序的ebin目录中。
首先,检查app
文件名是john.app
?
其次,检查app
文件是否在正确的目录中?
您可以使用loaded_applications() -> [{Application, Description, Vsn}]
检查您的应用是否已成功加载。