How to Create an Add-On for Spring Roo

W/ Spring Roo

1) Create the project in Spring Roo:

$ addon create simple --topLevelPackage br.eti.fernandoribeiro.sample --projectName sample

2) Change the src/main/java/br/eti/fernandoribeiro/sample/SampleCommands.java file:

package br.eti.fernandoribeiro.sample;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.shell.CliAvailabilityIndicator;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;

@Component
@Service
public final class SampleCommands implements CommandMarker {

  @CliCommand(value = "sample do-something", help = "Does something")
  public String doSomething() {
    return null;
  }

}

3) Remove all the other generated files.

4) Generate the Apache Felix SCR descriptor:

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-scr-plugin</artifactId>
  <version>1.8.0</version>
  <executions>
    <execution>
      <goals>
        <goal>scr</goal>
      </goals>
    </execution>
  </executions>
</plugin>

5) Build the bundle.

6) Drop the bundle in the <Install Dir>/bundle folder.

7) Run the command:

$ sample do-something

W/o Spring Roo

1) Create the command class:

package br.eti.fernandoribeiro.sample;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.shell.CliAvailabilityIndicator;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;

@Component
@Service
public final class SampleCommands implements CommandMarker {

  @CliCommand(value = "sample do-something", help = "Does something")
  public String doSomething() {
    ...
  }

}

2) Generate the Apache Felix SCR descriptor:

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-scr-plugin</artifactId>
  <version>1.8.0</version>
  <executions>
    <execution>
      <goals>
        <goal>scr</goal>
      </goals>
    </execution>
  </executions>
</plugin>

3) Build the bundle.

4) Drop the bundle in the <Install Dir>/bundle folder.

5) Run the command:

$ sample do-something

You can find more details here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s