簡體   English   中英

json文件的Maven資源過濾

[英]Maven resource filtering of json file

在我當前的項目中,我有一個子模塊,它使用maven exec插件來運行測試服務,該服務從resources / testResources文件夾之外的位置提取配置文件。

我需要使用過濾將環境變量注入到一些配置文件中。 這適用於其中一個文件,一個.properties文件,但不適用於另一個.json文件。 在后一種情況下,它只是將變量留在json文件中。 這兩個文件在篩選目錄中彼此相鄰。

以下是子模塊的過濾片段:

<build>
  <finalName>${artifactId}</finalName>
  <testResources>
    <testResource>
      <filtering>true</filtering>
      <directory>../etc</directory>
    </testResource>
  </testResources>

json文件:

{ "customMappings" :
    { "tag:example.com:/vagrant/" : "file:${VAGRANT_CWD}" }
}

縮寫項目結構:

  • 項目
    • 等等
      • config.properties
      • config.json
    • 子模塊
      • 的pom.xml

子模塊肯定會加載兩個文件,但只過濾.properties文件。

它是一個特殊的關於它是一個json文件,可以防止過濾發生嗎? 有什么可以做的嗎?

為了它的價值,我最終做到了這一點。 我發現我必須直接列出要包含的文件以便進行處理(已經很長時間了,所以希望這是正確的解決方案):

<build>
  <finalName>${artifactId}</finalName>
  <testResources>
    <testResource>
      <filtering>true</filtering>
      <directory>../etc</directory>
      <includes>
        <include>config.json</include>
        <include>config.properties</include>
      </includes>
    </testResource>
  </testResources>
...

暫無
暫無

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

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