How to compile Brainstorm

I encountered two problems when I tried to compile Brainstorm by modifying the two files ‘bst_deploy_java_2016b.m’ and 'bst_javabuilder_2016b.prj' under the deploy folder.
Thanks in advance for your help!

Best Regards,


Build environment:

JDK version: 1.7.0_75
MATLAB version:R2016b
System environment:Window10
Brainstorm3 source code path:C:\Users\admin\Desktop\brainstorm3

Problem 1:
When I compile brainstom by bst_deploy_java_2016b.m, I got some error messages.
I found that the brainstorm3_deploy\R2016b\sigproc file is missing.

Error Message

    DEPLOY> Starting Matlab Compiler...
    Error: Caught exception when building project: C:\Users\admin\Desktop\brainstorm3\deploy\bst_javabuilder_2016b.prj 
    File sigproc from Files required for your library to run does not exist. 
    DEPLOY> Packaging binary distribution...

Problem 2:
When I went to step system(['deploytool -build ', compilerFile]), the program (bst_deploy_java_2016b.m) went wrong.

Error Message

DEPLOY> Starting Matlab Compiler...
Start build process 
mcc -W 'java:bst_javabuilder_2016b,Run' -T link:lib -d C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing class{Run:C:\Users\admin\Desktop\brainstorm3\brainstorm.m} -a C:\Users\admin\Desktop\brainstorm3\defaults -a C:\Users\admin\Desktop\brainstorm3\deploy -a C:\Users\admin\Desktop\brainstorm3\doc -a C:\Users\admin\Desktop\brainstorm3\external -a C:\Users\admin\Desktop\brainstorm3\java -a C:\Users\admin\Desktop\brainstorm3\toolbox  
Error using getSymbolNames 
Import argument "org.brainstorm.tree.BstNode" in MATLAB code 
'C:\Users\admin\Desktop\brainstorm3\toolbox\tree\node_create_subject.m' cannot 
be found or cannot be imported. 
Error in matlab.depfun.internal.MatlabInspector/getSymbols (line 161) 
            [F, S] = getSymbolNames(w); 
Error in matlab.depfun.internal.MwFileInspector/analyzeSymbol (line 33) 
            symlist = getSymbols(obj, client.WhichResult); 
Error in matlab.depfun.internal.Completion/findDependentFiles (line 1349) 
                    analyzeSymbol(inspector, symbol); 
Error in matlab.depfun.internal.Completion/computeDependencies (line 263) 
Error in matlab.depfun.internal.Completion/computePartsList (line 2012) 
Error in matlab.depfun.internal.Completion/requirements (line 2412) 
            parts = computePartsList(obj, false); 
Error in matlab.depfun.internal.requirements (line 215) 
    [parts, resources.products, resources.platforms] = c.requirements(); 
mcc -W 'java:bst_javabuilder_2016b,Run' -T 'link:lib' -d 'C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing' 'class{Run:C:\Users\admin\Desktop\brainstorm3\brainstorm.m}' -a 'C:\Users\admin\Desktop\brainstorm3\defaults' -a 'C:\Users\admin\Desktop\brainstorm3\deploy' -a 'C:\Users\admin\Desktop\brainstorm3\doc' -a 'C:\Users\admin\Desktop\brainstorm3\external' -a 'C:\Users\admin\Desktop\brainstorm3\java' -a 'C:\Users\admin\Desktop\brainstorm3\toolbox'  
Unexpected error while determining required deployable files. Compilation terminated. 
Build failed 
DEPLOY> Packaging binary distribution...
Error using bst_deploy_java_2016b (line 279)
Compilation is incomplete: cannot package the binary distribution.

