IntelliJ IDEA meven的配置文件管理

来源:互联网 发布:莱恩打碟软件安装教程 编辑:程序博客网 时间:2024/06/16 00:18

IntelliJ IDEA meven的配置文件管理

 

     java后台项目中会用到meven对项目进行编译、导包、发布

等操作。


     pom中可以通过配置变量,来配置文件直接的映射关系。

     通过meven可以管理整个项目的配置文件:

 

     实现思路:

     1、通过pom.xml文件配置系统配置文件

     2、通过业务配置文件调用

     3、应用层文件调用业务配置文件


    思路图:


   

     实现代码:

<!-- 定义环境 start--><profiles>  <profile>  <id>localhost</id>  <properties>  <env>localhost</env>  <name>manage</name>  </properties>  </profile>  </profiles><build>    <filters>    <filter>src/main/resource/filter/${env}.properties</filter> <!-- 得到localhost  映射到resource下的filter目录下 -->    </filters>    <resources>    <resource>    <directory>src/main/resource</directory>    <filtering>true</filtering>    </resource>    </resources><plugins>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-compiler-plugin</artifactId>            <configuration>                <source>1.8</source>                <target>1.8</target>                <encoding>UTF-8</encoding>            </configuration>        </plugin></plugins>    <finalName>${name}</finalName>     <!-- 得到manage-->  </build>


调用配置文件:

jdbc.properties:

# mysql configjdbc.driver.class=com.mysql.jdbc.Driverjdbc.db_maxActive=50jdbc.url=${jdbc.url}jdbc.username=${jdbc.username}jdbc.password=${jdbc.password}


系统配置文件:

localhost.properties:


host=192.168.1.154port=6379password=tyhd4545259879jdbc.url=jdbc:mysql://119.29.19.173:3306/majiang?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNulljdbc.username=rootjdbc.password=4165587downloadHost=http\://192.168.1.154\:8080/download/version




原创粉丝点击