MATLAB: Does JBoss 7.1 throw a Segmentation Violation when trying to call a MATLAB Builder JA 2.2.4 (R2012a) Java class

MATLAB Compiler SDK

I have compiled my MATLAB Code into a MATLAB Builder JA Java class and I have developed a Web Service which calls this class. I now am trying to deploy this Web Application to a JBoss 7.1 Application Server. As soon as I instantiate an instance of my MATLAB Builder JA class, the server shows a segmentation violation in its output:
Stack Trace (from fault):
[ 0] 0x000000006d9c395d c:\Program Files\Java\jdk1.6.0_27\jre\bin\server\jvm.dll+01259869 ( JNI_CreateJavaVM+002221 )
[ 1] 0x000000006d9c3d4f c:\Program Files\Java\jdk1.6.0_27\jre\bin\server\jvm.dll+01260879 ( JNI_CreateJavaVM+003231 )
[ 2] 0x000000007572fc5b C:\MATLAB\R2012a\bin\win64\jmi.dll+00130139 ( mljGetStaticMethod+000059 )
[ 3] 0x000000005415ce04 C:\MATLAB\R2012a\bin\win64\hg.dll+02936324 ( hg::ScreenDataUpdate::operator=+000116 )
[ 4] 0x000000005415d0c5 C:\MATLAB\R2012a\bin\win64\hg.dll+02937029 ( hg::ScreenDataUpdate::setScreenDataCache+000229 )
[ 5] 0x000000005415d139 C:\MATLAB\R2012a\bin\win64\hg.dll+02937145 ( hg::ScreenDataUpdate::setScreenDataCache+000345 )
[ 6] 0x0000000053f7a40e C:\MATLAB\R2012a\bin\win64\hg.dll+00959502 ( MLInitialize_hg+000318 )
[ 7] 0x000000005386f9da C:\MATLAB\R2012a\bin\win64\hgbuiltins.dll+00260570 ( hgutils::HitImpl::HitImpl+022042 )
[ 8] 0x000000006224b21f C:\MATLAB\R2012a\bin\win64\m_dispatcher.dll+00045599 ( Mfh_file::dispatch_fh+000959 )
[ 9] 0x000000006224b7ee C:\MATLAB\R2012a\bin\win64\m_dispatcher.dll+00047086 ( Mfunction_handle::dispatch+000478 )
[ 10] 0x00000000548b4ff3 C:\MATLAB\R2012a\bin\win64\m_interpreter.dll+00479219 ( inDestroyWS+193347 )
(snip)
Then the server either keeps running (then when I try my Web Application for a second time it works fine), or the whole server crashes.

Best Answer

This crash is related to intializing the Handle Graphics system of the MCR which requires the sun.awt.DisplayChangedListener class. By default this class cannot be loaded in JBoss 7.1.
To work around this issue:
1. You can add the following option to the (end of) your JBoss JAVA_OPTS setting:
-Djboss.modules.system.pkgs=sun.awt
This will allow the required class to be loaded in JBoss 7.1.
2. Or, if you do not make use of any of the handle graphics features of MATLAB anyway, you can disable it by:
a. Disabling the JVM completely. You do this by intializing the MCR in your Web Application through:
MWApplication.initialize(MWMCROption.NOJVM);
b.If you are on a Linux system, you can also choose to keep the JVM enabled and only disable the DISPLAY:
MWApplication.initialize(MWMCROption.NODISPLAY);
Related Question