【发布时间】:2017-11-02 01:24:56
【问题描述】:
我创建了一个可执行的 Tomcat jar 应用程序,它可以由 Maven (mvn clean install exec:exec) 运行。在 Linux 上可以通过 Ctrl+C 停止此应用程序。但是,它不能在 Windows 上。有谁知道原因和解决办法吗?
环境:
$ 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+C
(4) 访问http://localhost:8080 -> 仍然显示主页面(Tomcat 没有停止)。
【问题讨论】:
-
它会打开一个与您执行的窗口分开的控制台窗口吗?如果是这样,请选择该控制台并按 CTRL+C 看看会发生什么...
-
看起来你正在执行 maven 目标,它运行你正在构建的 jar。这有点奇怪。成功了吗?
-
收件人:Jorge,No。在一个窗口上执行。
-
to:Amarnath,我想构建 jar 并使用一个命令运行它。不可能吗?
-
请注意,对于 maven-surefire-plugin(“maven 测试”),类似问题已修复 as of version 2.19。