AnyLogic
Expand
Font size

Exporting models to Java application

In AnyLogic Professional, you can export your models as standalone Java applications. This provides users with the ability to run AnyLogic models standalone without AnyLogic being installed on their machines.

Java applications can communicate with databases, external files, and other applications. This feature enables you to embed simulation models into larger decision support systems.

To export a model as a Java application

  1. Select an item of the model in the Projects view and choose  Export > To standalone Java application from the main menu, or
    Right-click (Mac OS: Ctrl + click) the model in the Projects view (the top-level item of the model tree) and choose  Export > To standalone Java application from the popup menu.
  2. This opens the Export Model dialog box.

  3. Select the experiment, which settings you want to be applied to the model, from the Experiment to Export drop-down list.
  4. Specify a folder, where you want files of the exported model to be stored, in the Destination folder box. You can browse for the destination folder using the Browse button.
  5. By default, toolbar buttons and other UI elements of your standalone application will be named according to the locale settings of your computer. If you, however, plan to share your application with customers from other countries, choose another language from the Language drop-down list).
  6. If you want to browse to the exported model folder on export completion, leave the check box Browse exported model folder selected.
  7. If you plan to run this standalone model under other operating systems (for example, distribute your model to other users who might potentially use a different OS), you should provide the model with Mac OS X and Linux versions of the browser which will be used to show the standalone model’s animation.
    To download the pack of the Chromium browser, containing browser versions for Windows, Mac OS X, and Linux, click the For multiple operating systems support... link. This will start the download process. The browsers will be downloaded to the standalone model’s folder, and this will make the standalone model completely cross-platform.
  8. Click Finish. You will see a message box informing you that the model was successfully exported.

The model exported as a Java application consists of the following files:

  • <model name>_windows.bat file that is used to run the standalone application on Windows.
  • <model name>_mac file that is used to run the standalone application on Mac OS X.
  • <model name>_linux.sh file that is used to run the standalone application on Linux.
  • model.jar — the compiled model file.
  • lib folder — library files required by the model (database driver library, AnyLogic engine file (com.anylogic.engine.jar), and so on).
  • (optionally) JAR files and classes that are necessary to build the model (listed in the model dependencies).
  • (optionally) chromium folder — the Chromium package (portable Chromium browsers to display model animation on Windows, Linux, and Mac OS X).
  • AnyLogic Model User Agreement.pdf — AnyLogic Model User Agreement in Adobe Reader (.pdf) format.
  • readme.txt — brief instructions in text format;
  • license.txt — AnyLogic Model User Agreement in text format.

A simulation application (the AnyLogic model exported as a standalone Java application) does not require AnyLogic installed on the computer and can be run on any Java-enabled machine (computer with Java Standard Edition 9.0 or installed). To download the latest version, go to the Open JDK website.

To run a simulation application (the AnyLogic model exported as a standalone Java application)

  1. Launch the <model name>_<OS name>.bat/.cmd/.sh file generated for the exported model. The file should be located in the folder you have specified while exporting the model.

Upon starting the application, you will see the model window. The model exported as a standalone Java application is executed by the runtime version of the AnyLogic simulation engine — AnyLogic Engine Runtime — basically, a locally-launched server that is accessible from the browser on a certain port. With the help of the About program dialog box, you can identify the version of the AnyLogic Engine Runtime used by the model as well as the Java version and architecture (32- or 64-bit), and also get access to the license agreement.

The size of the window is defined in the properties of the exported model, in AnyLogic IDE.

If the exported model contains data from the built-in database, make sure to allocate enough memory both for the model and the DB server in the Maximum available memory property of the specified experiment before you begin the export process.

To run a model as a Java application in a specified browser

  1. In the folder containing your exported model, create the com.anylogic.engine.ini options file, as described below.
  2. Within the file, specify the path to the browser executable, using the standaloneBrowserPath option:
    standaloneBrowserPath=C\:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe
    The line above points at the Firefox installation. You may replace it with the applicable path, just make sure to use double backslashes () rather than single slashes (/).
    If a script is unable to locate the browser executable at the specified location, it will attempt to use the system default browser instead.
  3. The script can pass arguments to the specified browser. We need this to specify the address of the runtime engine. This address is already encoded in the script with the $1 variable. You need to assign this variable as the value of the standaloneBrowserCommandArguments option.
    To do that, append the following line after the path to the browser executable:
    standaloneBrowserCommandArguments=$1
  4. Launch the <model name>_<OS name>.bat/.cmd/.sh file generated for the exported model.
    The specified browser should open up, launching the model window.

