Where are JavaScript files kept in an OpenMRS module

Am currently looking at the source codes for the database backup module. I will like to know where inside the module, JavaScript files are kept.

Example, where is this file “/dwr/interface/BackupFormController.js” .

Thank you

Is this of help? https://wiki.openmrs.org/display/docs/DWR+in+OpenMRS

1 Like

@dkayiwa Knows a lot more about this than I do, and may have given you exactly what you asked for, but the general topic caught my attention and I think others may be looking for an answer to that too.

Disclaimer: I’m still new to this too. I’ve been looking at this question in passing for awhile. These methods vary in “correctness” (some are probably considered “the wrong way to do it”, even by me), and ideally there are better ways for some of these approaches (though I have yet to find them).

In general, there are many correct answers, but only relative to the specific question you’re asking.

For the basics of Java Servlets in general, you may find this book helpful. Head First Servlets and JSP (also currently “free” with O’Reilly Safari if you have access through your college, University or ACM) gives some overview and introduction to basic servlets and JSP. Spring MVC 3.0 builds on top of java servlets, using annotations and various other boilerplate.

In an OpenMRS maven source tree: Generally in the “/resources/” subfolders of the omod component, generally “omod/src/main/webapp/resources/” in OpenMRS.

However, “omod/src/main/resources” is the more generic Java Web Application directory (and can still be used by developers) (Tomcat 7’s deployment details, this can vary by web container/server combo).

On the server (can be affected by the previously mentioned web container e.g. Tomcat 7): The modules “classes” directory is given by OpenmrsClassLoader.getInstance().getResource("/").getPath() (this is not where you’ll necessarily find the classes from your module however, you can use one of your own specific classes if you are looking for that). getResource() and getResourceAsStream() are the general methods to load WAR resources.

A module’s omod subproject (when using maven and tomcat), will (generally) have view directories “…/view/<module_name>/*” on the server, of which resources is generally one.

using JSP: Web Containers running .WAR files are somewhat arbitrary at some points of the tree, but the spec requires some parts of a path like “/WEB-INF”. These are accessible in the Spring MVC JSP for <@% include %>.

using openmrs:htmlInclude <openmrs:htmlInclude file="/moduleResources/<module_name>/some.js"/>

On the client: using JS: + “/moduleResources/<module_name>/some.js” where basepath would be something like “http://demo.openmrs.org/openmrs” which is configured on the web server itself. It is possible to use a relative path here if you know where something is being served relative to the resource you’re looking for.

You may also want to look at, ModuleClassLoader.findResource() OpenmrsUtil.getDirectoryInApplicationDataDirectory()

It is possible to see how the deployment is done on the file system by looking in the /openmrs/ directory (if using mvn openmrs-sdk:run), or the .OpenMRS directory in the web server software’s directory structure on it’s host, depending on your system/setup.

Again, I’m still (relatively) new to OpenMRS, so apologies for any missing caveats or partially (wholly?) incorrect info.

1 Like