`

maven的多环境打包部署与web.xml整合

 
阅读更多

为什么需要

现在同时维护着dev、test、demo、uat环境,由于现在没有绑定域名,在做单点登录的时候,每次打包都需要手动修改web.xml中的ip地址,十分麻烦,并且非常容易出错。

怎么做

使用maven的profile

1.在pom的profile中添加如下代码:新增cas.serverLoginUrl、cas.serverName、cas.serverUrlPrefix三个properties

<profiles>
    <profile>
        <id>development</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profiles.active>dev</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <log.path>/home/lirui/dev</log.path>
            <cas.serverLoginUrl>http://10.11.100.48:8880/login</cas.serverLoginUrl>
            <cas.serverName>http://10.11.11.167:8080</cas.serverName>
            <cas.serverUrlPrefix>http://10.11.100.48:8880/</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <profiles.active>test</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://10.11.100.48:8880/login</cas.serverLoginUrl>
            <cas.serverName>http://localhost:8080</cas.serverName>
            <cas.serverUrlPrefix>http://10.11.100.48:8880/</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>demo</id>
        <properties>
            <profiles.active>demo</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://123.57.27.212</cas.serverLoginUrl>
            <cas.serverName>http://123.56.120.217</cas.serverName>
            <cas.serverUrlPrefix>http://123.57.27.212</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>uat</id>
        <properties>
            <profiles.active>uat</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://123.57.237.183</cas.serverLoginUrl>
            <cas.serverName>http://123.57.85.22</cas.serverName>
            <cas.serverUrlPrefix>http://123.57.237.183</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>pre</id>
        <properties>
            <profiles.active>pre</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
        </properties>
    </profile>
    <profile>
        <id>production</id>
        <properties>
            <profiles.active>pro</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
        </properties>
    </profile>
</profiles>

2.在web module的pom中,新增过滤web资源配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
</plugin>

3.在web.xml中用占位符替换

<filter>
   <filter-name>CASFilter</filter-name>
   <filter-class>com.ezubo.global.om.web.filter.LoginFilter</filter-class>
   <init-param>
      <param-name>casServerLoginUrl</param-name>
      <param-value>${cas.serverLoginUrl}</param-value>
   </init-param>
   <init-param>
      <param-name>serverName</param-name>
      <param-value>${cas.serverName}</param-value>
   </init-param>
   <init-param>
      <param-name>noFilterUrl</param-name>
      <param-value>*.js</param-value>
   </init-param>
</filter>

4.打包时加入-P,如demo环境  mvn clean package -DskipTests -Pdemo

5.没了

分享到:
评论
1 楼 laodongbao 2016-08-18  
学习了  

相关推荐

Global site tag (gtag.js) - Google Analytics