overriding of JAVA_HOME when running SDK for 2.x and latter for 1.9

Hi all,

I run into an error when running SDK trying to setup openmrs 1.9 with java 7. But I had run SDK setting up 2.x with java 8 (where default java was 7). This error was due to /.mavenrc file that overrides java.home of the instance set it to java 8(as of my case).

ERROR - Listener.contextInitialized(150) |2020-04-06 18:28:22,136| Got exception while starting up: org.openmrs.api.APIException: OpenMRS requires Java 6, but is running under 1.8.0_242 at org.openmrs.util.OpenmrsUtil.validateJavaVersion(OpenmrsUtil.java:1201) at org.openmrs.web.Listener.contextInitialized(Listener.java:116) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5197) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5720) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1705) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1695) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

1 Like

You have multiple java versions ??

I would simply say , when your going to run OpenMRS , edit your JAVA_HOME to point to java 8

Thanks @mozzy,

@jbyiringiro is up and running now, he is just posting here in case others run into similar issues. It is quite common to have multiple Java versions on one’s machine. And certainly it is needed if one needs to run both 1.x (which will not run on Java 8) and 2.x (which requires Java 8) versions of OpenMRS.

The point here is that no setting of JAVA_HOME as an environment variable fixed his issue or had any effect. He tried setting it in his environment, profile, and in the shell directly before running the SDK. He made sure that he set it correctly in openmrs-server.properties. He needed Java 7 to be picked up to run his OpenMRS 1.9 instance, but regardless of what he did, Java 8 was always used.

It took several hours of debugging over screensharing while running the SDK through the debugger to finally have our “aha” moment where we finally figured out what was happening. @jbyiringiro is posting here so that if anyone else runs into a similar problem, the solution is documented.

In his case, it turns out that he had a “.mavenrc” file in his home directory which contained as single line that set JAVA_HOME to Java 8. This led Maven to always use Java 8, including within the forked, embedded Tomcat process started by the SDK, even though the Java 7 version was specified in every other possible location.

So…the moral of the story is, if you are using the SDK, and can’t figure out why the version of Java you are trying to use is not getting picked up - check to see if you have a .mavenrc file in your home directory that might be overriding things. We hope this saves someone some time one day.

Best, Mike


Interesting! Thank you so much for the detailed explanation. :slight_smile:

1 Like

great explanation @mseaton :slightly_smiling_face: i have learnt alot

1 Like

thanks for the detailed explanation