Deploying a project using Maven
I have created a project in Eclipse and built it using Maven. I need to deploy my project to my Tomcat serv开发者_运维百科er after packaging the project. How can I do this? I have already added my Tomcat server to Eclipse.
While developing, if you use M2E plugin, then you can still let M2E build the project and simply use Run on Server by right clicking on the project. That's the easiest.
If Run on Server is not shown on the menu, you could simply right click the project --> Enable faceted form and then check on Dynamic Web Module as in this screenshot
For maven plugin options, apart from what @Ramon pointed out, there's t7mp T7MP is useful from an integration testing point of view. You may refer to the configuration wiki page for more info.
Seems there is now an official maven plugin for tomcat here. I have used the old version which seems to be the more stable option.
To deploy a web project to an Eclipse Tomcat server: http://www.eclipse.org/webtools/community/tutorials/BuildJ2EEWebApp/BuildJ2EEWebApp.html
To learn about deploying apps to a standalone Tomcat server: http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html
edit (or create if it doesn't exist) your $HOME/.m2/settings.xml to include the following server block, this assumes
your $CATALINA_HOME/conf/tomcat-users.xml
has an entry like
<user username="tomcatuser" password="tomcatpw" roles="tomcat, manager-gui"/>
<settings>
<servers>
<server>
<id>tomcat</id>
<username>tomcatuser</username>
<password>tomcatpw</password>
</server>
</servers>
</settings>
Then you can deploy to tomcat with maven using
mvn tomcat:deploy
For further tomcat deployment settings for maven see
http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html
精彩评论