MATLAB: Matlab compiled jar cannot run with task scheduler but can run manually

compiled matlabtask scheduler

Hello everyone,
I have some matlab-code, which included as jar-File (created with matlab compiler sdk) in a java-application. If I start my java-application manually using a bat-file everything works. But if I start the same bat-file using the windows task scheduler the matlab-code cannot be executed. (The other parts of the java-application work in both cases)
Stacktrace:
... Matlab M-code Stack Trace ...
com.mathworks.toolbox.javabuilder.MWException: An error occurred while initializing the component.
Could not access the MATLAB Runtime component cache. Details: Some error has occurred in the file: b:\matlab\standalone\mclmcr\mcr_cache\mclcomponentcache.cpp, at line: 250.
The error message is:
Failed to completely extract component!
at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclInitializeComponentInstance(Native Method)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$700(MWMCR.java:31)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclInitializeComponentInstance(MWMCR.java:888)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:770)
at com.sun.proxy.$Proxy79.mclInitializeComponentInstance(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.newInstance(MWMCR.java:632)
I also don't understand why it's accessing drive B. The file and the matlab runtime installation is located on drive C.
Things I already checked:
  • Path variable of the matlab runtine installation
  • Check the cache files (https://de.mathworks.com/matlabcentral/answers/33638-could-not-access-the-mcr-component-cache-error)
  • Setting an env-variable MCR_ROOT_CACHE to a temp-folder (didn't found the link again)
  • I tried to compile with -C but it fails:Packaging…Creating the bundle…Failed to create the install bundle[…]\for_testing\de.ctf (The system cannot find the file specified)
Setup:
  • Matlab 2016b
  • Java 8
  • win server 2012 (64bit)
Would be great, if someone give me a hint. Thanks, Thomas

Best Answer

I am not sure what might be the issue, but there are few things you might try:
1) It may be a permission issue. Make sure that you have the right permissions to access MCR cache folder. Can you try changing MCR_CACHE_ROOT to some other folder and see if it makes any difference.
2) Is your application accessed/shared by multiple users? (Again look for the permissions for all the users even within your system.)
3) Did you correctly provide 'start-in' directory while creating the task? This discussion might be helpful: http://stackoverflow.com/questions/1020023/specifying-start-in-directory-in-schtasks-command-in-windows
Related Question