Fork me on GitHub

Run SARL Agent from the Command Line

For running an agent, you must launch this agent on the runtime environment. This document explains how to launch an agent on the Janus platform from the command line.

Three methods could be used for launching an agent with Janus:

1. Use the janus command-line tool

The SARL project provides a command-line tool for launching agents on the Janus runtime environment.

1.1. Download the janus command-line tool

You could download this command line tool, named "janus" on the downloading page of SARL.

1.2. Launching the agent

For launching an agent, you must launch the command-line tool with the fully-qualified name of the agent as parameter, myapp.MyAgent in the following example.

janus myapp.MyAgent

The janus command-line tool provides options that will enable you to tune the launching configuration:

janus --help

One of the command-line options that is usually mandatory is the --jar option, which enables you to specify the jar files that contains your application:

janus --jar path/to/myapp.jar myapp.MyAgent

If the janus script indicates to you an error "agent not found", most of the time it is because your application's jar file is not on the class path. The --jar option becomes mandatory for specifying the jar file.

2. Use the standard java method

2.1. Boot of Janus

The Janus platform provides a Boot class. For launching the platform, you must execute this boot class in a Java Virtual Machine.

The typical command line is:

java -cp app.jar io.janusproject.Boot

The option -cp specifies the Jar file that contains the compiled classes. The given app.jar file is a Jar file that is containing the Janus platform, the SARL libraries, and the application classes. The last argument is the fully qualified name of the booting class of Janus: io.janusproject.Boot

2.2. Specify the Agent to Launch

The example given in the previous section causes an error. Indeed, it is mandatory to specify the fully qualified name of the agent to launch:

java -cp app.jar io.janusproject.Boot myapp.MyAgent

The Janus platform allows to start only one agent from the command line. If you want to start a collection of agents, you must select one of the following approaches:

2.3. What is app.jar?

In the previous section, we assume that all the application binary files are contained into the app.jar file.

You may replace the app.jar in the previous command lines by the classpath that is containing all the jar files required for running your application, including the Janus jar file(s):

java -cp /path/to/myapplication.jar:/path/to/io.janusproject.kernel-<version>-with-dependencies.jar io.janusproject.Boot myapp.MyAgent

The io.janusproject.kernel-<version>-with-dependencies.jar file may be dowloaded from the Janus website

You may also create the app.jar file with Maven by using the assembly plugin for creating a jar file with all the dependencies inside.

2.4. Janus Command Line Options

The Janus platform provides a collection of command line options. For obtaining the list of these options, you should type:

java -cp app.jar io.janusproject.Boot --help

3. Use Maven Execution Plugin

Maven provides a plugin for launching an application after automatically building the application's classpath. This plugin may be used for launching an agent.

3.1. Boot of Janus

Based on the fact that the Janus platform provides a Boot class for launching itself, you may use the Maven execution plugin for classing this booting class.

The typical command line is:

mvn exec:exec -Dexec.executable=java -Dexec.args="-cp %classpath io.janusproject.Boot"

The option -Dexec.executable specifies the Java executable.

The option -Dexec.args contains the command line arguments to pass to Java. The first argument is the classpath of the project. You must not change %classpath because it will be dynamically replaced by the Maven plugin.

3.2. Specify the Agent to Launch

The example given in the previous section causes an error. Indeed, it is mandatory to specify the fully qualified name of the agent to launch:

mvn exec:exec -Dexec.executable=java -Dexec.args="-cp %classpath io.janusproject.Boot <qualified_name_of_the_agent>"

The Janus platform allows to start only one agent from the command line. If you want to start a collection of agents, you must select one of the following approaches:

3.3. Janus Command Line Options

The Janus platform provides a collection of command line options. For obtaining the list of these options, you should type:

mvn exec:exec -Dexec.executable=java -Dexec.args="-cp %classpath io.janusproject.Boot --help"

4. What's next?

In the next section, we will learn how to launch your SARL project from a Java program.

Next>

Copyright © 2014-2018 the original authors or authors.

Licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the License. You may obtain a copy of the License.

You are free to reproduce the content of this page on copyleft websites such as Wikipedia.

Generated with the translator io.sarl.maven.docs.generator 0.8.0.