簡體   English   中英

如何將 .properties 文件從父項目共享到子項目

[英]how share a .properties file from parent project to child projects

我有一個帶有 .properties 文件的父項目,這個文件根據項目定義的配置文件進行過濾,這個項目有子項目或模塊,我希望過濾后的 .properties 文件可用於子項目,我可以使用 java 中的 resourceBoundle 或其他方式訪問文件的屬性。

我嘗試使用,沒有運氣如何在 Maven2 模塊之間共享過濾器文件? -> MojoHaus 項目

父 pom

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.data</groupId>
    <artifactId>data2</artifactId>
    <version>data-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>dataNameapp</name>

    <modules>
        <module>child  1</module>
        <module>child  2</module>
        </modules>
.....
</project>

子項目

reference parent properties in pom some code In guess

使用過 java 代碼
child1/test.java

ResourceBundle resourceBundleProperties= ResourceBundle.getBundle("parentproperties")

更新

在 mi 父項目中,extras 中的這個文件被過濾,當我通過它時,我希望它更新其他內部文件屬性

parent--extras/filtered.properties (file filtered)
   child
   --filters/filtered.properties (get from parent)  
   --resources/final.properties  (filtered of filtered.properties)

您可以嘗試使用 Maven 的資源插件從父項目復制文件,例如:

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>process-resourcesphase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${basedir}/target/resources</outputDirectory>
                  <resources>          
                    <resource>
                      <directory>${project.parent.basedir}/src/resources/extras</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>              
                </configuration>            
              </execution>
            </executions>
          </plugin>
        </plugins>
        ...
      </build>
      ...
    </project>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM