在Eclipse上使用Maven实现自动部署
1. 准备工作:在eclipse上集成Maven
2. 首先是配置Tomcat conf 目录下的tomcat-users.xml,配置用户权限,提供给本地Maven使用
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
3. 登陆http://127.0.0.1/manager/text
成功登陆后就说明Tomcat权限已经配置好了,接下来就是本地Maven的配置了。
4.接下来是Maven里面的settings.xml文件的配置的<servers>中添加代码如下:
<server>
<id>test</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
注意:这里的id对应的是Maven项目 pom.xml里面的 server , 其他的username 和 password都是一致的,即 Tomcat登录的用户名和密码。
5.pom.xml的配置,在项目的build标签中添加3Maven个插件
1.maven-resources-plugin----xml/properties资源处理
2. maven-compiler-plugin---编译
3. tomcat7-maven-plugin---部署
<build>
<finalName>server-monitoring</finalName>
<resources>
<!-- 配置文件 -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/server-monitoring</path>
<!-- 填写远程服务器地址 -->
<url>http://192.168.163.137:8080/manager/text</url>
<server>test</server>
<username>tomcat</username>
<password>tomcat</password>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
6.项目右键maven build….
设置goals:clean install tomcat7:depeloy
注意:如果是相互依赖的项目,先install 被依赖的项目
完成啦!!!!!!!!!!!!!!!!!!!!!