首页 文章

在路径中加载所有erlang模块

提问于
浏览
5

使用Easy way of loading projects with rebar dependencies的答案,现在可以自动解析依赖关系,但不会自动加载它们 .

那么,如何自动加载我的ebin和/ deps / * / bin路径中的所有模块?这样,当使用Erlang shell选项卡完成时,它们可用,这大大加快了我的开发过程 .

My solution based on the great answer of Adam Lindberghttps://gist.github.com/1131312它只会自动加载项目模块,所以erl启动几乎没有延迟 .

2 回答

  • 4

    这个片段可以解决这个问题:

    [code:ensure_loaded(list_to_atom(filename:rootname(filename:basename(F))))
     || P <- code:get_path(), F <- filelib:wildcard(P ++ "/*.beam")].
    

    将它作为一行(包括点: . )放在 ~/.erlang 文件中,它将在启动任何Erlang shell时执行 . 但要注意,它的速度非常慢!

    » time erl -noshell -s init stop
    erl -noshell -s init stop  0.11s user 0.02s system 11% cpu 1.143 total # Without
    » time erl -noshell -s init stop
    erl -noshell -s init stop  7.31s user 1.08s system 88% cpu 9.480 total # With
    
  • 9

    如果你产生这个过程,你将获得一个非常快的开始 .

    LP = fun() -> [code:ensure_loaded(list_to_atom(filename:rootname(filename:basename(F)))) || P <- code:get_path(), F <- filelib:wildcard(P ++ "/*.beam")] end.
    spawn(LP).
    

    在〜/ .erlang文件中

相关问题