Error in brainstorm (line 340)


    <deployment-project plugin="plugin.ezdeploy" plugin-version="1.0">
  <configuration build-checksum="805395868" file="C:\Users\admin\Desktop\brainstorm3\deploy\bst_javabuilder_2016b.prj" location="C:\Users\admin\Desktop\brainstorm3\deploy" name="bst_javabuilder_2016b" target="target.ezdeploy.library" target-name="Library Compiler">
    <param.icon />
    <param.icons />
    <param.authnamewatermark>Francois Tadel</param.authnamewatermark>
    <>McGill University</>
    <param.summary />
    <param.description />
    <param.screenshot />
    <param.guid />
    <param.installpath.string>\McGill University\bst_javabuilder_2016b\</param.installpath.string>
    <param.logo />
    <param.install.notes />
    < />
    <param.user.defined.mcr.options />
    < />
    <param.namespace />
    <param.classorg />
    <param.log.file />
    <param.encryption.key.file />
    < />
    < />
    < />
    < />
    < />
      <param.icon />
      <param.icons />
      <param.version />
      <param.authnamewatermark />
      < />
      < />
      <param.summary />
      <param.description />
      <param.screenshot />
      <param.guid />
      <param.installpath.string />
      <param.installpath.combo />
      <param.logo />
      < />
      < />
      <param.user.defined.mcr.options />
      <param.embed.ctf />
      < />
      <param.namespace />
      <param.classorg />
      <param.package.mcr />
      < />
      < />
      < />
      < />
      < />
      <param.create.log />
      <param.log.file />
      <param.user.only.registration />
      < />
      <param.assembly.type />
      <param.encryption.key.file />
      < />
      < />
      < />
      < />
      < />
      < />
      < />
      < />
      < />
      <entity.package name="">
        <entity.class name="Run">
    <fileset.depfun />
    <fileset.package />
      <file location="C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing" name="bst_javabuilder_2016b.jar" optional="false">C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing\bst_javabuilder_2016b.jar</file>
      <file location="C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing" name="doc" optional="false">C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing\doc</file>
      <file location="C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing" name="readme.txt" optional="true">C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing\readme.txt</file>
    <workflow />
      <root>C:\Program Files\MATLAB\R2016b</root>
      <toolboxes />

up up... :joy: :joy:

Compiling Brainstorm requires additional files, we don't support this for the general users.
This is too complicated to set up for us to try to generalize it.
There is a lot that can be done with executing custom scripts with the compiled version. Example: Scripting to create multiple subjects

Why do you need to compile Brainstorm if you already have Matlab?

Thank you for the reply. :grin: :grin:

Because I added some native Matlab function to process MEG data in the script generated by Brainstorm. But when I run the the script on a server with the compiled brainstorm, the script crashed. And I found you mentioned in the forum that when using the free MCR library instead of a full Matlab license, I am not allowed by the Mathworks to execute my own .m scripts, I can only run the programs that were compiled with the Matlab Compiler.

In addition, I found that the brainstorm custom_script.m can't handle when custom_script.m calls another function defined by me.

So I searched through the forum and found that this problem can be solved by compiling Brainstorm. That's why I decided to compile Brainstorm.

Finally, can you provide some additional files for compiling Brainstorm?

Thanks in advance for your help!

:joy: :joy:

Here are the missing files. (205.6 KB)

Be aware that this might be breaking the Mathworks customer agreement you signed when installing Matlab and the MCR. Please try to deal with this on your own.

Thanks Francois! :grin: :grin:

I successfully compiled the system using 2020A and generated an executable file, but the file is only 32MB, which is significantly smaller than your executable file. Moreover, my file did not work normally after double clicking, but there was no error prompt during compilation.Please tell me what to do,thanks!

I successfully compiled the system using 2020A and generated an executable file, but the file is only 32MB, which is significantly smaller than your executable file.

The package on the website is built including SPM, FieldTrip, and many other plugins. This is why it is twice as large.

Moreover, my file did not work normally after double clicking

You need to run the .bat file.
Run it from a terminal (CMD) so that you can get the error messages at startup.

but there was no error prompt during compilation

There is an error: this warning about a missing file probably cause the packaging to fail.
I don't think I'll be able to help you debugging this, this is going to be too specific to your computer.
Good luck!

First of all, thank you for your answer. My execution results isshown in the figure. Does that mean that I can only compile with 2019a or lower? Or how to form a higher version of runcompiled.class?

The recommended version for compilation is currently Matlab 2020a.
Here is the class RunCompiled for 2020a: (36.7 KB)

Great. It's working normally. These two days of efforts have not been in vain. Thank you very much for your sharing and contribution.

Can you give us the class RunCompiled for 2021a?

I haven't prepared this one yet, sorry.

Here you go: (35.8 KB)

I realized that deploytool was going to be soon deprecated for compiling Matlab programs as .jar, therefore I worked on a new deployment/compilation system.

I made the compilation much more portable. Now you should not need any extra files that are only available on my computer :slight_smile:
From any Brainstorm installation, it should work by running only "brainstorm compile noplugs".

See the new documentation section:

1 Like

@Raymundo.Cassani If you have a windows computer around, could you try this please?