How to compile and deploy SimBiology file on the web

3 views (last 30 days)
Hi everyone. Really need someone to assist me on this matter. I have an *.sbproj file. I know that we need to export the file and use the exported model in order to deploy it in a standalone application. But, how can I use this file for the deployment in the web? I don't have any idea on how to create the *.jar file for this case. One of the example show it this way (for standalone application),
mccCommand = ['mcc -m T1.m -N -p simbio -a exportedM1.mat', dependencies_2];
But since I need it to be in a *.jar file, I don't know how to do it. Hope someone could show me the right way to do this. Any examples will be very much appreciated. For your information, I am using Eclipse Kepler to build Java servlet and JSP and using Tomcat as the server. Thanks in advance!

Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 22 Jul 2014
Hi Zetty,
You need to take two additional steps to update this example to work with MATLAB Builder JA.
First, you need to modify the mcc command so that it produces a Java jar file instead of an executable. You do that by changing the -m option to something like -W java:package,Class. Replace package by the package you want the generated Java classes stored in, and replace Class with the name you want to use for the main class in this package. For example, to create a class named SBApp in a package pkg, you can update your sample code as follows:
mccCommand = ['mcc -W ''java:pkg,SBApp'' T1.m -N -p simbio -a exportedM1.mat ', ...
dependencies_2];
Second, you need to create a Java class that somehow runs the class in this jar file. To learn the details on that, you should inspect the generated Java code and the MATLAB Builder JA documentation. However, here's a simple class that will run the Java class created with the command above, wait until all figures are closed, and then exit:
import com.mathworks.toolbox.javabuilder.*;
import pkg.SBApp;
public class runApp {
public static void main(String[] args) {
try {
SBApp app = new SBApp();
try {
app.T1();
app.waitForFigures();
} finally {
app.dispose();
}
} catch (MWException e) {
e.printStackTrace();
}
}
}
  6 Comments
Zetty  Zakaria
Zetty Zakaria on 27 Jul 2014
Hi Arthur, thanks again! I have actually tried to work backward, where I have exported the SimBiology as equation and save all the equations in a matlab function file. It works great! But I think it's just like a redundant works. But still, your answers help me a lot! Will continue the question with Technical Support. Thanks!
Martijn
Martijn on 29 Jul 2014
To clarify: MATLAB Builder JA does indeed support showing MATLAB GUIs locally when using a MATLAB Builder JA class in a local Java application. It does not support displaying those GUIs in a browser when the classes are used in a Web Application though.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!