Get file path to the modules in the modules folder on the server


I am not that proficient in Java especially spring. I want to get the file path to the modules in the modules directory on the server. I set up the server instance using the OpenMRS SDK. Any help is very much appreciated.


1 Like

Hello @sibo , the modules’ .omod files can be found at this path


on windows.

Thanks @ruhanga, I need a way to dynamically locate them in the code as opposed to hard cording a path in there.

Can you briefly describe the use case for this to pick little more context.

@ruhanga When you set up a fresh platform instance using the SDK, there are usually 3 modules that come with it, fhir, and, owa omods. In this case I show a splash page in case a user goes to the route ‘openmrs/’. This splash page gives users access the addOn manager to add modules. After they add the legacyui to the available modules, I need to stop showing the splash page and let the legacyui module UI take over. So I wanted to check for the availability of the legacyui which is loaded to the modules directory. That is why I wanted to get the file path but if you have a better or possible way to do that, I’d be very glad to know. Thank you

Can the file located in the server root directory (your_server_id) be of any help? it contains the installed modules which is the info you are looking for if I got you correctly.

@ruhanga It contains the 3 default omods with their versions. But it won’t get me the path to the modules directory where new modules are loaded. What I want is, check the modules directory, if the legacyui is there, do something. To check it, I need a way to get there, was assuming the file path would help.

The file gets updated with the installed modules as well. A lookup for the module of interest from the file would just be as great as following the file path to the module folder. And am thinking there could be a core-api resource method that grabs this info from this file. Other than reinvent the wheel, @ivange94, @reubenv, @darius , @wyclif , @dkayiwa what could be the api method or rather a better way to approach this (get info on installed modules)?

1 Like

@sibo RefApp Distro ships with most of the modules for a generic use case.Is it of help to you, or you specifically want to build on Platform ?

Great idea @tendomart, or even customize platform (into reference application distro) to have the desired modules specified in the file in a folder from where you would then run the maven server setup command. The file would look something like

name=Reference Application

@ruhanga Good observation** !!** but does he need go through all that path anyways?Unless he just needs basic UI and may be harness REST to build his own distribution?

I however also found and for comparison .As indicated by Nathan .could it be of help ? cc @sibo

I don’t think so. Maybe let me explain this from a user’s perspective. When you setup a new instance of the platform, not reference application, this is the interface you see.

From this interface, a user cannot easily add modules as the links available redirect you to wiki pages.

So the openmrs-owa-platform should replace this splash page.

The platformui will give a user a way to log in and access the addOn manager that the user will use to load modules.

if(new platform instance){
    default_modules = {fhir,, owa}
    //assuming a user has not loaded anyother module
    if(no new modules installed and user is at "/" or "login.htm" or "index.htm"){
        redirect user to platformui where user will log in
        at url (http://localhost:8080/openmrs/owa/openmrs-owa-platformui/index.html#/login)
    }else if (user loaded legacyui and is at "/" or "login.htm" or "/index.htm"){
        display legacyui not platformui


As soon as a user loads a new module say, legacyui, the platformui should not be visible when a user accesses "/", "/login.htm" or "/index.htm".

I need to figure out a way to dynamically detect that a new module has been loaded so that the else part of the psuedo code above takes over. One thing I thought of was to monitor the modules folder and as soon as the legacyui is there, I don’t redirect the user to the platformui but do a chain.doFilter(httpRequest, httpResponse);

In other words, only show platformui for a fresh instance of the platform but as soon as a user loads a module, don’t show it again. @tendomart, @ruhanga

@sibo i think you may capture logs and notification from Module Activator Class like from this example and eventually do some thing with the Notification.

When a module starts there is a log like wise when a module stops it drops a notification,so you could harness that.

Likewise could Event Module be of help as well in that case ?

Wouldn’t it be better to invert this? That is, instead of the login process hardcoding all scenarios, have the login page injected. So, the pseudocode becomes:

String loginPath = "/owa/openmrs-owa-platformui/"; // default to platform UI
private URL loginURL = basePath + loginPath;
redirect user to loginURL

When the Legacy UI or Reference Application modules are loaded, they could set loginPath (you’d just need to ensure the correct one sets it last). For security reasons, you might consider constraining which classes could set the loginPath (or save that for future work… but at least avoid letting it be set to another host or application).