Reputation: 24851
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
Upvotes: 3
Views: 1106
Reputation: 7836
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:
MyProject--/src /ebin /lib /include /priv /doc /examples /test /Emakefile
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 into ebin
, i enter this into the Emakefile
{"src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "ebin"}]}.
In that case i would start the erlang shell with its pwd()
pointing in the folder MyProject
, to enable the function call make:all()
to find the file Emakfile
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 your lib
folder, so that your application looks like this:
MyProject--/src /ebin /lib/some_otp_app-1.0 /include /priv /doc /examples /test /Emakefile
then we would change our Emakefile
to look like this:
{"src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "ebin"}]}. {"lib/some_otp_app-1.0/src/*", [debug_info, netload,strict_record_tests,warn_obsolete_guard,{outdir, "lib/some_otp_app-1.0/ebin"}]}.
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:
#!/bin/bash erl \ -name my_node@my_domain \ -pa ./ebin ./lib/*/ebin ./include \ -mnesia dump_log_write_threshold 10000 \ -eval "make:all()"
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:
$pwd /export/home/your_user_name/MyProject $sh start_project.sh
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:
MyProject--/src /ebin /lib/some_otp_app-1.0 /include /priv /doc /examples /test /Emakefile /start_project.sh
So if you substitute the erlang driver for mysql application with this "some_otp_app-1.0", everything will be fine. success!
Upvotes: 4
Reputation: 819
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.
Upvotes: 4