Erlang Code Auto Reloader

本文介绍了一种在Erlang开发环境中使用名为reloader的实用工具的方法。通过该工具可以实现在开发过程中对修改后的模块进行自动重载,并运行单元测试以验证更改的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I wrote this post a few months ago when I was developing a new Erlang application. I eventually ended up using the reloader I mentioned at the end, but never documented it. Now I’m about to start writing a new app, and I’m on a different machine.

First, get the reloader. It was developed as part of mochiweb but functions just fine on it’s own. Just put it somewhere accessible – I use the ebin directory in my home folder. (yes, I just copied & pasted the source) Then compile it like so:

erlc reloader.erl

Now you can load the reloader automatically on startup by adding this to your ~/.erlang config file:

code:load_abs(“/path/to/your/ebin/reloader”).
reloader:start().

Change your path to match your reloader. Do not add the .beam extension. See the code module documentation.

When you start your Eshell, you’ll automatically get the reloader running. If you didn’t do it right, you’ll get output that looks like this:

computer:~ jhaddad$ erl
Erlang R14B (erts-5.8.1) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

{“init terminating in do_boot”,{undef,[{reloader,start,[]},{init,start_it,1},{init,start_em,1}]}}

After loading a module, if you rebuild it, it’ll automatically get reloaded. If you’ve added the eunit .hrl file, it’ll also run your unit tests for you.

There’s not a lot of documentation out there on this incredibly useful library – hopefully this helps a few of you out.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值