How to use ejabberd as an Elixir application dependency

Mickaël Rémond
· 1 min read
Send by email

Starting from version 16.02, ejabberd is packaged as an Hex.pm application: ejabberd on hex.pm. In case of doubt, you can refer to ejabberd official documentation: Embedding ejabberd in an Elixir application

It means that you can now build a customized XMPP messaging platform with Elixir on top of ejabberd. You do so by leveraging ejabberd code base in your app and providing only your custom modules.

This makes the management of your ejabberd plugins easier and cleaner.

To create your own application depending on ejabberd, you can go through the following steps:

  1. You are all set, you can now connect with an XMPP client !

Register an account from Elixir console, later check it was registered:

:ejabberd_auth.try_register("test", "localhost", "passw0rd")
:ejabberd_auth.get_users()

Start your app, ejabberd will be started as a dependency:

iex -S mix

Get the source code of all dependencies and compile them:

mix do deps.get, compile

Setup some system options in a new file called config/config.exs:

import Config

config :ejabberd,
  file: "config/ejabberd.yml",
  log_path: 'logs/ejabberd.log'

config :mnesia,
  dir: 'database/'

Get the default ejabberd configuration file:

mkdir config; wget https://raw.githubusercontent.com/processone/ejabberd/master/ejabberd.yml.example -O config/ejabberd.yml

Add the ejabberd package as a dependency in your mix.exs file:

defmodule Ejapp.Mixfile do
...
  defp deps do
    [{:ejabberd, "~> 23.10"}]
  end
end

Go to your new app directory:

cd ejapp

Create new Elixir app with mix:

mix new ejapp
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/ejapp.ex
* creating test
* creating test/test_helper.exs
* creating test/ejapp_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd ejapp
    mix test

Run "mix help" for more commands.