work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Maven 环境隔离实践

Posted on 2018-07-31 14:54  work hard work smart  阅读(300)  评论(0编辑  收藏  举报

现在将SpringMVC中Maven环境隔离实践总结如下:

1. 在pom中配置

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

  

  <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>

  

2. 创建resources.beta, resources.dev, resources.prod 文件夹,

 将文件夹标记为Resources Root

 

3. 打包命令

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

beta代码使用beta文件下的配置

 

第三步遇到的问题

1)编码GBK的不可映射字符

解决方法:

 <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

 参考:https://blog.csdn.net/EvelynHouseba/article/details/16114353 

 

 2) 程序包***不存在,找不到符号

pom文件中配置插件maven-compiler-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <encoding>UTF-8</encoding>
        <compilerArgs>
            <arg>-verbose</arg>
            <arg>-Xlint:unchecked</arg>
            <arg>-Xlint:deprecation</arg>
            <arg>-bootclasspath</arg>
            <arg>${env.JAVA_HOME}/jre/lib/rt.jar</arg>
            <arg>-extdirs</arg>
            <arg>${project.basedir}/src/main/webapp/WEB-INF/lib</arg>
        </compilerArgs>
    </configuration>
</plugin>  

参考:https://blog.csdn.net/wabyking/article/details/79700030

 

3) Maven项目的子模块不能打成jar包输出到lib目录

1、在子模块的pom.xml中加个打包方式

  <packaging>jar</packaging>

2、再对对模块执行下mvn clean install