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

1. 在pom中配置

Maven 环境隔离实践

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

  

Maven 环境隔离实践

  <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 文件夹,

Maven 环境隔离实践

 将文件夹标记为Resources Root

Maven 环境隔离实践

 

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-12-01
  • 2021-12-15
  • 2021-09-05
  • 2021-04-14
  • 2021-05-28
猜你喜欢
  • 2021-05-04
  • 2021-09-16
  • 2021-12-08
  • 2021-11-05
  • 2022-01-28
相关资源
相似解决方案