MATLAB: Matlab 2011 integration with java

javaMATLAB

Guys:
I've been facing a problem with integrating an opensource RTI from Portico which was developed in c++ (MS Visual C++ 2010) and a java library portico.jar developed in java 1.7
The problem is I declare portico.jar in the classpath.txt file and run my program developed in c++ I get the following error messages:
java.lang.UnsupportedClassVersionError: org/jgroups/blocks/RequestHandler : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.portico.bindings.jgroups.JGroupsConnection.getFederationChannel(JGroupsConnection.java:215) at org.portico.bindings.jgroups.JGroupsConnection.createFederation(JGroupsConnection.java:229) at org.portico.lrc.services.federation.handlers.outgoing.CreateFederationHandler.process(CreateFederationHandler.java:79) at org.portico.utils.messaging.MessageSink.process(MessageSink.java:187) at org.portico.impl.hla1516e.Impl1516eHelper.processMessage(Impl1516eHelper.java:99) at org.portico.impl.hla1516e.Rti1516eAmbassador.processMessage(Rti1516eAmbassador.java:5473) at org.portico.impl.hla1516e.Rti1516eAmbassador.createFederation
Seems that it has to do with the java version used by matlab which is 1.6 (for all versions including the recent 2013).
I need to know if there is a workaround to allow jar files in version 1.7 run with matlab.
Sincerely, Andre Nudel

Best Answer

Hi,
MATLAB uses JAVA 6 so JAVA 7 compiled files wont work. However you can change the JAVA version MATLAB uses by creating an environment variable called MATLAB_JAVA whcih points to the JRE7 installation folder.
This can work but can also lead to undesirable behavior of MATLAB especially selfmade MATLAB GUIs can behave strange.
Related Question