Search code examples
javaspringcommand-line-interfacespring-shell

Spring Shell - command Prompt exits immediately, does not await user input


I am attempting to build a Spring Shell application. I am able to run my application successfully but it exits immediately @ startup & does not await user input. It seems to not remain in the JLineShell promptLoop method.

I am building a jar with a mainClassName = "org.springframework.shell.Bootstrap".

My spring-shell-plugin.xml is as follows:

<?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-3.1.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

 <context:component-scan base-package="com.zailab" />

</beans>

My Main class:

public class Main {

public static void main(String[] args) throws IOException{
    Bootstrap.main(args);
}

}

My Command class:

@Component
public class BuildCommand implements CommandMarker {

@CliAvailabilityIndicator({"echo"})
  public boolean isCommandAvailable() {
    return true;
  }

@CliCommand(value = "echo", help = "Echo a message")
 public String echo(
   @CliOption(key = { "", "msg" }, mandatory = true, help= "The message to echo") String msg) {
  return msg;
 }

}

Solution

  • I've figured out what the issue was. Do not attempt to start the shell from within an IDE(STS to be exact). It seems an EOF is returned immediately when running the app from within the IDE, works perfectly via command line.

    Thanks