Java 使用 Maven 和 IntelliJ 在 tomcat 中运行应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32057675/
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
Run app in tomcat using maven with IntelliJ
提问by Mateus Viccari
Without using maven, to run the app on tomcat from the Intellij IDE, all you have to do is create an artifact and a "tomcat" run configuration pointing to that artifact, this way you can see tomcat output, restart the server, and other stuff right in the IDE.
在不使用 maven 的情况下,要从 Intellij IDE 在 tomcat 上运行应用程序,您所要做的就是创建一个工件和一个指向该工件的“tomcat”运行配置,这样您就可以看到 tomcat 输出、重新启动服务器等IDE 中的东西。
Now using maven, there's no need to create an artifact, because maven already does the compiling, packaging, etc.
现在使用maven,不需要创建神器,因为maven已经做了编译、打包等工作。
I know i can deploy it using the command mvn tomcat7:redeploy
but this way i can't see standart output/errors and debug.
So what is the standard way to run the app from IntelliJ without having to create an artifact?
我知道我可以使用命令部署它,mvn tomcat7:redeploy
但这样我就看不到标准输出/错误和调试。那么从 IntelliJ 运行应用程序而无需创建工件的标准方法是什么?
采纳答案by Amila
If you have set
如果你已经设置
<packaging>war</packaging>
in your pom, IDEA should automatically identify the artifact (your WAR file) to deploy. No need to manually create an artifact.
在你的 pom 中,IDEA 应该自动识别要部署的工件(你的 WAR 文件)。无需手动创建工件。
回答by Neil McGuigan
In pom.xml
add
在pom.xml
加
<build>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<uriEncoding>UTF-8</uriEncoding>
<path>/your-path</path>
<update>true</update>
</configuration>
</plugin>
</build>
In IntelliJ, open Menu > View > Tool Windows > Maven Projects
在 IntelliJ 中,打开菜单 > 查看 > 工具窗口 > Maven 项目
Plugins > tomcat7 > tomcat7:run
回答by Monika Restecka
When you setup this: n IntelliJ, open Menu > View > Tool Windows > Maven Projects, you will see this menu:
当你设置这个:n IntelliJ,打开 Menu > View > Tool Windows > Maven Projects,你会看到这个菜单:
When you click on this picture you can enter the goal of Maven, for example tomcat7:run
点击这张图可以进入Maven的目标,例如tomcat7:run