简体   繁体   中英

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. I know you can export it as a .war file and dump it in CATALINA_HOME/webapps folder of the remote server. 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. 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). Does any one know how to do this? Any help is really appreciated.

The tool you are loooking for is called Tomcat Maven Plugin

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. By default Tomcat manager should be available in the following location:

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:

<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. (Either from command line of from Eclipse using m2Eclipse plugin .)

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. 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. Be warned, the configuration of admin users has undergone some subtle changes between tomcat 6 and 7.

Once this is working the Maven cargo plugin can deploy war files as follows:

<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.
  • I haven't used the Maven plugin. It's very new

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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