zoukankan      html  css  js  c++  java
  • 在propreties文件中引用另一个properties文件中的内容

    转载:http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1

     
     
     
    How do I filter resources based on values from a properties file?
    Author: Deron Eriksson
    Description: This tutorial describes how to filter resources based on properties in a file.
    Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)

    Page:    1 2 >

    In another tutorial, we saw how we could filter resource files so that we could replace references to properties with the values of those properties and how this substitution takes place during the "process-resources" default lifecycle phase. We can also specify properties in a properties file and use these properties in the substitutions during the "process-resources" lifecycle phase.

    For example, suppose we have the following resource file.

    src/main/resources/textfile.txt

    this is a test
    artifact id: ${project.artifactId}
    my.property: ${my.property}
    

    The project.artifactId property value comes from the project's pom.xml, but we'd like the my.property to be specified in a properties file, such as the following:

    src/main/filters/myfilter.properties

    my.property=hamburger and fries

    The project containing the resource file and the filter properties file are shown here:

    Project structure

    Here is the project's pom.xml file. It specifies to use the properties in the myfilter.properties file via the build.filters.filter value. It specifies to turn on filtering by setting build.resources.resource.filtering to true. It specifies the resource directory via the build.resources.resource.directory (this is needed since we overrid the default behavior by setting filtering to true).

    pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.maventest</groupId>
    	<artifactId>aproject</artifactId>
    	<packaging>jar</packaging>
    	<version>1.0-SNAPSHOT</version>
    	<name>aproject</name>
    	<url>http://maven.apache.org</url>
    	<dependencies>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>3.8.1</version>
    			<scope>test</scope>
    		</dependency>
    	</dependencies>
    	<build>
    		<filters>
    			<filter>src/main/filters/myfilter.properties</filter>
    		</filters>
    		<resources>
    			<resource>
    				<directory>src/main/resources</directory>
    				<filtering>true</filtering>
    			</resource>
    		</resources>
    	</build>
    </project>



    page2:

    Now, I'll perform a "mvn clean process-resources" on the project.

    Executing 'mvn clean process-resources' on 'aproject'

    This generates the target/classes/textfile.txt file.

    textfile.txt in target/classes

    If we examine the contents of the textfile.txt file, we can see that it has been filtered to contain the property values. The project.artifactId value came from the pom.xml file, and the my.property value came from the myfilter.properties file.

    target/classes/textfile.txt

    this is a test
    artifact id: aproject
    my.property: hamburger and fries
    
  • 相关阅读:
    hdu 5001(概率DP)
    hdu 5505(数论-gcd的应用)
    csu 1749: Soldiers ' Training(贪心)
    Button Bashing(搜索)
    Jury Jeopardy(反向模拟)
    interesting Integers(数学暴力||数论扩展欧几里得)
    湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)
    csu 1551(线段树+DP)
    csu 1555(线段树经典插队模型-根据逆序数还原序列)
    csu 1552(米勒拉宾素数测试+二分图匹配)
  • 原文地址:https://www.cnblogs.com/kongweiteng/p/6733132.html
Copyright © 2011-2022 走看看