fvgb 发表于 2015-11-14 11:01:35

maven实现项目远程部署到tomcat(热部署)

  http://shellblog.sinaapp.com/?p=66
  

  
1.配置远程的tomcat7,修改conf下的 tomcat-users.xml文件,如下:
1234<rolerolename=&quot;manager-gui&quot;/>    <rolerolename=&quot;manager-script&quot;/>    <userusername=&quot;tomcat&quot;password=&quot;tomcat&quot;             roles=&quot;manager-gui,manager-script&quot;/>2.在POM中加入部署插件,如下:

12345678<plugin>      <groupId>org.codehaus.mojo</groupId>      <artifactId>tomcat-maven-plugin</artifactId>      <configuration>            <url>http://192.168.5.231:8585/manager/html</url>            <server>test</server>      </configuration>    </plugin>
3.修改maven配置文件:settings.xml,在其中加入test的配置:
12345<server>       <id>test</id>       <username>tomcat</username>       <password>tomcat</password>   </server>
4.配置完成,执行命令:

1mvntomcat:redeploy

上述方式为tomcat热部署,不需要重启服务器。




上面方法适合web 项目并且是热部署,下面是一种自动打包并上传的办法
主要插件:
wagon:upload-single
Full name:
org.codehaus.mojo:wagon-maven-plugin:1.0-beta-4:upload-single
Description:
Upload a single file with option to change nameAttributes:
Required Parameters
NameTypeSinceDescriptionfromFileFile-Path to a local file to be uploadedurlString-URL to upload to or download from or list. Must exist and point to a directory.Optional Parameters
NameTypeSinceDescriptionserverIdString-settings.xml's server id for the URL. This is used when wagon needs extra authentication information.
Default value is: serverId.skipboolean-When true, skip the execution.
Default value is: false.toFileString-Relative path to the URL. When blank, default to fromFile's file name.下面是具体配置 :
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=&quot;org.apache.maven.plugins.shade.resource.ManifestResourceTransformer&quot;>
<mainClass>com.ifeng.tcp.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<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.version}.${project.packaging}</fromFile>
<url>scp://172.30.22.61/data</url>
<serverId>deploy</serverId>
</configuration>
</execution>
</executions>


</plugin>
</plugins>
</build>
  
页: [1]
查看完整版本: maven实现项目远程部署到tomcat(热部署)