zoukankan      html  css  js  c++  java
  • 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资源下的包

  • 相关阅读:
    Cors 跨域 共享
    关于上传视频到七牛的一些解决方案
    网站上传视频注意点
    Node.js 的环境配置
    动态加载js
    java web项目启动时自动加载自定义properties文件
    Apache Commons 工具类介绍及简单使用
    spring常用的工具类
    shiro内置过滤器研究
    抓取Js动态生成数据且以滚动页面方式分页的网页
  • 原文地址:https://www.cnblogs.com/coder-lzh/p/8698666.html
Copyright © 2011-2022 走看看