For developing with SARL, you should create a project. This document describes two ways for created SARL projects.
Two ways are available for creating a SARL project:
These two ways are explained below.
For creating a project, you should open your Eclipse and click on File > New > Projects, and select SARL Project in the SARL category.
After clicking on Next, the wizard is displaying the first page for creating a SARL project.
You must enter the name of your project. You could change the standard SARL and Java environment configurations as well.
Then you could click on Next for continuing the edition of the project’s properties, or simply click on the Finish button for creating the project with the default properties.
The rest of this section is devoted to the edition of the additional properties for the SARL project.
The second page of the wizard contains the building settings. Two tabs are really interesting: the Source and the Libraries.
The Source tab defines the folders in your project that must contains source code files. By default, a SARL project is composed of four source folders:
src/main/java
: for your Java classes;src/main/sarl
: for your SARL scripts;src/main/generated-sources/sarl
: for the Java codes generated by the SARL compiler (you should not change them yourself);src/main/resources
: for the files that are not SARL nor Java code.The default output folder is target/classes
.
Note The names of these folders are following the conventions of a Maven-based project (described below). In this way, you will be able to turn the Maven nature on your SARL project on/off.
For creating a project with both the Maven and SARL natures, you should open your Eclipse and click on File > New > Others > Maven > Maven Project.
Follow the steps of the project creation wizard, and finally click on the Finish button.
Open the file pom.xml
, and edit it for obtaining a content similar to the configuration below.
Replace the version number 0.14.0
of SARL with the one you want to use. You could search on the
Maven Central Repository for the last available version.
<project>
...
<properties>
...
<sarl.version>0.14.0</sarl.version>
<jdk.version>21</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>io.sarl.lang</groupId>
<artifactId>sarl-maven-plugin</artifactId>
<version>${sarl.version}</version>
<extensions>true</extensions>
<configuration>
<source>${jdk.version}</source>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
...
<dependencies>
...
<dependency>
<groupId>io.sarl.sdk</groupId>
<artifactId>sdk</artifactId>
<version>${sarl.version}</version>
</dependency>
...
</dependencies>
...
</project>
The Maven configuration is based on the use of sarl-maven-plugin
. This plugin is in charge of compiling the SARL and
the Java files. Details about the sarl-maven-plugin
may be found on this page.
Important Note You must set the extensions
tag to true for the sarl-maven-plugin
plugin. If you missed to set it, the plugin will not able to be integrated in the Maven life-cycle. The consequence will be that only the Java compiler will be invoked.
For executing your SARL program, a run-time environment should be used. By default, the SARL development environment replaces any reference to the SARL libraries by the run-time environment’s libraries when the SARL program is launched within the SARL environment or when a runnable Jar library is created.
In several specific cases, you may want to include the runtime environment into the Maven dependencies of your project. In this case, you could replace the Maven dependency to the SARL sdk (as defined in the previous section) by a Maven dependency to the runtime environment library.
Caution Replacing the SARL sdk library by the SARL run-time environment (SRE) library within the Maven dependencies is not the recommended approach by the SARL core developers.
The runtime environment that is recommended by the developers of SARL is Janus.
Replace the version number (3.0.14.0
) of the Janus platform with the one you want to use.
You could search on the Maven Central Repository for the last available version.
<project>
...
<properties>
...
<janus.version>3.0.14.0</janus.version>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>io.sarl.lang</groupId>
<artifactId>sarl-maven-plugin</artifactId>
<version>${sarl.version}</version>
<extensions>true</extensions>
<configuration>
<source>${jdk.version}</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
...
<dependencies>
...
<dependency>
<groupId>io.sarl.sre.janus</groupId>
<artifactId>janus.kernel</artifactId>
<version>${janus.version}</version>
</dependency>
...
</dependencies>
...
</project>
By default, the Janus framework does not activate its network feature. If you would like to build a project with this feature,
you have to use another Maven dependency: janus.network
.
<project>
...
<properties>
...
<janus.version>3.0.14.0</janus.version>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>io.sarl.lang</groupId>
<artifactId>sarl-maven-plugin</artifactId>
<version>${sarl.version}</version>
<extensions>true</extensions>
<configuration>
<source>${jdk.version}</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
...
<dependencies>
...
<dependency>
<groupId>io.sarl.sre.janus</groupId>
<artifactId>janus.network</artifactId>
<version>${janus.version}</version>
</dependency>
...
</dependencies>
...
</project>
In the next section, we will learn how to create our first agent.
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.