为什么我不能关闭maven插件中的tomcat 7 ?

时间:2022-09-03 22:57:05

I'm using tomcat7-maven-plugin 2.2 to run a webapp from command line (I'm on Windows 8.1, Java 1.7.0_51 and Maven 3.2.1).

我使用tomcat7-maven-plugin 2.2从命令行运行一个webapp(我在Windows 8.1、Java 1.7.0_51和Maven 3.2.1)。

This is the configuration (pretty straightforward, I guess):

这是配置(很简单,我猜):

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>

    <configuration>
        <address>localhost</address>
        <port>8080</port>
        <path>/</path>
        <uriEncoding>UTF-8</uriEncoding>
    </configuration>
</plugin>

I run Maven with mvn tomcat7:run and it starts correctly, the server starts up, the webapp loads, and I can interact with it.
The command prompt in which I run Maven is busy showing Tomcat output (this looks fine to me):

我使用mvn tomcat7运行Maven:运行并正确启动,服务器启动,webapp加载,我可以与它交互。我运行Maven的命令提示符正忙着显示Tomcat的输出(这对我来说很好):

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <project-name-here> 0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ <project-name-here> >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ <project-name-here> ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 25 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ <project-name-here> ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ <project-name-here> <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ <project-name-here> ---
[INFO] Running war on http://localhost:8080/
[INFO] Using existing Tomcat server configuration at c:\workspace\<project-name-here>\target\tomcat
[INFO] create webapp with contextPath:
apr 01, 2014 10:39:50 AM org.apache.coyote.AbstractProtocol init
Informazioni: Initializing ProtocolHandler ["http-bio-127.0.0.1-8080"]
apr 01, 2014 10:39:50 AM org.apache.catalina.core.StandardService startInternal
Informazioni: Starting service Tomcat
apr 01, 2014 10:39:50 AM org.apache.catalina.core.StandardEngine startInternal
Informazioni: Starting Servlet Engine: Apache Tomcat/7.0.47
apr 01, 2014 10:39:52 AM org.apache.coyote.AbstractProtocol start
Informazioni: Starting ProtocolHandler ["http-bio-127.0.0.1-8080"]

Then, I want to shutdown the server: I run mvn tomcat7:shutdown from a separate command prompt, but all I get is this:

然后,我要关闭服务器:我运行mvn tomcat7:从一个单独的命令提示符中关闭,但是我得到的只是这个:

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <project-name-here> 0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:shutdown (default-cli) @ <project-name-here> ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.083 s
[INFO] Finished at: 2014-04-01T10:39:59+01:00
[INFO] Final Memory: 9M/154M
[INFO] ------------------------------------------------------------------------
"cmd" non è riconosciuto come comando interno o esterno,
 un programma eseguibile o un file batch.

That last line reads:

,最后一行写着:

"cmd" is not a recognized internal or external command, an executable or a batch file.

“cmd”不是一个公认的内部或外部命令、可执行文件或批处理文件。

I can stop Tomcat from the first command prompt hitting Ctrl+C, but since I need to pass all this others, I'd like to offer them a script to start the webapp and a script to stop it.

我可以阻止Tomcat在第一个命令提示符下按Ctrl+C,但是因为我需要传递所有这些,我想给他们一个脚本启动webapp和一个脚本来阻止它。

What's wrong? Is it a plugin error? Is it a configuration error on my side?

怎么了?它是一个插件错误吗?是我这边的配置错误吗?


EDIT

编辑

If I add <fork>true</fork> to the POM, the server crashes with this error:

如果我添加 true 到POM,服务器就会崩溃:

