Using Rell in Eclipse

Now that we have everything installed, we should try to make a simple hello world in Rell.

Hello World in Rell

  1. Switch to the Rell perspective, if not done already. Menu: Window - Perspective - Open Perspective - Other…, choose Rell.

  2. Create a project:

    • Menu File - New - Rell Project.
    • Enter a project name test and click Finish.
    ../_images/new_template_project_dialog_crop.png

    A Rell project with a default directory structure shall be created.

  3. Create a Rell file:

    • Right-click on the src folder and choose New - File.
    • Enter a file name test.rell and click Finish.
  4. Write the code in the editor:

    function main() {
        print('Hello, World!');
    }
    

    Save: manu File - Save or CTRL-S (⌘S).

  5. Run the program: right-click on the editor and choose Run As - Rell Console App.

    ../_images/run_console_app_menu_crop.png
  6. The output “Hello, World!” must be shown in the Console view.

    ../_images/run_console_app_output.png

IDE Overview

Eclipse IDE window consists of different views. Every view has its own tab. By default, Rell IDE has following views:

  • Project Explorer - shows projects and their directory trees.
  • Problems - shows compilation warnings and errors.
  • Console - console output (when running programs).
  • Outline - shows the structure of a selected Rell file.
../_images/ide_empty.png

Running Applications

Right-click on a file (or an editor) and choose Run As. Run options available for the file will be shown.

../_images/run_menu_crop.png

Alternatively, use keyboard shortcut CTRL-F11 (⇧⌘F11).

../_images/run_dialog_crop.png

Rell Console App

Executes a *.rell file as a stand-alone console program, not as a module in a Postchain node.

The program must contain a function (or operation, or query) called main, which will be the entry point. The output is displayed in the Console view.

The name of the main function and its arguments can be specified in a run configuration.

Database connection

By default, the program is executed without a database connection, and an attempt to perform a database operation will result in a run-time error.

To run a console app with a database connection, there must be a file called console-db.properties, db.properties or node-config.properties in the directory of the Rell file or in the rell/config directory of the project. The file shall contain database connection settings. For example:

database.driverclass=org.postgresql.Driver
database.url=jdbc:postgresql://localhost/postchain
database.username=postchain
database.password=postchain
database.schema=rell_app
../_images/run_console_app_db_properties.png

When running a console app with a database connection, tables for defined classes and objects are created on start-up. If a table already exists, missing columns are added, if necessary.

How to prepare a database is described in the Database Setup section.

Rell Postchain App

Starts a Postchain node with a configuration written in the Run.XML format. To use this option, right-click on a *.xml file, not on a *.rell file.

Using run.xml gives you the option to run multiple blockchains in one Postchain node.

Example of a minimal run.xml:

<run>
    <nodes>
        <config>
            database.driverclass=org.postgresql.Driver
            database.url=jdbc:postgresql://localhost/postchain
            database.username=postchain
            database.password=postchain
            database.schema=rell_app

            activechainids=1

            api.port=7740
            api.basepath=

            messaging.privkey=3132333435363738393031323334353637383930313233343536373839303131
            messaging.pubkey=0350fe40766bc0ce8d08b3f5b810e49a8352fdd458606bd5fafe5acdcdc8ff3f57

            node.0.id=node0
            node.0.host=127.0.0.1
            node.0.port=9870
            node.0.pubkey=0350fe40766bc0ce8d08b3f5b810e49a8352fdd458606bd5fafe5acdcdc8ff3f57
        </config>
    </nodes>
    <chains>
        <chain name="user" iid="1">
            <config>
                <app module="main" />
            </config>
        </chain>
    </chains>
</run>
../_images/run_postchain_app_output_runxml.png

Clear Database

This option is available for database properties files, *.properties (for instance, node-config.properties). Drops all tables (and stored procedures) in the database.

../_images/clear_database_menu_crop.png

Run with a Keyboard

By default, CTRL-F11 (⇧⌘F11) shortcut runs the file of the active editor. It can be configured to run the last launched application instead, which may be more convenient, as there is no need to choose an application type. Go to the menu Window - Preferences (macOS: Eclipse - Preferences), then Run/Debug - Launching. In the Launch Operation box, choose Always launch the previously launched application.

../_images/preferences_launching_ed.png

Running Multiple Apps

It is possible to run multiple applications (e. g. multiple nodes) simultaneously. For example, one can define two Run.XML configuration files that use the same Rell module, but different ports and database schemas.

The output of all running applications will be shown in the Console view, but on different pages. It is possible to switch between the consoles of different applications using a button or a dropdown list.

../_images/run_console_switch_ed.png

Run Configurations

To run an application, Eclipse IDE needs a run configuration, which contains different properties, like the name of the main function, arguments or blockchain RID. When running an application via the Run As context menu, the IDE automatically creates a run configuration with default settings if it does not exist.

To change a run configuration, go to the menu Run - Run Configurations…. The last launched application will be selected. Change the settings and click either Apply or Run to save the changes.

../_images/run_configurations_console_dialog.png