简体   繁体   English

如何在Elixir / mix项目中加载Erlang模块?

[英]How to load an Erlang module within a Elixir/mix project?

I have an Elixir project managed by mix. 我有一个由混合管理的Elixir项目。 When started with iex -S mix all Elixir modules within my lib folder get loaded. 当使用iex -S mix启动时,我的lib文件夹中的所有Elixir模块都会被加载。 An Erlang module in an .erl file within the lib folder doesn't. lib文件夹中的.erl文件中的Erlang模块不会。

I'd like to know either a) how do I load an Erlang module explicitly from my Elixir code or b) what do I have to do to have mix autoload the Erlang module, too. 我想知道a)如何从我的Elixir代码中显式加载Erlang模块或b)我还需要做什么来混合自动加载Erlang模块。 (Preferably both ;) ) (最好两者;))

Erlang modules that get compiled will get included automatically. 编译的Erlang模块将自动包含在内。 If your local erlang module is in the lib/ folder though the problem may be that its not getting compiled. 如果你的本地erlang模块在lib/文件夹中,虽然问题可能是它没有被编译。

The mix task that handles compiling erlang modules ( mix compile.erlang ) assumes the default path where the erlang modules are included is in a src/ directory. 处理编译erlang模块的混合任务( mix compile.erlang )假定包含erlang模块的默认路径位于src/目录中。

If you'd prefer to place it somewhere else, you can adjust the configuration via the :erlc_paths parameter, in your project config in mix.exs . 如果您希望将其放在其他位置,可以通过:erlc_paths参数在mix.exs的项目配置中mix.exs配置。 A bare bones example would look like: 一个简单的骨头示例如下:

def project do
  [
    app: :test,
    version: "0.1.0",
    elixir: "~> 1.6",
    erlc_paths: ["lib"],
    start_permanent: Mix.env() == :prod,
    deps: deps()
  ]
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM