1) Create the command class:
package com.wordpress.simplesassim.shell; import org.springframework.shell.core.CommandMarker; import org.springframework.shell.core.annotation.CliCommand; import org.springframework.stereotype.Component; @Component public class SampleCommands implements CommandMarker { @CliCommand(value = "sample do-something", help = "Does something") public void doSomething() { ... } }
2) Create the META-INF/spring/spring-shell-plugin.xml
file:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="com.wordpress.simplesassim.shell" /> </beans>
3) Build the archive.
4) Drop the archive in the class path.
5) Run the command:
$ sample do-something