如何在 Erlang 中安装应用程序?
在我的项目中,我想使用 mysql 所以我签出了这个 https://github.com/dizzyd/ erlang-mysql-驱动程序。我想知道如何安装该应用程序以便我的项目可以与其交互
In my project, i want to use mysql so i checkout this https://github.com/dizzyd/erlang-mysql-driver. I want to know how install the application so that my project can interact with it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看“rebar” - https://bitbucket.org/basho/rebar/wiki/Home
它可用于安装依赖项,以及创建独立版本。
快速浏览一下您想要使用的 erlang-mysql-driver,就会发现它也使用 rebar 进行依赖项管理。
Have a look at "rebar" - https://bitbucket.org/basho/rebar/wiki/Home
It can be used for installing dependencies, and for creating independent releases.
And a quick look at erlang-mysql-driver, that you want to use, shows that it is also using rebar for its dependency management.
如果您已经开始布局您的应用程序(已经完成了一些编码)或者如果您是新手,那么 rebar 可能会使事情变得复杂,但是,如果您的项目是 erlang/OTP 应用程序,那么我建议您首先根据推荐的文件系统如下:
Emakefile
是一个重要的文件。它可能没有文件扩展名。它使 BIF:make:all()
能够编译您指向的所有 erlang 源模块,并将所有 .beam 文件传输到您想要的目的地。例如:我想要编译 src 中的所有模块并将 Beam 文件传输到 ebin 中,我将其输入到 Emakefile
中在这种情况下,我将启动 erlang shell,使其
pwd()
指向文件夹MyProject
,以启用函数调用make:all()
找到文件Emakfile
以便编译我所有的 src 文件。现在,假设您有另一个 OTP 应用程序,您希望将其作为构建中的额外包。如果它像我向您展示的那样按 OTP 方式排列,并且尚未构建,即尚未制作,我的意思是只有它的 src 和它的文件夹 ebin 是空的,或者它的 ebin 可能包含
.APP 文件
已经。然后将此 OTP 应用程序复制到您的lib
文件夹中,以便您的应用程序如下所示:然后我们将
Emakefile
更改为如下所示:在文件夹
中MyProject
,您可以放置一个 shell 脚本来启动您的项目,并将所有相关的 ebin 路径添加到您的节点代码路径中。sh 脚本可能如下所示:您可以将此文件另存为
start_project.sh< /代码>。因此,当您更改源代码时,即使在启动项目时,当您使用指向文件夹的终端路径运行 sh 脚本时:
MyProject
,您会执行 以下操作:您的项目位于您在脚本中输入的节点,并将编译关闭时更改的所有 src 文件。不仅如此,每当您对 src 代码进行更改时,您还可以在 shell 中调用:
make:all()
。那么你可以在 make 之后调用:l(some_module)
,以便 erlang 虚拟机重新加载已编译模块的新目标代码。所以,你的整个项目现在将如下所示:
因此,如果你用这个“some_otp_app-1.0”替换mysql应用程序的erlang驱动程序,一切都会好起来的。成功!
rebar may complicate things if you have already started laying out your app (done some coding already) or if you are a newbie , however, if your project is an erlang/OTP app, then i suggest that you first organize you code according to the recommended file system like this:
The
Emakefile
is an important file. It maynot have a file extension. It enables the BIF:make:all()
to compile all the erlang source modules you point it to and transfers all the .beam files to the destination you want.For example: is i want all the modules in
src
to be compiled and transfer the beam files intoebin
, i enter this into theEmakefile
In that case i would start the erlang shell with its
pwd()
pointing in the folderMyProject
, to enable the function callmake:all()
to find the fileEmakfile
so as to compile all my src files.Now, suppose you have another OTP app which you want to have as an extra package in your build. If it OTP-like arranged as i have showed you, and not yet built i.e. not yet made, i mean with only its src and its folder ebin are empty or it ebin may be containing a
.APP file
already. Then you copy this OTP application into yourlib
folder, so that your application looks like this:then we would change our
Emakefile
to look like this:In the folder
MyProject
, you can put a shell script that will start your project and add all relevant ebin paths to your nodes code path.the sh script may look like this:You can save this file as
start_project.sh
. Hence as you make changes to your source code, even at the time of starting your project, when you run the sh script with your terminal path pointing into the folder:MyProject
, you do this:This would start your project at the node you entered in the script and would compile all src files which were changed when it was off. Not only this, you can as well call:
make:all()
in your shell whenever you make cahnges to your src code. then you would call:l(some_module)
after making so that the erlang vm reloads the new object code of the compiled module.So, your entire project will now appear like this:
So if you substitute the erlang driver for mysql application with this "some_otp_app-1.0", everything will be fine. success!