在 Eclipse 中,如何在 Tomcat 中运行我的 Maven 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7727204/
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
From Eclipse, how can I run my Maven project in Tomcat?
提问by Dave
I'm on Windows XP, using Eclipse Indigo, Tomcat 6.0.33, and have the Maven plugin installed. (Using Maven 3.0.3 on my system). I have Tomcat showing up in my Eclipse servers list, but I can't figure out a one click way to deploy my WAR project to the Tomcat server. When I right click my project and select "Run" there are many Maven options (e.g. "Maven Install"), but none builds and then deploys my project to Tomcat.
我使用的是 Windows XP,使用 Eclipse Indigo、Tomcat 6.0.33,并安装了 Maven 插件。(在我的系统上使用 Maven 3.0.3)。我的 Eclipse 服务器列表中显示了 Tomcat,但我无法找到一种将我的 WAR 项目部署到 Tomcat 服务器的单击方式。当我右键单击我的项目并选择“运行”时,有许多 Maven 选项(例如“Maven 安装”),但没有一个构建然后将我的项目部署到 Tomcat。
Any help along these lines? Thanks, - Dave
有什么帮助吗?谢谢, - 戴夫
回答by fmucar
see below link for details
详情请参阅以下链接
http://mojo.codehaus.org/tomcat-maven-plugin/deployment.html
http://mojo.codehaus.org/tomcat-maven-plugin/deployment.html
Alternatively, search for tomcat:run and you can use it directly
或者,搜索 tomcat:run 直接使用即可
EDIT:
编辑:
Run/Debug Configurations
运行/调试配置
Double click maven build, a new configuration will be created
双击maven build,会新建一个配置
put ${project_loc} for base directory
将 ${project_loc} 作为基本目录
put tomcat:run for goals
把 tomcat:run for目标
give an appropriate name for yourself at the top
在顶部为自己取一个合适的名字
Apply and run/debug using your new configuration
使用您的新配置应用和运行/调试
EDIT2:
编辑2:
The link has been changed to below one: http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/(Thanks @Lucky)
该链接已更改为以下链接:http: //tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/(感谢@Lucky)
回答by TrueDub
within Eclipse, you can run the project by doing the following:
在 Eclipse 中,您可以通过执行以下操作来运行项目:
In the servers view, create a server (right-click, new Server, Tomcat) Add the project to the server (right-click the server, add & remove, select the project) Start the server - the server will start & deploy the app
在servers视图中,创建一个服务器(右键,新建Server,Tomcat) 将项目添加到服务器(右键单击服务器,添加&删除,选择项目) 启动服务器——服务器将启动&部署应用程序
The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.
这样做的诀窍是服务器不会将打包的应用程序部署在tomcat webapps 目录中,而是将分解版本部署到eclipse 安装的plug-ins 目录下的目录中。
To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar
专门做maven打包并部署到外部tomcat实例(eclipse外部),使用fmucar指定的tomcat-maven-plugin
回答by user1533740
- Run Configurations : Select Base Directory of our maven base project directory.
- Give Goals as tomcat7:run to run application and tomcat7:deploy for deploy tomcat7:deploy
In maven settings.xml, give server configuration as below under
<servers>
tag<servers> <server> <id>TomcatServer</id> <username>admin</username> <password>admin</password> </server> <servers>
In the parameters section of run configurations give parameter maven.tomcat.port and give any required port number. Ex: 7777
In the pom.xml provide tomcat plugin as below under
<build>
tag<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:7777/manager/html</url> <server>TomcatServer</server> <username>admin</username> <password>admin</password> </configuration> <executions> <execution> <id>tomcat-run</id> <goals> <goal>run</goal> </goals> <phase>pre-integration-test</phase> <configuration> <port>7777</port> </configuration> </execution> </executions> </plugin>
- 运行配置:选择我们 Maven 基础项目目录的基础目录。
- 将目标指定为 tomcat7:run 以运行应用程序和 tomcat7:deploy 以部署 tomcat7:deploy
在 maven settings.xml 中,在
<servers>
标签下给出服务器配置如下<servers> <server> <id>TomcatServer</id> <username>admin</username> <password>admin</password> </server> <servers>
在运行配置的参数部分给出参数 maven.tomcat.port 并给出任何所需的端口号。例如:7777
在 pom.xml
<build>
标签下提供如下 tomcat 插件<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:7777/manager/html</url> <server>TomcatServer</server> <username>admin</username> <password>admin</password> </configuration> <executions> <execution> <id>tomcat-run</id> <goals> <goal>run</goal> </goals> <phase>pre-integration-test</phase> <configuration> <port>7777</port> </configuration> </execution> </executions> </plugin>
回答by Atul Singh Rathore
within Eclipse, you can run the project by doing the following:
在 Eclipse 中,您可以通过执行以下操作来运行项目:
In the servers view, create a server (right-click, new Server, Tomcat) Add the project to the server (right-click the server, add & remove, select the project) Start the server - the server will start & deploy the app
在servers视图中,创建一个服务器(右键,新建Server,Tomcat) 将项目添加到服务器(右键单击服务器,添加&删除,选择项目) 启动服务器——服务器将启动&部署应用程序
The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.
这样做的诀窍是服务器不会将打包的应用程序部署在tomcat webapps 目录中,而是将分解版本部署到eclipse 安装的plug-ins 目录下的目录中。
To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar
专门做maven打包并部署到外部tomcat实例(eclipse外部),使用fmucar指定的tomcat-maven-plugin
This I do not get because I don not want to add any maven plugin, I wanted to run it in simple manner like in old plain servlet programs we used to add server in server panel of eclipse and then over project we used to do Right Click and run on server.
我没有得到这个,因为我不想添加任何 maven 插件,我想以简单的方式运行它,就像在旧的普通 servlet 程序中一样,我们过去常常在 eclipse 的服务器面板中添加服务器,然后在我们过去常常做的项目上右键单击并在服务器上运行。
Here how can I do it without adding maven plugin or please explain in details why maven plugin explicitly needed why I can not run server added to eclipse. I did steps given above(last solutions) but in that case server added to my eclipse do not starts instead of that server which was downloaded during maven plugin resolution (I am talking about tomcat:run command) process gets started.
在这里我如何在不添加 maven 插件的情况下做到这一点,或者请详细解释为什么明确需要 maven 插件为什么我不能运行添加到 eclipse 的服务器。我做了上面给出的步骤(最后一个解决方案),但在这种情况下,添加到我的 eclipse 的服务器不会启动,而不是在 maven 插件解析(我说的是 tomcat:run 命令)过程中下载的那个服务器启动。
Please explain in details as short answers only confuses I am beginner for maven.
请详细解释,因为简短的答案只会让我是 maven 的初学者感到困惑。