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

背景:
由于项目处于变更频发阶段,经常需要同时在dev、test、demo、uat环境打包发布,由于现在没有绑定域名,在做单点登录的时候,每次打包都需要手动修改web.xml中的ip地址,十分麻烦,并且非常容易出错。

如何解决此类问题
1、在pom的profile中添加如下代码:新增cas.serverLoginUrl、cas.serverName、cas.serverUrlPrefix三个properties


<profiles>
    <profile>
        <id>developmentid>
        <activation>
            <activeByDefault>trueactiveByDefault>
        activation>
        <properties>
            <profiles.active>devprofiles.active>
            <mybatis.log>ERRORmybatis.log>
            <log.path>/opt/dev/log.path>
            <cas.serverLoginUrl>http://10.1.1.1cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1cas.serverUrlPrefix>
        properties>
    profile>
    <profile>
        <id>testid>
        <properties>
            <profiles.active>testprofiles.active>
            <mybatis.log>ERRORmybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1cas.serverUrlPrefix>
        properties>
        properties>
    profile>
    <profile>
        <id>demoid>
        <properties>
            <profiles.active>demoprofiles.active>
            <mybatis.log>ERRORmybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1cas.serverUrlPrefix>
        properties>
    profile>
    <profile>
        <id>uatid>
        <properties>
            <profiles.active>uatprofiles.active>
            <mybatis.log>ERRORmybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1cas.serverUrlPrefix>
        properties>
    profile>
    <profile>
        <id>preid>
        <properties>
            <profiles.active>preprofiles.active>
            <mybatis.log>ERRORmybatis.log>
        properties>
    profile>
    <profile>
        <id>productionid>
        <properties>
            <profiles.active>proprofiles.active>
            <mybatis.log>ERRORmybatis.log>
        properties>
    profile>
profiles>

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

<plugin>
    <groupId>org.apache.maven.pluginsgroupId>
    <artifactId>maven-war-pluginartifactId>
    <version>2.1.1version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/webappdirectory>
                <filtering>truefiltering>
            resource>
        webResources>
    configuration>
plugin>

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

<filter>
   <filter-name>CASFilterfilter-name>
   <filter-class>com.ezubo.global.om.web.filter.LoginFilterfilter-class>
   param>
      <param-name>casServerLoginUrlparam-name>
      <param-value>${cas.serverLoginUrl}param-value>
   param>
   param>
      <param-name>serverNameparam-name>
      <param-value>${cas.serverName}param-value>
   param>
   param>
      <param-name>noFilterUrlparam-name>
      <param-value>*.jsparam-value>
   param>
filter>

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

你可能感兴趣的:(Web)