A module can only access the api/service of another module if it is marked as required. The classloaders restrict this. The reasoning is to make classloading faster and to prevent classloading errors if the other module does not exist in a running openmrs.
To denote that the module you are writing depends on, or requires another one, put something like the following in your config.xml file:
- The "version" attribute on the require_module element is available as of OpenMRS v1.5.
- You probably want to then take the other module's .omod file, put it in your module's lib-common folder, and add it as a library in your eclipse project's build path(Add it to the .classpath of your module and also add to your build.xml <include name="*/.omod"/> to the <fileset dir="lib-common"> tab and ant should be able to see it too.
- The "require_modules" element must be after "require_version" and before "extension" in the config.xml file
With this example, if at least formentry version 1.8 is not installed, then this module will not start.
Being aware of other modules:
This feature is available starting from OpenMRS v1.9
There are times when you need to be able to make a module aware of other modules, without requiring them. This means that if the other module is also installed, do some extra features.
A specific example: The dev of formimportexport module wants his module to be able to be installed without requiring the user to install the formentry module as well. However, formimportexport has some extra stuff to do to forms if formentry is installed, so it needs to call formentry's API optionally.
Formimportexport should be aware of formentry, be compiled against formentry.jar, and be able to say something like:
To denote that the module you are writing is aware of another one, put something like the following in your config.xml file:
Compiling against the module
If you have a mavenized module:
In your module's root pom.xml you need something like this:
In your module's omod/pom.xml you need something like this:
If your module is NOT using maven:
- Take the other module's .jar or .omod file, put it in your module's lib-common folder, and add it as a library in your eclipse project's build path.
- The "aware_of_modules" element must be between "require_version" and "extension" in the config.xml file