MATLAB: Do I get an “Unable to initialize com.mathwo​rks.mwswin​g.MJStartu​p” error when I launch MATLAB 7.8 (R2009a) on a second display in Linux

MATLABmultiplenumberscreen

I have defined my xorg.conf file to configure a dual monitor setup for my Linux machine. Please note that I am not using xinerama mode. In other words, the two displays are separate and are not merged into one desktop.
When I launch MATLAB on the first display (environment variable DISPLAY = :0.0), it works fine. However, when I launch MATLAB on the second display (DISPLAY = :0.1), I get the following error:
Unable to initialize com.mathworks.mwswing.MJStartup
...
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.jmi.bean.MatlabBeanInterface.addCallback(MatlabBeanInterface.java:691)
at com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback(MatlabCallbackInterface.java:128)
...

Best Answer

Please note that MATLAB is officially supported only for single monitor setups.
You can try to work around this issue by changing the Java Virtual Machine that MATLAB uses. See the related solution below for instructions on how to do this.
To check that MATLAB is using the new JVM, launch MATLAB using the -nodisplay option and enter 'version -java' at the MATLAB command prompt.
If MATLAB is not using the new JVM, you may need to create a symbolic link from MATLAB's Java path (for example, /usr/local/matlab/sys/java/jre/glnxa64/jre1.6.0_13) to the new JVM. Then add a file called /usr/local/matlab/sys/java/jre/glnxa64/jre.cfg to contain the single line:
1.6.0_13