在开发过程当中常常要遇到为不一样的环境打包,这里面最主要的问题在于,不一样环境的配置是不同的,若是为不一样环境打包每次都手工修改配置,那不但工做量大,并且很容易出错。apache
<profiles> <profile> <!-- 开发环境 --> <id>dev</id> <properties> <!-- 经过env设置当前工做环境(重要) --> <env>dev</env> </properties> <build> <finalName>${project.name}</finalName> <!-- --> <resources> <resource> <!-- 定义resource所在的文件夹 --> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> <pluginManagement> <plugins> <plugin> <!-- tomcat7-maven-plugin --> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <executions> <execution> <id>run-war-only</id> <phase>pre-integration-test</phase> <goals> <goal>run-war-only</goal> </goals> </execution> </executions> <configuration> <warDirectory>target/${project.name}</warDirectory> <path>/</path> <contextReloadable>true</contextReloadable> <uriEncoding>UTF-8</uriEncoding> <!-- 指定启动端口 --> <port>${server.port}</port> </configuration> </plugin> </plugins> </pluginManagement> </build> </profile> </profiles> |
1.在tomcat的安装目录下,修改conf / tomcat-user.xml文件,在<tomcat-users> 节点下面增长以下配置:tomcat
|
2.在maven中添加server,配置tomcat的管理员账号密码maven
如今tomcat开启了权限,maven既然要操做tomcat,那么maven就要拿到tomcat的管理员账号和密码才可以使用。测试
在maven的安装目录下,修改conf / setting.xml文件.在<server> 节点下面增长以下配置:ui
|
3.在project中添加插件,以及maven中配置的server,url
如今maven已经拥有操做tomcat的权限了,可是这二者之间想要通讯的话还须要一个桥梁,那就是在maven中配置tomcat插件.spa
修改项目的pom.xml文件,在<build> 节点下面增长以下配置:插件
|
4.打包命令code
clean:clean package -P dev tomcat7:run-war-only -f pom.xml |
说明:server