Skip to Main Content Skip to Search
Product Documentation

Quick Start: Deploying a Component with the Hello World Example

MATLAB Programmer

RoleKnowledge BaseResponsibilities

MATLAB programmer
  • MATLAB expert

  • No IT experience

  • No access to IT systems

  • Develops models; implements in MATLAB

  • Uses tools to create a component that is used by the Java developer

About the Hello World Example

This section gives a very brief example of MATLAB Builder JA functionality. For a more extensive starter example, refer to The Magic Square Example.

Watch a Video

Watch a video about deploying applications using MATLAB Builder JA.

Before Running the Hello World Example

Before running this example, configure your environment. See Configuring Your Environment .

The Hello World Example

To write a function in MATLAB that displays the text hello world as output, you define the following function as hello.m.

function hello
% This is the hello, world function written in MATLAB code

% Copyright 2010 The MathWorks, Inc.
% $Revision: 1.1.6.43.2.2 $
%
        fprintf(1,'Hello, World\n' );

You can find the example code for hello.m at install_root\extern\examples\compiler\hello.m.

Building the Java Component

You create a Java application by using the Deployment Tool GUI to build a Java class that wraps around the sample MATLAB code discussed in The Hello World Example.

To compile or build hello using the Deployment Tool, use the following information as you work through this example:

Project namehelloprj
Class namehellocls
Package namehellopck
File to compilehello.m

  1. Start MATLAB, if you have not done so already.

  2. Type deploytool at the command prompt, and press Enter. The Deployment Project dialog box opens.

    The Deployment Project Dialog Box

  3. Create a deployment project using the Deployment Project dialog box:

    1. Type the name of your project in the Name field.

    2. Enter the location of the project in the Location field. Alternately, navigate to the location.

    3. Select the target for the deployment project from the Target drop-down menu.

    4. Click OK.

      Tip   You can inspect the values in the Settings dialog before building your project. To do so, click the Action icon ( ) on the toolbar, and then click Settings. Verify where your src and distrib folders will be created because you will need to reference these folders later.

  4. On the Build tab:

    • If you are building a Java application, click Add class. Type the name of the class in the Class Name field, designated by the letter c:

      For this class, add MATLAB files you want to compile by clicking Add files then click Open to select the file or files. To add another class, click Add class.

    • You may optionally add supporting files. For examples of these files, see the deploytool Help. To add these files, in the Shared Resources and Helper Files area:

      1. Click Add files/directories

      2. Click Open to select the file or files.

  5. When you complete your changes, click the Build button ( ).

 What Is a MATLAB Builder JA Project?

 What Is a MATLAB Builder JA Component?

Deploying Hello World on a Computer with MATLAB, MATLAB Compiler, and MATLAB Builder JA Installed

Run Hello World by entering the following from a system command shell.

  1. Before proceeding, ensure you have renamed you package file to hellopck. When a component is built, the package name is the same as the project name, by default. To change the package name, click the Actions icon and select Settings.

  2. Navigate to the directory containing the JAR file.

  3. Run the following command on:

    • Windows:

      java -classpath 
      matlabroot\toolbox\javabuilder\jar\javabuilder.jar;hellopck.jar 
             hellopck.hellocls 
      
    • UNIX:

      % java -classpath 
      matlabroot/toolbox/javabuilder/jar/javabuilder.jar:hellopck.jar 
             hellopck.hellocls 
      

    where matlabroot is the location of your MATLAB installation.

      Note   The above command should be entered on one continuous line.

Deploying Hello World on a Computer with Only the MATLAB Compiler Runtime (MCR) Installed (MATLAB Not Installed)

  1. Before proceeding, ensure you have renamed you package file to hellopck. When a component is built, the package name is the same as the project name, by default. To change the package name, click the Actions icon and select Settings.

  2. Run Hello World by entering the following from a system command shell. Ensure you are running from a directory defined to the JAVA_HOME variable. See Setting Up Your Java Environment for more information.

    • Windows:

      java -classpath 
               MCRROOT\toolbox\javabuilder\jar\javabuilder.jar;hellopck.jar 
                    hellopck.hellocls 
      
    • UNIX:

      % java -classpath 
               MCRROOT/toolbox/javabuilder/jar/javabuilder.jar:hellopck.jar 
                    hellopck.hellocls 
      

    where MCRROOT is the location of your MCR installation

      Note   The above command should be entered on one continuous line.

  3. If you are running UNIX, set your system path appropriately. See Directories Required for Development and Testing and Directories Required for Run-Time Deployment.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS