Just to add to the other answers: When you do a release, you may have two versions of your application and you may want to upgrade. Say, you first have lib/foo-1.0.0/ebin/foo_app.beam loaded. Then you install foo-2.0.0 via your preferred method, I use target_system:install("foo", "/tmp/erl-target") . Now I have /tmp/erl-target/lib/foo-2.0.0/ . I use code:which(foo_app) to see which one is loaded. To load it, in this case I would first start the Eshell as such:
If I added a new function in foo-2.0.0 which I exported, it will become available, for example. If you want to downgrade back to the previous version, you will have to have a similar foo.appup file in /tmp/erl-target/lib/foo-1.0.0/ebin/ , but with the version numbers swapped. Please correct me if I am wrong, I am new to Erlang. I did test it myself and it worked for me. This is just to upgrade your application within a release, this is not upgrading the release itself. If something is unclear, let me know. I am still trying to work this out myself. :)
3条答案
按热度按时间ki1q1bka1#
You can do it by:
c(module_name)
The module is only updated in the process where the fully qualified function call is made.
Here is an example:
a.erl:
In the shell:
xxe27gdn2#
Just to add to the other answers:
When you do a release, you may have two versions of your application and you may want to upgrade. Say, you first have
lib/foo-1.0.0/ebin/foo_app.beam
loaded. Then you installfoo-2.0.0
via your preferred method, I usetarget_system:install("foo", "/tmp/erl-target")
. Now I have/tmp/erl-target/lib/foo-2.0.0/
.I use
code:which(foo_app)
to see which one is loaded. To load it, in this case I would first start the Eshell as such:Afterwards I type:
To see which one is currently loaded, you type (in the same Eshell):
You will need the
foo.appup
file in/tmp/erl-target/lib/foo-2.0.0/ebin/
with the following contents:To upgrade, you type:
If everything was successful, you will see the following:
If I added a new function in
foo-2.0.0
which I exported, it will become available, for example.If you want to downgrade back to the previous version, you will have to have a similar
foo.appup
file in/tmp/erl-target/lib/foo-1.0.0/ebin/
, but with the version numbers swapped.Please correct me if I am wrong, I am new to Erlang. I did test it myself and it worked for me. This is just to upgrade your application within a release, this is not upgrading the release itself.
If something is unclear, let me know. I am still trying to work this out myself. :)
wxclj1h53#
像往常一样编译模块,然后在erlang shell中键入以下代码:
这将从新的
my_module.beam
文件加载代码并替换my_module
模块。旧版本可能不会完全消失--有关详细信息,请参阅Erlang参考手册中的代码重新加载部分。