How to compile Brainstorm

Hi,
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,
Pan

Ref:hot-to-compile-generated-scritp/1647


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 
    com.mathworks.project.api.InvalidProjectException 
    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  
lprj 
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) 
                    findDependentFiles(obj); 
 
Error in matlab.depfun.internal.Completion/computePartsList (line 2012) 
            computeDependencies(obj); 
 
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)
            bst_deploy_java(varargin{2:end});

bst_javabuilder_2016b.prj:

    <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.appname>bst_javabuilder_2016b</param.appname>
    <param.icon />
    <param.icons />
    <param.version>1.0</param.version>
    <param.authnamewatermark>Francois Tadel</param.authnamewatermark>
    <param.email>francois.tadel@mcgill.ca</param.email>
    <param.company>McGill University</param.company>
    <param.summary />
    <param.description />
    <param.screenshot />
    <param.guid />
    <param.installpath.string>\McGill University\bst_javabuilder_2016b\</param.installpath.string>
    <param.installpath.combo>option.installpath.programfiles</param.installpath.combo>
    <param.logo />
    <param.install.notes />
    <param.target.install.notes />
    <param.intermediate>C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_testing</param.intermediate>
    <param.files.only>C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_redistribution_files_only</param.files.only>
    <param.output>C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\bst_javabuilder\for_redistribution</param.output>
    <param.enable.clean.build>false</param.enable.clean.build>
    <param.user.defined.mcr.options />
    <param.embed.ctf>true</param.embed.ctf>
    <param.target.type>subtarget.java.package</param.target.type>
    <param.support.packages />
    <param.required.mcr.products>
      <item>35000</item>
      <item>35010</item>
    </param.required.mcr.products>
    <param.namespace />
    <param.classorg />
    <param.web.mcr>false</param.web.mcr>
    <param.package.mcr>false</param.package.mcr>
    <param.no.mcr>false</param.no.mcr>
    <param.web.mcr.name>MyAppInstaller_web</param.web.mcr.name>
    <param.package.mcr.name>MyAppInstaller_mcr</param.package.mcr.name>
    <param.no.mcr.name>MyAppInstaller_app</param.no.mcr.name>
    <param.windows.command.prompt>true</param.windows.command.prompt>
    <param.create.log>false</param.create.log>
    <param.log.file />
    <param.user.only.registration>false</param.user.only.registration>
    <param.net.framework>option.net.framework.default</param.net.framework>
    <param.assembly.type>false</param.assembly.type>
    <param.encryption.key.file />
    <param.net.enable.remoting>false</param.net.enable.remoting>
    <param.net.tsa.enable>false</param.net.tsa.enable>
    <param.net.tsa.assembly />
    <param.net.tsa.interface />
    <param.net.tsa.namespace />
    <param.net.tsa.superclass>Run</param.net.tsa.superclass>
    <param.net.tsa.metadata />
    <param.net.tsa.metadata.assembly>C:\Users\admin\Desktop\brainstorm3</param.net.tsa.metadata.assembly>
    <param.net.saved.interface />
    <unset>
      <param.icon />
      <param.icons />
      <param.version />
      <param.authnamewatermark />
      <param.email />
      <param.company />
      <param.summary />
      <param.description />
      <param.screenshot />
      <param.guid />
      <param.installpath.string />
      <param.installpath.combo />
      <param.logo />
      <param.target.install.notes />
      <param.enable.clean.build />
      <param.user.defined.mcr.options />
      <param.embed.ctf />
      <param.support.packages />
      <param.namespace />
      <param.classorg />
      <param.package.mcr />
      <param.no.mcr />
      <param.web.mcr.name />
      <param.package.mcr.name />
      <param.no.mcr.name />
      <param.windows.command.prompt />
      <param.create.log />
      <param.log.file />
      <param.user.only.registration />
      <param.net.framework />
      <param.assembly.type />
      <param.encryption.key.file />
      <param.net.enable.remoting />
      <param.net.tsa.enable />
      <param.net.tsa.assembly />
      <param.net.tsa.interface />
      <param.net.tsa.namespace />
      <param.net.tsa.superclass />
      <param.net.tsa.metadata />
      <param.net.tsa.metadata.assembly />
      <param.net.saved.interface />
    </unset>
    <fileset.exports>
      <file>C:\Users\admin\Desktop\brainstorm3\brainstorm.m</file>
    </fileset.exports>
    <fileset.classes>
      <entity.package name="">
        <entity.class name="Run">
          <file>C:\Users\admin\Desktop\brainstorm3\brainstorm.m</file>
        </entity.class>
      </entity.package>
    </fileset.classes>
    <fileset.resources>
      <file>C:\Users\admin\Desktop\brainstorm3\defaults</file>
      <file>C:\Users\admin\Desktop\brainstorm3\deploy</file>
      <file>C:\Users\admin\Desktop\brainstorm3\doc</file>
      <file>C:\Users\admin\Desktop\brainstorm3\external</file>
      <file>C:\Users\admin\Desktop\brainstorm3\java</file>
      <file>C:\Users\admin\Desktop\brainstorm3\toolbox</file>
     <file>C:\Users\admin\Desktop\brainstorm3_deploy\R2016b\sigproc</file>
    </fileset.resources>
    <fileset.depfun />
    <fileset.package />
    <build-deliverables>
      <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>
    </build-deliverables>
    <workflow />
    <matlab>
      <root>C:\Program Files\MATLAB\R2016b</root>
      <toolboxes />
    </matlab>
    <platform>
      <unix>false</unix>
      <mac>false</mac>
      <windows>true</windows>
      <win2k>false</win2k>
      <winxp>false</winxp>
      <vista>false</vista>
      <linux>false</linux>
      <solaris>false</solaris>
      <osver>6.1</osver>
      <os32>false</os32>
      <os64>true</os64>
      <arch>win64</arch>
      <matlab>true</matlab>
    </platform>
  </configuration>
</deployment-project>

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.
brainstorm3_deploy.zip (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:
brainstorm3_deploy_R2020a.zip (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.
image

Can you give us the class RunCompiled for 2021a?

I haven't prepared this one yet, sorry.

Here you go:
brainstorm3_deploy_R2021a.zip (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".
https://github.com/brainstorm-tools/brainstorm3/commit/96524b178fb2bc880377e1057c77ed91e40f7527

See the new documentation section:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#How_to_compile_Brainstorm

1 Like

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