To run an exported model in a custom web application

We do not recommend using standalone models in the context of custom web applications. Consider uploading your model to AnyLogic Cloud and take advantage of its embedding functionality for this purpose.

To learn how to embed models hosted in Cloud, see Embedding model animation.

To increase the model run performance, try out Private Cloud — a standalone on-premises solution for cloud-based model execution.

To pass arguments to a model exported as a standalone Java application

  1. Open the command line.
  2. Use the cd command to navigate to the folder containing the application startup script, for example:
    cd /d d:/Exported models/Call Center
  3. Enter the name of the startup script (<model name>_<os name>.bat/.cmd/.sh) and specify arguments one after another while separating them with spaces, for example:
    Call Center_windows.bat argument1 argument2

You can also choose to pass command-line arguments to the standalone application explicitly. To do that, enter the space-separated list of argument values directly within the startup script. For example, in the Windows-specific BAT file, you will need to enter it after the enumeration of all required JAR files.

No matter which way you will use, the experiment will be able to retrieve the arguments you’ve passed using its getCommandLineArguments() method. To learn more, check a description of the experiment you’re interested in in the corresponding section.

Settings of a standalone model application

To modify the settings of the model exported as a standalone Java application, create a text INI file named com.anylogic.engine.ini and save it into the exported model’s folder.

Despite having the INI extension, this file is not Windows-specific and works in other operating systems properly.

In the INI file, specify the values for the model settings you need to tune. The list of the customizable settings is given in the table below.

The example of file’s contents:

flowchartCountersVisible = false
languageId = es
Settings Description Possible values
flowchartCountersVisible This setting defines whether the counters near the process flowchart blocks (showing the numbers of agents who passed through block ports, and so on) should be displayed or not. true, false
flowchartPortStateAnimated Defines whether the "block busy" and "agent available" indicators should be shown near ports of flowchart blocks. true, false
useProxy Defines whether the proxy should be used for network connection. true, false
proxy The proxy address. URL of the proxy host.
proxyPort The proxy port. Positive integer number.
proxyLogin The proxy login.
proxyPassword The proxy password.
proxyBypassAddresses Use this setting to specify the hosts that should be accessed without the proxy.
If you use a proxy to access the Internet (for example, a GIS map server), but you also need to bypass a proxy to connect to a local server (for example, a database server), specify the local server name under this setting.
By default, all loopback addresses are bypassed.
A list of hosts, separated by the | character. Additionally, the wildcard (*) can be used.
parallelWorkersCount Number of processors (cores) to be used for parallel execution of model runs by experiments with several iterations (like parameter variation and optimization) and also by some libraries (for example, the Pedestrian Library). Positive integer number.
standaloneBrowserPath Path to the browser’s executable file. Use this setting in case you need to use not Chromium but some other browser to run the standalone model. The path should not contain single characters. Double / are preferred instead.
standaloneBrowserCommandArguments Command arguments for the custom browser. Use $1 to refer to the URL of the model runtime engine.
standaloneServerPort The port where the server with the running model will start on. This port will be used to run the model in the browser. For example, set the port to 12345 to run the model at http://localhost:12345. Positive integer number less than or equal to 65535.
Some port values might be reserved by the operating system or some services, especially values less than 1024.
languageId By default, the application UI will be in the language that was selected on model export. Here you can change it to any other language from the set of languages supported by AnyLogic: English, Russian, German, Chinese, Spanish, or Portuguese (Brasil). One of the text constants: en — English
es — Spanish
pt_BR — Portuguese (Brasil)
zh — simplified Chinese
ru — Russian
de — German

Exporting a standalone application from command line

The AnyLogic command-line interface supports the export of a model (or several models at once) as a standalone Java application.

Before calling the export command, use the cd command to change the working directory to the AnyLogic folder on your computer (specify absolute path), for example: cd C:\Program Files\AnyLogic 8.5 Professional.

The command syntax is as follows:

anylogic -e "absolute path to the exported model .alp file"

For example:

anylogic -e "D:\My Models\Call Center\Call Center.alp"

Here, -e is a common flag to run silent export. After it, you can list the paths to as many models for export as you need. The models will be loaded, built, exported, and closed one by one in the order of listing. For each model, all its experiments will be exported. By default, each experiment is put to a new folder >model name>_<experiment name> which will be created automatically in the model’s parent folder. You can also export the model to a specific folder by specifying parameter -o "folder path" in the command line.