[...]
Informazioni: Starting service Tomcat
apr 03, 2014 2:05:29 PM org.apache.catalina.core.StandardEngine startInternal
Informazioni: Starting Servlet Engine: Apache Tomcat/7.0.47
apr 03, 2014 2:05:31 PM org.apache.coyote.AbstractProtocol start
Informazioni: Starting ProtocolHandler ["http-bio-127.0.0.1-8080"]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.711 s
[INFO] Finished at: 2014-04-03T14:05:31+01:00
[INFO] Final Memory: 26M/368M
[INFO] ------------------------------------------------------------------------
ERROR: IllegalAccessException for stop method in class org.apache.tomcat.maven.plugin.tomcat7.run.ExtendedTomcat
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tomcat.maven.common.run.EmbeddedRegistry.shutdownAll(EmbeddedRegistry.java:110)
        at org.apache.tomcat.maven.common.run.EmbeddedRegistry$1.run(EmbeddedRegistry.java:69)
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardServer[-1]]
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
        at org.apache.catalina.startup.Tomcat.stop(Tomcat.java:351)
        ... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardService[Tomcat]]
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
        at org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:753)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardEngine[Tomcat]]
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
        at org.apache.catalina.core.StandardService.stopInternal(StandardService.java:502)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        ... 9 more
Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/core/ContainerBase$StopChild
        at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:1173)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        ... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.core.ContainerBase$StopChild
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
        ... 13 more

3 个解决方案

#1


5  

As far as I know you need to use Ctrl + c after starting Tomcat server with mvn tomcat7:run to shut it down as it's attached to the current Maven run.

据我所知,在使用mvn tomcat7启动Tomcat服务器后,您需要使用Ctrl + c:run关闭它,因为它连接到当前的Maven运行。

The shutdown goal is used to be called after e.g. performing some tests (integration tests) to finish all the job in a clean way.

关闭目标是在执行一些测试(集成测试)之后被调用的,以干净的方式完成所有的工作。

#2


1  

have a look at the fork option http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/run-mojo.html#fork

看看这个fork选项,http://tomcat.apache.org/maven-plugin-2 /tomcat7-maven-plugin/run-mojo.html#fork ?

So with this option you are able to start embeded tomcat run some tests then shutdown.

因此,通过这个选项,您可以开始嵌入tomcat运行一些测试然后关闭。

HTH

HTH

#3


0  

An alternative is if the Tomcat maven plugin had a way to enable the shutdown port (default 8005) then you can just send the default shutdown string (default "shutdown") to shut it down.

另一种选择是,如果Tomcat maven插件有一种方法来启用关闭端口(默认的8005),那么您可以只发送默认的关机字符串(默认的“关闭”)来关闭它。

Using a JMX client, the shutdown port is set to -1 when I run the plugin run goal.

使用JMX客户机,当我运行插件运行目标时,关闭端口设置为-1。

#1


5  

As far as I know you need to use Ctrl + c after starting Tomcat server with mvn tomcat7:run to shut it down as it's attached to the current Maven run.

据我所知,在使用mvn tomcat7启动Tomcat服务器后,您需要使用Ctrl + c:run关闭它,因为它连接到当前的Maven运行。

The shutdown goal is used to be called after e.g. performing some tests (integration tests) to finish all the job in a clean way.

关闭目标是在执行一些测试(集成测试)之后被调用的,以干净的方式完成所有的工作。

#2


1  

have a look at the fork option http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/run-mojo.html#fork

看看这个fork选项,http://tomcat.apache.org/maven-plugin-2 /tomcat7-maven-plugin/run-mojo.html#fork ?

So with this option you are able to start embeded tomcat run some tests then shutdown.

因此,通过这个选项,您可以开始嵌入tomcat运行一些测试然后关闭。

HTH

HTH

#3


0  

An alternative is if the Tomcat maven plugin had a way to enable the shutdown port (default 8005) then you can just send the default shutdown string (default "shutdown") to shut it down.

另一种选择是,如果Tomcat maven插件有一种方法来启用关闭端口(默认的8005),那么您可以只发送默认的关机字符串(默认的“关闭”)来关闭它。

Using a JMX client, the shutdown port is set to -1 when I run the plugin run goal.

使用JMX客户机,当我运行插件运行目标时,关闭端口设置为-1。