java mvn tomcat:run 不启动 Tomcat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1174363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:30:19  来源:igfitidea点击:

mvn tomcat:run doesn't start Tomcat

javatomcatmaven-2

提问by glaz666

I am trying to deploy and run my webapplication using maven and its tomcat plugin.

我正在尝试使用 maven 及其 tomcat 插件部署和运行我的 web 应用程序。

I have set it up in project's pom.xml, but when I'm calling it from command line:

我已经在项目的 pom.xml 中设置了它,但是当我从命令行调用它时:

mvn tomcat:run

all that I get is:

我得到的只是:

[root@ovz6022 trunk]# mvn -e tomcat:run
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.gotbrains.breeze:breeze:jar:1.0
[INFO]    task-segment: [tomcat:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing tomcat:run
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /root/trunk/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [tomcat:run {execution: default-cli}]
[INFO] Skipping non-war project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24 seconds
[INFO] Finished at: Thu Jul 23 14:34:31 MDT 2009
[INFO] Final Memory: 7M/14M
[INFO] ------------------------------------------------------------------------

And that's all. Tomcat hasn't been launched but I don't see any errors here.

就这样。Tomcat 尚未启动,但我在这里没有看到任何错误。

Does anybody knows what's happening?

有人知道发生了什么吗?

回答by user64141

As mentioned before, you should use war packaging. However, if you can't because you're using OSGI or some other reason, you can tell the Tomcat plugin to deploy anyway even if it isn't war packaging by using the ignorePackaging option:

如前所述,您应该使用War包装。但是,如果您因为使用 OSGI 或其他原因而不能,您可以通过使用 ignorePackaging 选项告诉 Tomcat 插件无论如何部署,即使它不是War打包:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat6-maven-plugin</artifactId> 
                <version>2.0</version>
                <configuration>
                    <ignorePackaging>true</ignorePackaging>

回答by Rich Seller

The clue is in the line:

线索就在这一行:

[INFO] Skipping non-war project

The tomcat:run goal is intended to work with war projects, I'm guessing yours is a jar project.

tomcat:run 目标旨在用于War项目,我猜你的目标是一个 jar 项目。

You need to change the packaging of your project to war, you may also need to provide some additional configuration for the war to actually do anything.

您需要将项目的打包更改为war,您可能还需要为war 提供一些额外的配置才能真正执行任何操作。

Note: I'd recommend having a separate war project to your jar projects, then adding the jars as dependencies to the war.

注意:我建议你的 jar 项目有一个单独的 war 项目,然后将 jars 作为依赖项添加到 war 中。

回答by RooChituv

if you're using Roo, and haven't yet invoked the controller command then your configuration is not yet set to generate a WAR file.

如果您正在使用 Roo,并且尚未调用控制器命令,那么您的配置尚未设置为生成 WAR 文件。