For running an agent, you must launch this agent on the runtime environment. In this document, we assume that the runtime environment is the Janus platform.
Two major methods are available for launching a SARL application inside the SARL Eclipse IDE:
The SARL launch configuration is recommended.
For launching the SARL agents on the runtime environment inside the SARL Eclipse IDE, you must define a Run Configuration.
Very Important Note The SARL launch configuration adds automatically the Jar files of the SRE (e.g., Janus) on the application classpath. It means that you don’t need to add any SRE, including Janus, in the dependencies of your project if you plan to use this launching method.
Open the run configuration dialog box by selecting Run > Run Configurations, and create a new SARL application. You obtain a page similar to:
Change the name of the run configuration, and select the project, which is containing your agent.
The second step is the specification of the agent to launch. Keep in mind that you can only give one start-up agent to the runtime environment. The other agents will be spawned by the specified start-up agent.
The start-up agent is given in the Agent qualified name field of the Main tab. You must enter the fully qualified name of the agent that must be launched.
At the bottom of this page, you may change configuration options for the runtime environment.
For running your agent, you must specify a SARL runtime environment. In this tutorial, we assume that you want to use the Janus platform.
If you don’t want to use the Janus platform, you must download the runtime environment that you want to use, and install it in the SARL Eclipse environment as follow. You add a SARL runtime environment (or SRE) in the Runtime environment tab. You should click on the Installed SREs button for managing the installed runtime environments (or open the corresponding preference page). After adding the SRE’s JAR file, you obtain a dialog box similar to:
It is possible to give arguments to the launched agent.
Indeed, all the arguments given as program arguments
are put in the parameters
attribute of the Initialize
event.
This event is fired when the launched agent is started.
The following example gives the values FirstArgument
and
SecondArgument
to the launched agent:
On this page, you could also specify the parameters to give to the SARL runtime environment or to the Java virtual machine.
For launching the SARL agents on the Janus runtime environment inside the Eclipse IDE, you must define a Run Configuration.
This section is dedicated to the definition of a launcher for Java application (the standard and classical launching configuration in the Eclipse community).
Very Important Note The Janus application configuration does not add automatically the Jar files of the SRE (e.g., Janus) on the application classpath. It means that you must add an SRE, e.g. Janus, in the dependencies of your project if you plan to use this launching method.
Open the run configuration dialog box by selecting Run > Run Configurations, and create a new Java Application. You obtain a page similar to:
Change the name of the run configuration, and select the project, which is containing your agent.
For running your agent with the Janus runtime environment, you must add the Janus library in the class path.
For adding the Janus library, select the Classpath tab, and User Entries. Click on the Advanced button. You will be able to select the type of classpath entry to add. Select “Add Library”.
Then, you are able to select the library for the Janus runtime environment.
You can go back to the Main tab, and enter the Main class.
The main class must always be io.sarl.sre.janus.boot.Boot
.
The last step is the specification of the agent to launch. Keep in mind that you can give to the Janus runtime environment only one start-up agent. The other agents will be spawn by the specified start-up agent.
The start-up agent is given in the Program arguments field of the Arguments tab. You must enter the fully qualified name of the agent that must be launched.
It is possible to give arguments to the launched agent.
Indeed, all the arguments given as program arguments
are put in the parameters
attribute of the Initialize
event.
This event is fired when the launched agent is started.
The following example gives the values FirstParam
and
SecondParam
to the launched agent:
For retrieving the values passed on the command line, you must handle the Initialize
event, as illustrated
by the following example:
agent MyAgent {
uses Logging
on Initialize {
println("Command line parameters: " + occurrence.parameters)
}
}
In the next section, we will learn how to launch your SARL project from the command line.
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.