Overview of MATLAB Builder JA Java integration


Need to add the javabuilder.jar Library to the Apache Tomcat folder of global JARs:

  • javabuilder.jar location: $(MATLAB_HOME)/toolbox/javabuilder/jar/
  • Tomcat lib dir: $(TOMCAT_HOME)/lib

Creating a dummy Java webapp: End to End Example

  1. Download the code from MATLAB Central
  2. Make sure the path for MATLAB's libraries is correctly set:
    export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/MATLAB_R2013b.app/sys/os/maci64/:/Applications/MATLAB_R2013b.app/runtime/maci64/:/Applications/MATLAB_R2013b.app/bin/maci64/
  3. Copy your web servers servlet-api.jar file into this directory;
  4. Copy the javabuilder.jar file from your MATLAB or MCR install root in the directory /toolbox/javabuilder/jar/javabuilder.jar to the web applications lib folder ./webapp/WEB-INF/lib
  5. Recompile the MATLAB component by running the following MCC command:
    /Applications/MATLAB_R2013b.app/bin/mcc -W "java:examples,MagicCalc" -d ./scratch -T "link:lib" -v "class{MagicCalc:./webapp/WEB-INF/mcode/getMagic.m,./webapp/WEB-INF/mcode/getMagicWebFigure.m}" 
    • this will generate the contents of scratch
  6. Copy the deployed component from the scratch folder to the web applications lib folder .\webapp\WEB-INF\lib
    cp ./scratch/examples.jar ./webapp/WEB-INF/lib 
  7. Compile the web application making sure to reference the servlet-api.jar, the deployed component jar, and the javabuilder.jar
    javac -cp servlet-api.jar:./webapp/WEB-INF/lib/javabuilder.jar:./webapp/WEB-INF/lib/examples.jar: -d ./webapp/WEB-INF/classes ./webapp/WEB-INF/src/MagicSquareServlet.java
  8. Navigate to the web applications directory and create the war file.
    cd webapp
    jar -cvf ../JavaEndToEnd.war .
    cd ..
  9. Copy this JavaEndToEnd.war file into your web servers webapps directory
  10. Start the web server and navigate in a browser to the following url:

Folder Structure

├── scratch
│   ├── classes
│   │   └── examples
│   ├── doc
│   │   └── html
│   │       ├── examples
│   │       └── resources
│   └── examples
└── webapp
    └── WEB-INF
        ├── classes
        ├── lib
        ├── mcode
        └── src