| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder JA |
| Contents | Index |
| Learn more about MATLAB Builder JA |
| On this page… |
|---|
Generating the Web Archive (WAR) File |
This example demonstrates how to display a plot created by a Java servlet calling a component created with the MATLAB Builder JA product over a Web interface. This example uses MATLAB varargin and varargout for optional input and output to the varargexample.m function. For more information about varargin and varargout, see How MATLAB Builder JA Handles Data.
This section describes what you need to know and do before you create the Web deployment example.
The following products must be installed at their recommended release levels.
MATLAB, MATLAB Compiler, MATLAB Builder JA. This example was tested with R2007b.
Java Development Kit (JDK). Ensure you have Sun JDK v1.6.0 installed on your system. You can download it from Sun Microsystems, Inc.
In order to run this example, your Web server must be capable of running accepted Java frameworks like J2EE. Running the WebFigures demo (Deploying a Java Component Over the Web) also requires the ability to run servlets in WARs (Web Archives).
Ensure that the javabuilder.jar library (matlabroot/toolbox/javabuilder/jar/javabuilder.jar) has been installed into your Web server's common library folder.
Download the demo files from the File Exchange at MATLAB Central. With File Exchange selected in the Search drop-down box, enter the keyword java_web_vararg_demo and click Go.
The demo files contain the following three folders:
mcode — Contains all of the MATLAB source code.
JavaCode — Contains the required Java files and libraries.
compile — Contains some helpful MATLAB functions to compile and clean up the demo.
Note As an alternative to compiling the demo code manually and creating the application WAR (Web Archive) manually, you can run compileVarArgServletDemo.m in the compile folder. If you choose this option and want to change the locations of the output files, edit the values in getVarArgServletDemoSettings.m. If you choose to run compileVarArgServletDemo.m, consult the readme file in the download for additional information and then skip to Running the Web Deployment Demo. |
Build your Java component by compiling your code into a deployable Java component .jar file.
Note For a more detailed explanation of building a Java component, including further details on setting up your Java environment, the src and distrib folders, and other information, see Getting Started |
Start deploytool at the MATLAB command line.
You create a Java application by using the Deployment Tool GUI to build a Java class that wraps around your M-code.
To compile or build the Java application using the Deployment Tool, use the following information as you work through this example in Building the Java Component:
| Project Name | vararg_java |
| Class Name | vararg_javaclass |
| File to compile | varargexample.m |
Use javac to compile the Java source file VarArgServletClass.java from demo folder JavaCode\src\VarArg.
javac.exe should be located in the bin folder of your JDK installation.
Ensure your classpath is set to include:
javabuilder.jar (shipped with the MATLAB Builder JA product)
servlet-api.jar (in the demo folder JavaCode\lib)
For more details about using javac, see the Sun Microsystems, Inc. Web site.
Web archive or WAR files are a type of Java Archive used to deploy J2EE and JSP servlets. To run this example you will need to use the jar command to generate the final WAR file that runs the application. To do this, follow these steps:
Copy the JAR file created using the MATLAB Builder JA product into the JavaCode\build\WEB-INF\lib demo folder.
Copy the compiled Java class to the JavaCode\build\WEB-INF\classes demo folder.
Use the jar command to generate the final WAR as follows:
jar cf VarArgServlet.war -C build .
For more information about the jar command, refer to the Sun Microsystems, Inc. Web site.
When you're ready to run the application, do the following:
Install the VarArgServlet.war file into your Web server's webapps folder.
Run the application by entering http://localhost:port_number/VarArgServlet in the address field of your Web browser, where port_number is the port that your Web server is configured to use (usually 8080).
To use the application, do the following on the http://localhost/VarArgServlet Web page:

Enter any amount of numbers to plot in the Data to Plot field.
Select Line Color and Border Color using the Optional Input drop-down lists. Note that these optional inputs are passed as varargin to the compiled M-code.
Select additional information you want to output, such as mean and standard deviation, by clicking an option in the Optional Output area. Note that these optional outputs are set as varargout from the compiled M-code.
Click Display Plot. Example output is shown below using the Mean optional output.

![]() | Optimization Example | Deploying a Java Component Over the Web | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |