2017-06-01 15 views
3

我創建了一個可由Maven運行的可執行Tomcat jar應用程序(mvn clean install exec:exec)。此應用程序可以通過在Linux上的Ctrl + C來停止。但是,它不能在Windows上。有誰知道原因和解決方案?由Maven啓動的java進程無法通過Windows上的Ctrl + C停止的原因

環境:

$ mvn -version 
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T22:51:42+09:00) 
Maven home: c:\apache-maven-3.2.2 
Java version: 1.8.0_121, vendor: Oracle Corporation 
Java home: c:\Program Files\Java\jdk1.8.0_121\jre 
Default locale: ja_JP, platform encoding: MS932 
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos" 

的pom.xml的摘錄:

<plugin> 
    <groupId>org.apache.tomcat.maven</groupId> 
    <artifactId>tomcat7-maven-plugin</artifactId> 
    <version>2.1</version> 
    <executions> 
     <execution> 
      <id>tomcat-run</id> 
      <goals> 
       <goal>exec-war-only</goal> 
      </goals> 
      <phase>package</phase> 
      <configuration> 
       <path>/</path> 
       <enableNaming>true</enableNaming> 
       <finalName>embtest.jar</finalName> 
       <charset>utf-8</charset> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <failOnMissingWebXml>false</failOnMissingWebXml> 
     <warName>ROOT</warName> 
    </configuration> 
</plugin> 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
      <id>startup-uber-tomcat</id> 
      <phase>install</phase> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <configuration> 
       <classpathScope>test</classpathScope> 
       <executable>java</executable> 
       <arguments> 
        <argument>-jar</argument> 
        <argument>target/embtest.jar</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

重現步驟:

(1)運行在Windows的命令:

$ git clone https://github.com/k-tamura/embtest.git 
$ cd embtest 
$ mvn clean install exec:exec 

(2)訪問http://localhost:8080 - >顯示主頁面。

(3)按Ctrl鍵+ç

(4)http://localhost:8080訪問 - 是>首頁仍然顯示(Tomcat沒有停止)。

+0

是否打開從你執行一個分開的控制檯窗口?如果是這樣,請選擇該控制檯並按CTRL + C,看看會發生什麼...... –

+0

看起來像您正在執行maven目標,該目標運行您正在構建的jar。這有點奇怪。它有用嗎? –

+0

發送至:Jorge,No.在一個窗口中執行。 –

回答

0

要停止所有作業:

mvn tomcat7:shutdown 

當使用組合的鍵按Ctrl +Ç,仍然有一些工作。

參考:

http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/plugin-info.html

http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/shutdown-mojo.html

+0

我試過'mvn tomcat7:shutdown',但Tomcat沒有停止。我是否也應該更改我的pom.xml? –

+0

在Windows任務管理器中終止進程'java'。如果你可以在Linux中關閉Tomcat服務器,我相信在Windows中關閉Tomcat是一樣的。 –

+0

我知道任務管理器可以終止進程,但我不想使用它。 –

相關問題