关于Maven的远程部署

本文来自各网友收集整理   本人只做备忘之用

使用maven-wagon-plugin远程部署war项目

我的目的是将本地打好的war包传输到远程服务器上的某个固定目录中

使用maven的其他插件也可以完成同样的任务,wagon-plugin相对简单。

1.我使用ssh,所以不需要手动引入任何依赖,如果使用ftp需要引入特定包

2.我使用了upload-single goal

3.我是用来maven-wagon-plugin 1.0-beta-3版本,截至2011-09-05最新版本

下面是pom:

 

 

<build>

              ……

              <pluginManagement> 
                    <plugins> 
                        <plugin> 
                            <groupId>org.codehaus.mojo</groupId> 
                            <artifactId>wagon-maven-plugin</artifactId> 
                            <version>1.0-beta-3</version> 
                            <executions> 
                                <execution> 
                                    <id>upload-war</id> 
                                    <phase>package</phase> 
                                    <goals> 
                                        <goal>upload-single</goal> 
                                    </goals> 
                                    <configuration> 
                                        <fromFile>target\${project.artifactId}.${project.packaging}</fromFile> 
                                        <url>scp://yoururl(e.g.123.12.12.1)/</url>

                                        <!—serverId 是你在setting.xml中配置的server信息 –> 
                                        <serverId>cms_server</serverId> 
                                        <skip>false</skip>

                                        <!– 相对路径,相对于你上面定义的scp地址,结果是:url/home/reader/service…. –> 
                                        <toFile>home/reader/service/${project.artifactId}.${project.packaging}</toFile> 
                                    </configuration> 
                                </execution> 
                            </executions> 
                        </plugin> 
                    </plugins> 
                </pluginManagement>

                ……

                <plugins> 
                    <plugin> 
                        <groupId>org.codehaus.mojo</groupId> 
                        <artifactId>wagon-maven-plugin</artifactId> 
                    </plugin> 
                </plugins>

               ……

               </build>
 

 

然后你在执行mvn package的时候,就会看到类似的传输信息:upload target/…*.war到scp:url/home/reader/service/*.war

然后检查远程服务器是否收到了文件,如果配置正确并且build success的话,一定能看到你想看到的文件。

以后我在发布我的prod 产品的时候,只需要执行一个带prod参数的package命令就可以咯,现在是

clean package -Denvirenment.type=prod

(-D参数是用来选择maven profiles的,通过profiles可以配置不同的产品开发环境打不同属性的包)


setting.xml中的server信息的话参考setting中的例子就行,类似:

 

    <server> 
      <id>cms_server</id> 
      <username>root</username> 
      <password>,?N_iXasdflksajdflk</password> 
    </server>
 

maven 实现tomcat的远程部署

需要更改的有三处: 
1.tomcat的配置:在conf\tomcat-users.xml中加上有管理权限的用户: 
<?xml version='1.0' encoding='utf-8'?>   
<tomcat-users>   
  <role rolename="manager"/>   
  <user username="marshal" password="password" roles="manager"/>   
</tomcat-users>  

2.在pox.xml中添加 
plugin>   
    <groupId>org.codehaus.mojo</groupId>   
    <artifactId>tomcat-maven-plugin</artifactId>   
    <configuration>   
        <url>http://localhost:8080/manager</url>   
        <server>tomcat.server</server>   
        <path>/mycontext</path>   
    </configuration>   
</plugin> 

3.在.m2/settings.xml文件中增加: 
<settings xmlns="http://maven.apache.org/POM/4.0.0"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   
http://maven.apache.org/xsd/settings-1.0.0.xsd">   
        <servers>   
                <server>   
                        <id>tomcat.server</id>   
                        <username>marshal</username>   
                        <password>password</password>   
                </server>   
        </servers>   
</settings>  
注意:红色的要一致,username和password要一致,<url>要配置上服务器的url</url>

猜你喜欢

转载自northc.iteye.com/blog/1502793