在远程linux服务器的tomcat中部署一个eclipse maven项目

我正在寻找一种方法来部署在远程linux服务器的tomcat中使用eclipse开发的maven项目。 我知道你可以将它作为一个.war文件导出,并将其转储到远程服务器的CATALINA_HOME / webapps文件夹中。 但为此,您必须先将其导出到.war文件,然后通过SFTP或SCP将.war文件复制到远程服务器。 我正在寻找一种方法来做到这一点点几下使用eclipse或/和configuration一些maven设置(在pom.xml或settings.xml中)。 有谁知道如何做到这一点? 任何帮助真的很感激。

你喜欢的工具叫做Tomcat Maven Plugin

它基本上做的是使用Tomcat管理器应用程序的API,您必须确保将其部署在您正在使用的Tomcat实例上。 默认情况下,Tomcat管理器应在以下位置可用:

http://ip_of_your_linux_server:8080/manager/html 

如果不是,请使用以下命令安装它:

 sudo apt-get install tomcat6-admin 

您可以按如下方式配置Tomcat实例的位置:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://www.mydomain.com:1234/mymanager</url> </configuration> </plugin> 

然后运行maven mvn tomcat:部署目标。 (从Eclipse的命令行使用m2Eclipse插件 。)

有关详细信息,请参阅插件的配置和部署页面。

对于像Tomcat,Jetty,Glassfish等许多不同容器的适配器最灵活的解决方案可能是Maven Cargo插件。 你可以在他们的主页上找到大量的例子 ,所以不需要在这里再次粘贴。

要远程部署应用程序,您需要在tomcat实例上配置tomcat部署者应用程序 。 需要警告的是,管理员用户的配置在tomcat 6和7之间经历了一些微妙的变化。

一旦这个工作正常,Maven货物插件可以部署如下的war文件:

 <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <id>tomcat-deploy</id> <phase>package</phase> <configuration> <container> <containerId>tomcat7x</containerId> <type>remote</type> </container> <configuration> <type>runtime</type> <properties> <cargo.remote.uri>${tomcat.manager.url}</cargo.remote.uri> <cargo.remote.username>${tomcat.manager.user}</cargo.remote.username> <cargo.remote.password>${tomcat.manager.pass}</cargo.remote.password> </properties> </configuration> <deployer> <deployables> <deployable> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <type>war</type> <properties> <context>${project.artifactId}</context> </properties> </deployable> </deployables> </deployer> </configuration> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> 

补充笔记

  • Cargo插件支持几个不同的容器,问题是doco很难解释。
  • 我没有使用Maven插件。 这是非常新的