CAS (13) —— CAS 使用Maven Profile支持多环境编译

CAS (13) —— CAS 使用Maven Profile支持多环境编译

摘要

CAS 使用Maven Profile支持多环境编译


版本

tomcat版本: tomcat-8.0.29

jdk版本: jdk1.8.0_65

cas版本: 4.1.3

**cas4.1.3 (4.x还在开发过程中不是很稳定,迭代比较快,也会有些bug) **

cas-client-3.4.1

maven版本: 3.3.9

主要内容

准备

以项目github上CAS项目为例进行扩充

  • 参考文章

CAS (1) —— Mac下配置CAS到Tomcat(服务端)

配置

扩充不同环境下需要定制配置文件目录

Profile使用

<profiles>
      <profile>
          <id>local8433</id>
          <properties>
              <env>local8433</env>
          </properties>
          <activation>
              <activeByDefault>true</activeByDefault>
          </activation>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                          <exclude>*.bak</exclude>
                      </excludes>
                  </resource>
                  <resource>
                      <directory>src/main/resources-config/local8433</directory>
                  </resource>
              </resources>
          </build>
      </profile>
      <profile>
          <id>local8443</id>
          <properties>
              <env>local8443</env>
          </properties>
          <activation>
              <activeByDefault>true</activeByDefault>
          </activation>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                          <exclude>*.bak</exclude>
                      </excludes>
                  </resource>
                  <resource>
                      <directory>src/main/resources-config/local8443</directory>
                  </resource>
              </resources>
          </build>
      </profile>

      <profile>
          <id>local</id>
          <properties>
              <env>local</env>
          </properties>
          <activation>
              <activeByDefault>true</activeByDefault>
          </activation>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                          <exclude>*.bak</exclude>
                      </excludes>
                  </resource>
                  <resource>
                      <directory>src/main/resources-config/local</directory>
                  </resource>
              </resources>
          </build>
      </profile>
    <profile>
      <id>dev</id>
      <properties>
        <env>dev</env>
      </properties>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <excludes>
              <exclude>*.bak</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/main/resources-config/dev</directory>
          </resource>
        </resources>
      </build>
    </profile>
    <profile>
      <id>qa</id>
      <properties>
        <env>qa</env>
      </properties>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <excludes>
              <exclude>*.bak</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/main/resources-config/qa</directory>
          </resource>
        </resources>
      </build>
    </profile>
    <profile>
      <id>prod</id>
      <properties>
        <env>prod</env>
      </properties>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <excludes>
              <exclude>*.bak</exclude>
            </excludes>
          </resource>
          <resource>
            <directory>src/main/resources-config/prod</directory>
          </resource>
        </resources>
      </build>
    </profile>
      <profile>
          <id>prod215</id>
          <properties>
              <env>prod215</env>
          </properties>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                          <exclude>*.bak</exclude>
                      </excludes>
                  </resource>
                  <resource>
                      <directory>src/main/resources-config/prod215</directory>
                  </resource>
              </resources>
          </build>
      </profile>
      <profile>
          <id>prod216</id>
          <properties>
              <env>prod216</env>
          </properties>
          <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                          <exclude>*.bak</exclude>
                      </excludes>
                  </resource>
                  <resource>
                      <directory>src/main/resources-config/prod216</directory>
                  </resource>
              </resources>
          </build>
      </profile>
  </profiles>

Filter使用

<build>
    <filters>
        <filter>${basedir}/src/main/webapp-config/${env}/filters/cas.properties</filter>
        <!--<filter>${basedir}/src/main/webapp-config/${env}/filters/spring-configuration/ticketRegistryDataSource.xml</filter>-->
        <!--<filter>${basedir}/src/main/webapp-config/${env}/filters/spring-configuration/authenticationDataSource.xml</filter>-->
        <filter>${basedir}/src/main/webapp-config/${env}/filters/spring-configuration/authenticationEncoder.xml</filter>
    </filters>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <warName>cas</warName>
          <webResources>
            <resource>
              <directory>${basedir}/src/main/webapp/WEB-INF</directory>
              <filtering>true</filtering>
              <targetPath>WEB-INF</targetPath>
              <includes>
                <include>**/web.xml</include>
              </includes>
              <excludes>
                <exclude>**.bak</exclude>
              </excludes>
            </resource>
              <resource>
                  <directory>${basedir}/src/main/webapp-config/${env}/filters</directory>
                  <filtering>true</filtering>
                  <targetPath>WEB-INF</targetPath>
                  <includes>
                      <include>*.properties</include>
                      <include>**.xml</include>
                  </includes>
              </resource>
              <resource>
                  <directory>${basedir}/src/main/webapp-config/${env}/filters/spring-configuration</directory>
                  <filtering>true</filtering>
                  <targetPath>WEB-INF/spring-configuration</targetPath>
                  <includes>
                      <include>*.properties</include>
                      <include>**.xml</include>
                  </includes>
              </resource>
          </webResources>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${maven-jetty-plugin.version}</version>
        <configuration>
          <webApp>
            <contextPath>/cas</contextPath>
          </webApp>
        </configuration>
      </plugin>
  </build> 

参考

Introduction to Build Profiles

CAS (7) —— Mac下配置CAS 4.x集群及JPATicketRegistry

结束

posted @ 2016-02-23 11:48  Richaaaard  阅读(1461)  评论(0编辑  收藏  举报