5

This is a completely newbie question from a Java programmer trying to learn Erlang. What's the equivalent of a Java JAR file in Erlang by which 3'rd party libraries can be included in an Erlang application?

The other day I made a copy of the mochijson2.erl in my project and it worked, but I am wondering if there's a better/more formal way of discovering and including libraries in the Erlang world.

Ranjit Iyer
  • 857
  • 1
  • 11
  • 20

1 Answers1

5

If you're familiar with Maven (or its siblings), the Erlang analogue is Rebar.

You could create a rebar.config (similar to a POM file) with the contents

{deps, [
  {mochiweb, "2.9.0", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.9.0"}}}
]}.

Then rebar get-deps && rebar compile will fetch mochiweb (and any dependencies it declares), build the dependencies, and build your own code.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
  • thanks, and I'd assume that the dependency being pulled must conform to rebar conventions. I am probably asking for too much, but is there a way to turn an ad-hoc erlang project structure into a rebar compatible structure and it more amenable to sharing with others? Would be very useful for beginners like me. – Ranjit Iyer Jun 27 '14 at 19:07
  • As long as your project structure conforms to the OTP standards, it will work with Rebar. Also, here you don't necessary need to have `rebar.config` if you want to compile the project (like you must have `pom.xml` in Maven), although it gives you a lot of possibilities. You can just have a `/src` folder with source code and `*.app.src` file and it'll work. – rpozarickij Jun 27 '14 at 20:44