在5.0.3版本中使用_schema.erl文件正常运行,但在5.0.16版本中运行则会报错

在5.0.3版本中使用_schema.erl文件正常运行,但在5.0.16版本中运行则会报以下错误

escript: exception error: undefined function emqx_mytest_schema:roots/0
  in function  hocon_schema:roots/1 (hocon_schema.erl, line 239)
  in call from emqx_conf_schema:roots/1 (emqx_conf_schema.erl, line 1257)
  in call from lists:flatmap/2 (lists.erl, line 1254)
  in call from lists:flatmap/2 (lists.erl, line 1254)
  in call from emqx_conf_schema:roots/0 (emqx_conf_schema.erl, line 107)
  in call from hocon_schema:roots/1 (hocon_schema.erl, line 239)
  in call from hocon_schema:resolve_struct_name/2 (hocon_schema.erl, line 220)
ERROR: call_hocon_failed: -s emqx_conf_schema -c /home/zz/work/docker-build/5.0.16/run/_build/emqx/rel/emqx/etc/emqx.conf multi_get node.data_dir node.name node.cookie node.db_backend cluster.proto_dist

在自己编写的模块mytest中使用的_schema.erl文件如下:

-module(emqx_mytest_schema).

-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").

-export([roots/0, fields/1, desc/1, namespace/0]).

namespace() -> "mytest".

roots() -> ["mytest"].

fields("mytest") ->
    [
        {enabled, sc(boolean(), false, mytest_enabled)},
        {"kafka",
            ?HOCON(
                ?R_REF("kafka"),
                #{
                    desc => "mytest_kafka",
                    required => false
                }
            )
        }
    ];
fields("kafka") ->
    [
        {enabled, sc(boolean(), false, mytest_kafka_enabled)},
        {bootstrap, sc(string(), "127.0.0.1", kafka_bootstrap)},
        {topic, sc(string(), "mqtt-conn-session", kafka_topic)},
        {client, sc(string(), "brod_client", kafka_client)},
        {consumer_group, sc(string(), "mqtt-conn-session-group-local", kafka_consumer_group)},
        {insert_interval,
            sc(
                emqx_schema:duration_s(),
                "100s",
                kafka_insert_interval
            )},
        {batch_size,
            sc(
                integer(),
                100,
                kafka_batch_size
            )}
    ].

desc("mytest_enabled") ->
    ?DESC(mytest_enabled);
desc("kafka_enabled")->
    ?DESC(mytest_kafka_enabled);
desc("mytest_kafka") ->
    ?DESC(mytest_kafka);
desc(_) ->
    undefined.

%%--------------------------------------------------------------------
%% Internal functions
%%--------------------------------------------------------------------
sc(Type, Default, Desc) ->
    ?HOCON(Type, #{default => Default, desc => ?DESC(Desc)}).

看上去是的beam文件没有加载进来,你放在什么目录下的?

放置在 emqx/apps/emqx_mytest目录下 该目录与emqx_dashboard同级

那应该还没有对应的beam文件生成,所以才undefined
你在rebar.config.erl 里面与emqx_dashbaoard 相同的位置也要添加一下,让他打包进release中。