将使用 Eclipse 和 Maven 创建的项目部署到 Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2891859/
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
Deploying project, created with Eclipse and Maven, to Tomcat
提问by user348267
I'm using Eclipse 3.5, Maven 2, m2eclipse and Tomcat 6. So i create Maven project for archetype webapp. This is pom.xml:
我正在使用 Eclipse 3.5、Maven 2、m2eclipse 和 Tomcat 6。所以我为原型 webapp 创建了 Maven 项目。这是 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itransition</groupId>
<artifactId>hello</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- tools.jar dependency -->
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8.1</version>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
</build>
</project>
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
那么我想将我的 Web 应用程序部署到 Tomcat。我需要做什么?Maven 安装没有帮助。但是,如果我通过 Maven 安装创建War,我可以将它导入到 eclipse 并通过服务器弹出窗口中的“添加和删除...”将其部署到 Tomcat。
采纳答案by pkainulainen
This problem can be resolved by using the Tomcat plugin for Maven. Its homepage has got extensive documentation concerning the configurationof the plugin and deployment of war files.
回答by Parthasarathy B
It can be done in 2 ways.
它可以通过 2 种方式完成。
Refer below URL
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
Create maven Project with eclipse and locate the project folder from command prompt (or) Terminal
mvn eclipse:eclipse -Dwtpversion=2.0 [ in project folder ]
参考以下网址
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
使用 eclipse 创建 maven 项目并从命令提示符(或)终端找到项目文件夹
mvn eclipse:eclipse -Dwtpversion=2.0 [在项目文件夹中]
Refersh Eclipse project.
Now you can Add and Remove Deployment.
引用 Eclipse 项目。
现在您可以添加和删除部署。
回答by LaRa
Found out that the tomcat manager url (i am using Tomcat 6.0) is http://localhost:8080/manager/html
, while the default used by the mvn tomcat plugin stops at manager in the URL. Add the url specified to your pom.xml as a configuration parameter - (see this url for more details http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html) and voilà it works...
发现 tomcat manager url(我使用的是 Tomcat 6.0)是http://localhost:8080/manager/html
,而 mvn tomcat 插件使用的默认值在 URL 中的 manager 处停止。将指定的 url 添加到 pom.xml 作为配置参数 - (有关更多详细信息,请参阅此 url http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html),瞧它工作...
With Tomcat7, I found I needed to set up the URL as http://localhost:8080/manager/html
anduse a username with a manager-gui role. However, using a username with the manager-script role, with URL http://localhost:8080/manager/text
also works and is more appropriate. The manager-script role is the designed way to go for ant/maven scripts.
使用 Tomcat7,我发现我需要将 URL 设置为http://localhost:8080/manager/html
并使用具有 manager-gui 角色的用户名。但是,使用具有 manager-script 角色的用户名和 URLhttp://localhost:8080/manager/text
也有效并且更合适。manager-script 角色是 ant/maven 脚本的设计方式。
回答by Pascal Thivent
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
那么我想将我的 Web 应用程序部署到 Tomcat。我需要做什么?Maven 安装没有帮助。但是,如果我通过 Maven 安装创建War,我可以将它导入到 eclipse 并通过服务器弹出窗口中的“添加和删除...”将其部署到 Tomcat。
Since you are using m2eclipse, my recommendation would be to deploy your application using the WTP. Assuming you have the Maven integration for WTPfeature installed (from m2eclipse extras) and Tomcat configured as Server, just right-clickon your project and select Run > Run on Server...
由于您使用的是 m2eclipse,我的建议是使用 WTP 部署您的应用程序。假设您已经安装了 WTP功能的Maven 集成(来自m2eclipse extras)并将 Tomcat 配置为服务器,只需右键单击您的项目并选择Run > Run on Server...
Another option would be to run your application on Jetty (yes, I know that this is not what you're asking for but this is very valid option if you don't want to use the WTP). Add the following snippet to your pom:
另一种选择是在 Jetty 上运行您的应用程序(是的,我知道这不是您所要求的,但如果您不想使用 WTP,这是非常有效的选择)。将以下代码段添加到您的 pom 中:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
</plugins>
</build>
</project>
And simply run mvn jetty:run
to start an embedded Jetty server and deploy your application on it.
只需运行mvn jetty:run
即可启动嵌入式 Jetty 服务器并在其上部署您的应用程序。
The same can be achieved for Tomcat using the Tomcat Maven Pluginbut unless you want to deploy to a remote Tomcat (see the Usagepage), I don't see any advantage over the Maven Jetty Plugin.
使用Tomcat Maven Plugin也可以为 Tomcat 实现相同的目的,但除非您想部署到远程 Tomcat(请参阅使用页面),否则我看不出比Maven Jetty Plugin 有任何优势。
During development, I would use the first option (deploy with the WTP).
在开发过程中,我会使用第一个选项(使用 WTP 部署)。
回答by Sai prateek
If you want that your war
file created by maven
, should be deploy on tomcat server directly then this tomcat deployment configurationcan help you.
如果你希望你的war
文件由maven
, 直接部署在 tomcat 服务器上,那么这个tomcat 部署配置可以帮助你。