Error Encountered While Running OpenMRS Webservices.rest API Locally - Need Step-by-Step Guidance

I followed the official OpenMRS documentation and successfully set up OpenMRS core along with the database on my local machine. The OpenMRS core is running without any issues, and the database connection is working as expected.

However, when I attempt to run the webservices.rest API, I encounter errors. I’ve gone through the setup multiple times and tried various troubleshooting steps, but the issue persists.

Steps Taken:

  1. Installed OpenMRS core and connected it to my local database.
  2. Followed all the necessary steps for setting up webservices.rest API.
  3. The OpenMRS core runs successfully.
  4. I encounter errors specifically when trying to access the web services.

** Full log **:

Error Log Details: - Pastebin.comFull Logs

### **Error Details**:
 -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest
[ERROR] Tests run: 53, Failures: 0, Errors: 39, Skipped: 0, Time elapsed: 0.538 s <<< FAILURE! - in org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest
[ERROR] getResourceByName_shouldReturnResourceForGivenNameAndIgnoreUnannotatedResources(org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest)  Time elapsed: 0.351 s  <<< ERROR!
java.lang.IllegalAccessException: Can not set static final java.lang.String field org.openmrs.util.OpenmrsConstants.OPENMRS_VERSION_SHORT to java.lang.String
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.setCurrentOpenmrsVersion(RestServiceImplTest.java:227)
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.getResourceByName_shouldReturnResourceForGivenNameAndIgnoreUnannotatedResources(RestServiceImplTest.java:208)

[ERROR] getResourceBySupportedClass_shouldReturnResourceSupportingGivenClassAndCurrentOpenmrsVersion(org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest)  Time elapsed: 0 s  <<< ERROR!
java.lang.IllegalAccessException: Can not set static final java.lang.String field org.openmrs.util.OpenmrsConstants.OPENMRS_VERSION_SHORT to java.lang.String
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.setCurrentOpenmrsVersion(RestServiceImplTest.java:227)
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.getResourceBySupportedClass_shouldReturnResourceSupportingGivenClassAndCurrentOpenmrsVersion(RestServiceImplTest.java:367)

[ERROR] initialize_shouldClearCachedResourcesAndSearchHandlersAndReinitializeThem(org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest)  Time elapsed: 0 s  <<< ERROR!
java.lang.IllegalAccessException: Can not set static final java.lang.String field org.openmrs.util.OpenmrsConstants.OPENMRS_VERSION_SHORT to java.lang.String
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.setCurrentOpenmrsVersion(RestServiceImplTest.java:227)
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.initialize_shouldClearCachedResourcesAndSearchHandlersAndReinitializeThem(RestServiceImplTest.java:1137)

[ERROR] getResourceByName_shouldReturnResourceForGivenName(org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest)  Time elapsed: 0.016 s  <<< ERROR!
java.lang.IllegalAccessException: Can not set static final java.lang.String field org.openmrs.util.OpenmrsConstants.OPENMRS_VERSION_SHORT to java.lang.String
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.setCurrentOpenmrsVersion(RestServiceImplTest.java:227)
        at org.openmrs.module.webservices.rest.web.api.impl.RestServiceImplTest.getResourceByName_shouldReturnResourceForGivenName(RestServiceImplTest.java:190)

What I Need Help With:

Could someone please help me by providing step-by-step guidance for:

  • Which repository to pull the code from.
  • The correct branch to use for the webservices.rest API.
  • Any specific code or configuration changes that I might be missing.

I would really appreciate it if someone could walk me through the process to resolve the issue and successfully run the OpenMRS API.

Thank you!

What is the output of this command? mvn -v

`java -version`
java version "11.0.27" 2025-04-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.27+8-LTS-232)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.27+8-LTS-232, mixed mode)
`mvn -v`
Apache Maven 3.9.10 (5f519b97e944483d878815739f519b2eade0a91d)
Maven home: C:\apache-maven-3.9.10
Java version: 11.0.27, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Does it compile successfully if you switch to Java 8?

First i try then i notify you

The API is not working as expected. The logs show repeated connection failures while trying to reach the server:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.openmrs.module.webservices.rest.SessionIT
Waiting for server at http://localhost:8080/openmrs for 300 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 295 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 280 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 266 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 252 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 238 more seconds...
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Waiting for 224 more seconds...

What does this command return? mvn -v

mvn -v

Apache Maven 3.9.10 (5f519b97e944483d878815739f519b2eade0a91d)
Maven home: C:\apache-maven-3.9.10
Java version: 1.8.0_202, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_202\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Can you now share the whole build log via pastebin.com?