Fork me on GitHub

Create your First Project

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:

  1. creating a SARL project inside Eclipse without Maven, or
  2. creating a SARL project with Maven (inside or outside Eclipse).

These two ways are explained below.

1. Create a SARL Project without Maven

For creating a project, you should open your Eclipse and click on File > New > Projects, and select SARL Project in the SARL category.

Select the SARL Project Type

After clicking on Next, the wizard is displaying the first page for creating a SARL project.

1.1. Step 1: Entering the project information

You must enter the name of your project. You could change the standard SARL and Java environment configurations as well.

Enter the Project Information

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.

1.2. Step 2: Configuration of the source folders”

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:

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.

Source Code Folders

2. Create a SARL Project with Maven

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.

2.1. Edit the Maven configuration

Open the file pom.xml, and edit it for obtaining a content similar to the configuration below.

Replace the version number 0.14.0-SNAPSHOT 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-SNAPSHOT</sarl.version>
	   <jdk.version>17</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.11.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.

2.2. Configuration of a runtime environment (optional)

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.

Janus as maven dependency

The runtime environment that is recommended by the developers of SARL is Janus.

Replace the version number (3.0.14.0-SNAPSHOT) 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-SNAPSHOT</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>

Janus with networking feature as maven dependency

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-SNAPSHOT</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>

3. What’s next?

In the next section, we will learn how to create our first agent.

Next>

Copyright © 2014-2023 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-SNAPSHOT.