Check if application available in Erlang VM. How?

Hello all!
There are necessity to check if application available in Erlang VM. How to check it out? The application: which_applications/0(/1) isn’t what is seeking by me. Need all of available application, not only that is running. Is there any way to get list of all available applications? Need to check list of dependencies before application started.

Hi,

you could apply a combination of

  • code:all_available which returns a list of all available modules,
    take the first element of each tuple, which is the module’s name,
    convert it to an atom,
  • call module_info(attributes)
    and filter for all that have {behaviour, [application]}.

Maybe there is a shorter way.

[Edited]
On a second thought, why would you need this?
If you know the application which you want to start, you can do this instantly with
application:start(Name).

1 Like

Need to check before any attempt of starting it. If something not installed - required not to start strictly.

Go through code:get_path() and look for .app files?

You may allow this mechanism outside your code, using optional_applications key in app file of your application. From the docs:

optional_applications

    A list of applications that are optional. Note if you want an optional dependency to be automatically started before the current application whenever it is available, it must be listed on both applications and optional_applications.

code:all_available is working for me. Thx a lot.