2014-09-23 83 views
1

我正在嘗試構建Spring Shell應用程序。 我能夠成功運行我的應用程序,但它立即退出@啓動&不會等待用戶輸入。它似乎不保留在JLineShell promptLoop方法中。Spring Shell - 命令提示立即退出,不等待用戶輸入

我正在用mainClassName =「org.springframework.shell.Bootstrap」構建一個jar。

我的春天殼的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; 
} 

} 
+1

請張貼一些代碼/配置。 – 2014-09-23 09:49:48

+0

增加的代碼&config – 2014-09-23 09:57:27

+0

可能不是根本原因,但爲什麼有一個主類不做任何事情,而是委託給Bootsrap類?另外,你appContext xml文件是否正確放置並且在/META-INF/spring/spring-shell-plugin.xml下可見。 – ebottard 2014-09-23 16:21:43

回答

0

我已經想通了問題是什麼。不要嘗試從IDE中啓動shell(準確地說是STS)。從IDE內運行應用程序時,似乎EOF立即返回,通過命令行完美工作。

謝謝

+1

這與IDE的工作方式有關。只要通過Cengiz答覆的參數,一切都應該沒問題。 – 4F2E4A2E 2015-05-30 09:36:26

4

您也可以在IDE中啓動您的應用程序而不立即返回。

你必須把以下JVM參數您運行配置:

在* nix機器:

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

爲Windows機器:

-Djline.WindowsTerminal.directConsole=false 
-Djline.terminal=jline.UnsupportedTerminal