1

我正在尝试构建一个 Spring Shell 应用程序。我能够成功运行我的应用程序,但它立即退出@启动并且不等待用户输入。它似乎没有保留在 JLineShell promptLoop 方法中。

我正在构建一个带有 mainClassName =“org.springframework.shell.Bootstrap”的 jar。

我的 spring-shell-plugin.xml 如下:

<?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>

我的主要课程:

public class Main {

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

}

我的命令类:

@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;
 }

}
4

2 回答 2

5

您也可以在 IDE 中启动您的应用程序,而无需立即返回。

您必须将以下 JVM 参数放入运行配置中:

对于 *nix 机器:

-Djline.terminal=org.springframework.shell.core.IdeTerminal

对于 Windows 机器:

-Djline.WindowsTerminal.directConsole=false
-Djline.terminal=jline.UnsupportedTerminal
于 2014-11-29T15:56:56.487 回答
0

我已经弄清楚问题所在了。不要尝试从 IDE(确切地说是 STS)中启动 shell。从 IDE 中运行应用程序时,似乎立即返回 EOF,通过命令行完美运行。

谢谢

于 2014-09-29T15:09:46.723 回答