http://shellblog.sinaapp.com/?p=66
1.配置远程的tomcat7,修改conf下的 tomcat-users.xml文件,如下:
1
2
3
4
|
<role rolename=
"manager-gui"
/>
<role rolename=
"manager-script"
/>
<user username=
"tomcat"
password=
"tomcat"
roles=
"manager-gui,manager-script"
/>
|
2.在POM中加入部署插件,如下:
1
2
3
4
5
6
7
8
|
<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的配置:
1
2
3
4
5
|
<server>
<id>test</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
|
4.配置完成,执行命令:
1
|
mvn tomcat: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 name
Attributes:
Required Parameters
Name | Type | Since | Description |
---|---|---|---|
fromFile | File | - | Path to a local file to be uploaded |
url | String | - | URL to upload to or download from or list. Must exist and point to a directory. |
Optional Parameters
Name | Type | Since | Description |
---|---|---|---|
serverId | String | - | settings.xml's server id for the URL. This is used when wagon needs extra authentication information. Default value is: serverId. |
skip | boolean | - | When true, skip the execution. Default value is: false. |
toFile | String | - | 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="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<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>
<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="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<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>