Ros*_*iet 1 java spring command-line-interface spring-shell
我正在尝试构建一个 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>
Run Code Online (Sandbox Code Playgroud)
我的主课:
public class Main {
public static void main(String[] args) throws IOException{
Bootstrap.main(args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的命令类:
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以在 IDE 中启动您的应用程序,而无需立即返回。
您必须将以下 JVM 参数放入运行配置中:
对于 *nix 机器:
-Djline.terminal=org.springframework.shell.core.IdeTerminal
Run Code Online (Sandbox Code Playgroud)
对于 Windows 机器:
-Djline.WindowsTerminal.directConsole=false
-Djline.terminal=jline.UnsupportedTerminal
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1914 次 |
| 最近记录: |