如何筛选资源文件:
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> 启用筛选,默认false </resource> </resources> </build>
在src/main/resources里,新增一个application.properties文件
# application.properties application.name=${env.PATH} application.name=${settings.offline} application.name=${java.home} application.version=${pom.name} application.version=${project.version}
运行cmd
mvn process-resources
就会被放到target/classes里
# application.properties application.name=C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;F:\\MySQL\\MySQL Server 5.1\\bin;D:\\Program Files\\TortoiseSVN\\bin;D:\\Program Files\\TortoiseGit\\bin;d:\\Program Files (x86)\\Git\\cmd;F:\\apache-maven-3.2.3\\bin;F:\\Java\\jdk1.8.0_25\\bin;F:\\HashiCorp\\Vagrant\\bin;F:\\Tomcat 7.0\\bin application.name=false application.name=F:\\Java\\jdk1.8.0_25\\jre application.version=my-app application.version=1.0-SNAPSHOT
现在新建个src/main/filters/filter.properties:
# filter.properties my.filter.value=hello!
更改pom.xml:
<build> <filters> <filter>src/main/filters/filter.properties</filter> </filters> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
更改application.properties:
message=${my.filter.value}
就会变成:
message=Hello!
当然也可以完全不用外部文件,直接在pom.xml的properties里定义,当然也无需引用外部文件
时间: 2024-10-05 04:40:49