anylogic -e -o "absolute path to the destination folder" "absolute path to the exported model ALP file"

For example:

anylogic -e -o "C:\Export\Standalone Model Applications" "D:\My Models\Call Center\Call Center.alp"

If the model only contains a default simulation experiment, the following folder will appear in the model’s parent folder: Call Center_Simulation.

Exporting a standalone application from Mac OS X Terminal

In Mac OS X, the process of exporting models to standalone applications is a bit more complex:

  1. Open Terminal.
  2. Execute the following command:
    export APP=/Applications/AnyLogic\ 8\ Professional.app
  3. After that, in the same Terminal window, execute the following command:
    open -a $APP --args -vm $APP/Contents/jre/lib/jli/libjli.dylib -startup $APP/Contents/Resources/Java/plugins/org.eclipse.equinox.launcher_1.5.700.v20200207-2156.jar --launcher.library $APP/Contents/Resources/Java/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.1200.v20200508-1552/eclipse_1902.so -e -o output input
    Replace output with the full absolute path to the folder, where AnyLogic will export the standalone application. For example: /tmp/exported-models/.
    Replace input with the full absolute path to the .alp file of the model you want to export. For example: /Users/user/Models/Model1/Model1.alp.

Exporting specific experiments

To export a particular experiment of the model, specify the experiment’s name after the model’s name in the command. To list more than one experiment, separate them by commas.

anylogic -e "D:\My Models\Call Center\Call Center.alp:Simulation,OptimizedSimulation"

Upon calling this command, the following two folders will appear in the model’s parent folder: Call Center_Simulation and Call Center_OptimizedSimulation.

Depending on whether AnyLogic is running or not, the export process will differ.

When AnyLogic is not running:

  • During export, the AnyLogic launch window will appear and the status will receive messages about the current actions.
  • Upon completion, the launch window will close automatically.
  • If no errors occurred during the export, on application exit the code will be 0. If at least one critical error occurred preventing the proper export of a model, on application exit the code will be 1, but the export will continue. If multiple models have been listed for export, only the model with the export error will not be exported.

When AnyLogic is running:

  • The application will return neither the error code nor the successful export code. You can only perform the manual check of whether the models have been exported correctly.
  • If a model with the same name and path as the model listed for export is currently open in AnyLogic, the export will be performed for the current model state.
  • If a model with the same name but a different path as the model listed for export is currently open in AnyLogic, the model will not be exported and on application exit, there will be no error code.

Dependent model support

If the exported model has another model (or several) in its list of dependencies, these models will be exported automatically.

The search for the dependencies is executed by the java package name. It starts from the exported model folder and its subfolders and then moves upwards the folder structure.

If any of the folders contain more than one ALP file that satisfies the search conditions, neither of these models will be exported. The export process will run its course, but an error message will be logged.

Opening a model from the command line

Before calling the command to open a model, use the cd command to change the working directory to the AnyLogic folder on your computer (specify absolute path), for example:

cd C:\Program Files\AnyLogic 8.5 Professional

The command syntax is as follows:

anylogic "absolute path to the model ALP file"

For example:

anylogic "D:\My Models\Call Center\Call Center.alp"

To list the paths to multiple models, separate them by spaces. The models will be opened all at once.

Alternatively, you can open models without changing the working directory to the AnyLogic folder on your computer. In this case, omit the anylogic command and specify the absolute path to the AnyLogic executable file AnyLogic.exe.

For example:

"C:\Program Files\AnyLogic 8.5 Professional\AnyLogic.exe" "D:\My Models\Call Center\Call Center.alp"

Running a specific experiment from the command line

Before running a particular experiment of the model, use the cd command to change the working directory to the AnyLogic folder on your computer (specify absolute path), for example:

cd C:\Program Files\AnyLogic 8.5 Professional

The command consists of -r flag and two arguments separated by single space.

  • Use the -r flag.
  • Specify the path to the model enclosed in quotation marks.
  • Specify the experiment’s name also enclosed in quotation marks.
You can list only one experiment.

The command syntax is as follows:

anylogic -r "absolute path to the model ALP file" "name of the experiment"

For example:

anylogic -r "D:\My Models\Call Center\Call Center.alp" "Simulation"

How can we improve this article?