maven的隔离部署

场景:比如说我们一个项目,在开发的时候是一套配置文件,在发布的时候又是一套配置文件。我们每次都要修改配置文件很烦有木有。所以,我们需要maven的这样的一个功能,就是隔离部署。就是说我们写好几套配置文件,然后我们可以在发布的时候选择我们想要打包的配置文件。只需要在maven中配置一下就ok

 

需要在pom中添加

<build>
    <finalName>mmall</finalName>
    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
          <verbose>true</verbose>
          <overwrite>true</overwrite>
        </configuration>
      </plugin>

      <!-- geelynote maven的核心插件之-complier插件默认只支持编译Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml里面加上 增加编译插件 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
          <compilerArguments>
            <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
          </compilerArguments>
        </configuration>
      </plugin>
    </plugins>

    <resources>
      <resource>
        <directory>src/main/resources.${deploy.type}</directory>
        <excludes>
          <exclude>*.jsp</exclude>
        </excludes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>

  </build>

  <profiles>
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <deploy.type>dev</deploy.type>
      </properties>
    </profile>
    <profile>
      <id>beta</id>
      <properties>
        <deploy.type>beta</deploy.type>
      </properties>
    </profile>
    <profile>
      <id>prod</id>
      <properties>
        <deploy.type>prod</deploy.type>
      </properties>
    </profile>
  </profiles>
View Code

上面的代码的意思是其实就是定义一个变量   然后build里面的<resource>节点取那几个的值来达到到底加载那个配置文件源。

当然了,我们也要相应的在文件夹的地方写上我们的配置文件

看下图

然后我们用mvaven的打包命令      

mvn clean package -Dmaven.test.skip=true -Pdev

意思是跳过test测试   先clean 然后打包  选择dev资源下的包

posted @ 2018-04-02 23:21  发疯的man  阅读(362)  评论(0编辑  收藏  举报