Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

OpenMRS code follows a specific format. To set up Eclipse properly, so that your code can be formatted automatically, follow the instructions below.

Download and Install Eclipse

  1. Download Eclipse from http://www.eclipse.org/downloads/.
    We recommend the Eclipse IDE for Java EE Developers.
  2. Install Eclipse on your system.

Clone openmrs-core

To configure code format in Eclipse, you will need xml files in the openmrs-core repository.

To get these files, follow these steps:

  1. Sign in to your Github account.
  2. Go to: https://github.com/openmrs/openmrs-core, fork the repository.
  3. Run the following command on your computer:

    $ git clone https://github.com/{your_github_id}/openmrs-core

    The openmrs-core folder with all its files will be cloned to your local directory.

Configure Eclipse

Note: All images and settings shown in the following sections were taken on Eclipse version: 2020-6.

Configure Java Code Format for OpenMRS

In order for Eclipse to format the code, you will need to import the OpenMRSFormatter.xml. This file is located in the OpenMRS core, which you should clone if you haven't already.

  1. Open Eclipse, select Window > Preferences.
  2. In the search box,  enter  formatter, then select Java > Code Style > Formatter
  3. In the left pane, select Import.
    An Import Profile dialog displays.
  4. In the dialog, browse to: openmrs-core/tools/src/main/resources/eclipse, and select OpenMRSFormatter.xml.
  5. Select Open.
    The OpenMRS Formatter shows as the Active profile. See the picture below:
  6. Select Apply and Close.
    Now you can let Eclipse format any java class with the shortcut:

Ctrl+Shift+F (Command+Shift+F on Mac)

Configure Java Import Order

In order for Eclipse to order the java imports according to the OpenMRS style and remove unused imports do the following:

  1. Select Window >  Preferences. In the search box enter organize imports.
  2.  Select Java > Code Style > Organize Imports.
    The result is as following:
  3. Make sure the order of the import groups is as what you see above (java, javax, org, com).
    It is the Eclipse default, so you might not have to change anything.
  4. Check both Number of imports needed for * and Number of static imports needed for * are set to 99.  
    The numbers need to be high enough so that Eclipse will not replace your imports with the so called "star imports" using *. 99 is the default value for Eclipse and is usually high enough.
  5. Select the Do not create imports for types starting with a lowercase letter checkbox.
  6. Select Apply and Close.
    Now you can let Eclipse format and remove unused imports with the shortcut:
    Ctrl+Shift+O (Command+Shift+O on Mac)

  • No labels