![](/img/trans.png)
[英]How to include a config file in the “META-INF/services” folder of a JAR using Maven
[英]Maven: include files in JAR's META-INF
我正在使用 Maven 構建一個 Java 項目,我有幾個文件CHANGELOG
和LICENSE
,我想將它們復制到 JAR 文件內的META-INF
目錄中。
到目前為止,我的工作如下:
<build>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>CHANGELOG</include>
<include>LICENSE</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
</resources>
<plugins>
...
但這也會在編譯時將這兩個文件復制到classes/META-INF
目錄。
所以我希望這些文件包含在 JAR 文件中,但沒有其他地方。 有沒有辦法做到這一點?
您不需要指定任何自定義 Maven 配置來滿足您的需求。
在src/main/resources
,只需創建一個META-INF
文件夾並將您的文件放在此處。
這樣,您就可以在構建的 JAR 的META-INF
文件夾中找到它們。
此外,您應該刪除在pom.xml
添加的<resource>
元素,因為它將默認資源文件夾更改為項目的根目錄,而不是默認的src/main/resources
。
如果要將文件和目錄添加到 META-INF 文件夾,請在 pom.xml 中使用此代碼
<build>
<finalName>CustomJsfComponents</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**.xml</include>
<include>**resources/**</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
</resources>
</build>
通過添加webResources修改你的 pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>target/classes/META-INF/</directory>
<includes>
<include>*.*</include>
</includes>
<targetPath>META-INF/</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
考慮要在其中找到的 config.properties 文件
src / main / resources / META-INF / config.properties
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.