简体   繁体   English

在远程Linux服务器的tomcat中部署Eclipse Maven项目

[英]Deploying an eclipse maven project in a remote linux server's tomcat

I'm looking a way to deploy a maven project developed using eclipse in a remote linux server's tomcat. 我正在寻找一种在远程Linux服务器的tomcat中部署使用eclipse开发的maven项目的方法。 I know you can export it as a .war file and dump it in CATALINA_HOME/webapps folder of the remote server. 我知道您可以将其导出为.war文件并将其转储到远程服务器的CATALINA_HOME / webapps文件夹中。 But for that you have to first export it to .war file and then copy the .war file in to remote server through SFTP or SCP. 但是为此,您必须首先将其导出到.war文件,然后通过SFTP或SCP将.war文件复制到远程服务器。 I'm looking for a way to do it with few clicks using eclipse or/and configuring some maven settings(in pom.xml or settings.xml). 我正在寻找一种使用Eclipse或/并配置一些Maven设置(在pom.xml或settings.xml中)的方法,只需单击几下即可。 Does any one know how to do this? 有谁知道如何做到这一点? Any help is really appreciated. 任何帮助都非常感谢。

The tool you are loooking for is called Tomcat Maven Plugin 您正在寻找的工具称为Tomcat Maven插件

What it basically does is it uses the API of Tomcat manager application, which you have to make sure is deployed on the Tomcat instance you are using. 它的基本作用是使用Tomcat管理器应用程序的API,您必须确保已将其部署在所使用的Tomcat实例上。 By default Tomcat manager should be available in the following location: 默认情况下,Tomcat管理器在以下位置可用:

http://ip_of_your_linux_server:8080/manager/html

If it is not, please install it using the following command: 如果不是,请使用以下命令进行安装:

sudo apt-get install tomcat6-admin

You can configure the location of your Tomcat instance as follows: 您可以按如下方式配置Tomcat实例的位置:

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

and then run maven mvn tomcat:deploy goal. 然后运行maven mvn tomcat:deploy目标。 (Either from command line of from Eclipse using m2Eclipse plugin .) (从Eclipse的命令行使用m2Eclipse插件 。)

Please refer to configuration and deployment pages of the plugin for more verbose information. 请参阅插件的配置部署页面以获取更多详细信息。

The most flexible solution with adapters for many different containers like Tomcat, Jetty, Glassfish, etc. is probably Maven Cargo plugin. 带有适用于许多不同容器(例如Tomcat,Jetty,Glassfish等)的适配器的最灵活的解决方案可能是Maven Cargo插件。 You can find an extensive list of examples on their homepage , so no need to paste that here again. 您可以在其主页上找到大量示例示例 ,因此无需在此处再次粘贴。

To remotely deploy an application you'll need to configure the tomcat deployer app on the tomcat instance. 要远程部署应用程序,您需要在tomcat实例上配置tomcat部署程序 Be warned, the configuration of admin users has undergone some subtle changes between tomcat 6 and 7. 请注意,在tomcat 6和tomcat 7之间,管理员用户的配置进行了一些细微的更改。

Once this is working the Maven cargo plugin can deploy war files as follows: 一旦运行正常,Maven货运插件可以如下部署战争文件:

<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>      

Additional notes 补充笔记

  • The Cargo plugin supports several different containers, problem is the doco is difficult to interpret. Cargo插件支持几种不同的容器,问题在于doco难以解释。
  • I haven't used the Maven plugin. 我还没有使用过Maven插件。 It's very new 这是很新的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM