Mathematica Application Projects


This section describes the way that a Mathematica application can be used in a Workbench project.

Typically, each application should live in one Workbench project. The recommended layout for a project that contains an application is shown below.

Applications

In this example the project contains an application, ComputeTools, a folder for tests, and a notebook ComputeTools.nb that can be used to execute code in the application.

This is a description and explanation of some of the contents.

Project Name

In this example the project is called ComputeToolsProject. The project name is only used in the Workbench, it is not used inside the application, and it is not used when the application is deployed to Mathematica.

The name should probably be something that describes what the project contains. The Workbench project wizards often create a project with the same name as the application. In this example it is given a different name to help to distinguish it from the application.

Application Name

In this example the application is called ComputeTools. This is the name given to the top-level folder that contains the application; it is also the name given to the main package file ComputeTools.m. The name of the application is important; it should match the name of the folder and the context for the application.

Application Contents

Typically, the folder that contains the application, here called ComputeTools, is located at the top of the project. Many features of the Workbench, such as launching or project export, look for it here. However, it is possible to place the application folder elsewhere, for example, nested more deeply in some other folder. To do this a setting for the Source in the Mathematica project paths is needed. This will then be used by the Workbench to locate the source for the application.

The other resources that the application provides, such as stylesheets or J/Link classes, also have to be specified with the Mathematica project paths system.

Application Context

In this example, the application context is ComputeTools`. It appears in the main package, ComputeTools.m, as shown in the following.

The context should match the name of the package file and the name of the application folder. The application context is used by Mathematica to load the application, for example, with a command such as Needs.

Multiple Packages

In this example there is only one package, the main application package, called ComputeTools. If you want to have more than one package in your application, this is quite possible. You simply place the extra packages in the application folder.

In this example two more packages, ExtraTools.m and Utilities.m, have been added. These have package contexts, ComputeTools`ExtraTools` and ComputeTools`Utilities`, respectively. A sample of ExtraTools.m is shown below.

Multiple Applications and Project References

If you want to develop several applications which refer to each other, you can do this using project references. Suppose that you have two applications, App1 and App2. Furthermore, App1 needs functions from App2, for example, it contains the declaration BeginPackage["App1", "App2"].

In this case you could set up two projects in the Workbench, one for each application. Then you could set a reference from App1 to App2. You can do this by right-clicking on the project and choosing Project References. You can then select App2 as shown below.

Applications

When you run or debug the project for App1 the Workbench will add the source for App2 so that this gets used as well.