使用wagon-maven-plugin插件自动部署项目
2018-03-20 14:11
711 查看
该插件的maven依赖为:
[html] view
plain copy
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
</dependency>
插件的文档地址为:
http://www.mojohaus.org/wagon-maven-plugin/
主要提供如下几个goal
wagon:upload-single uploads the specified file to a remote location.
wagon:upload uploads the specified set of files to a remote location.
wagon:download-single downloads the specified file from a remote location.
wagon:download downloads the specified set of files from a remote location.
wagon:list lists the content of a specified location in a remote repository.
wagon:copy copies a set of files under a Wagon repository to another.
wagon:merge-maven-repos merges , including metadata, a Maven repository to
another.
wagon:sshexec Executes a set of commands at remote SSH host.
用法如下:
为了让wagon-maven-plugin插件能SSH连上Linux服务器,首先需要在Maven的配置文件settings.xml中配置好server的用户名和密码。
[html] view
plain copy
<server>
<id>webserver</id>
<username>hadoop</username>
<password>123</password>
</server>
使用该插件,需要在build里面配置如下内容
[html] view
plain copy
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
如下演示了一个,使用该查询部署一个war到tomcat的过程
[html] view
plain copy
<build>
<finalName>osc-shop</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<serverId>webserver</serverId>
<!-- 需要部署的文件 -->
<fromFile>target/osc-shop.war</fromFile>
<!-- 部署目录 -->
<url>scp://hadoop@192.168.1.222/home/hadoop/apache-tomcat-8.0.5/webapps/
</url>
<commands>
<!-- 关闭tomcat -->
<command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command>
<!-- 删除之前解压后的目录 -->
<command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop
</command>
<!-- 启动tomcat -->
<command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command>
</commands>
<displayCommandOutputs>true</displayCommandOutputs>
</configuration>
</plugin>
</plugins>
</build>
配置完成后,执行命令
mvn clean package wagon:upload-single wagon:sshexec
即可部署到服务器,并且重启了tomcat
[html] view
plain copy
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
</dependency>
插件的文档地址为:
http://www.mojohaus.org/wagon-maven-plugin/
主要提供如下几个goal
wagon:upload-single uploads the specified file to a remote location.
wagon:upload uploads the specified set of files to a remote location.
wagon:download-single downloads the specified file from a remote location.
wagon:download downloads the specified set of files from a remote location.
wagon:list lists the content of a specified location in a remote repository.
wagon:copy copies a set of files under a Wagon repository to another.
wagon:merge-maven-repos merges , including metadata, a Maven repository to
another.
wagon:sshexec Executes a set of commands at remote SSH host.
用法如下:
为了让wagon-maven-plugin插件能SSH连上Linux服务器,首先需要在Maven的配置文件settings.xml中配置好server的用户名和密码。
[html] view
plain copy
<server>
<id>webserver</id>
<username>hadoop</username>
<password>123</password>
</server>
使用该插件,需要在build里面配置如下内容
[html] view
plain copy
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
如下演示了一个,使用该查询部署一个war到tomcat的过程
[html] view
plain copy
<build>
<finalName>osc-shop</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<serverId>webserver</serverId>
<!-- 需要部署的文件 -->
<fromFile>target/osc-shop.war</fromFile>
<!-- 部署目录 -->
<url>scp://hadoop@192.168.1.222/home/hadoop/apache-tomcat-8.0.5/webapps/
</url>
<commands>
<!-- 关闭tomcat -->
<command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command>
<!-- 删除之前解压后的目录 -->
<command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop
</command>
<!-- 启动tomcat -->
<command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command>
</commands>
<displayCommandOutputs>true</displayCommandOutputs>
</configuration>
</plugin>
</plugins>
</build>
配置完成后,执行命令
mvn clean package wagon:upload-single wagon:sshexec
即可部署到服务器,并且重启了tomcat
相关文章推荐
- 使用wagon-maven-plugin插件自动部署项目
- 使用wagon-maven-plugin插件自动部署项目
- 使用wagon-maven-plugin插件自动部署项目
- 使用cargo-maven2-plugin插件自动化部署项目时遇到的问题
- 使用wagon-maven-plugin自动部署文件到Linux服务器
- Maven自动部署(SCM-SVN/Git)(maven-scm-plugin/maven-release-plugin插件的使用)
- Maven插件wagon-maven-plugin自动化部署Java项目到Linux远程服务器
- 使用wagon-maven-plugin自动部署文件到Linux服务器
- Idea 配置maven-tomcat-plugin插件实现项目部署
- 使用tomcat7-maven-plugin部署Web项目
- 开发过程使用Tomcat Maven插件持续快捷部署Web项目
- Intellij IDEA使用 JRebel 搭配 maven-jetty-plugin插件实现热部署
- 使用Apache Tomcat Maven插件部署运行 Web 项目
- 开发过程使用Tomcat Maven插件持续快捷部署Web项目
- 在IDEA下,使用maven的mybatis-generator-maven-plugin插件自动生成实体类
- 使用Maven自动部署Java Web项目到Tomcat问题小记
- maven 使用tomcat 插件,项目部署时访问路径问题
- 使用shell脚本自动部署(发布,重起)maven(java)项目
- 使用Maven自动部署插件