![](/img/trans.png)
[英]Maven Eclipse: How to include custom folder (with files) into the “target” folder on build?
[英]How to include custom folder in Maven Package?
下面是我的項目結構:
META-INF/abc.jpg
META-INF/xyz.jpg
src/com/hcc/files.java
pom.xml
以下是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>xyz</groupId>
<artifactId>zyx</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${basedir}/META-INF/services/abc.px" tofile="${project.build.directory}/META-INF/services/abc.px" />
<copy file="${basedir}/META-INF/services/xyz.px" tofile="${project.build.directory}/META-INF/services/xyz.px" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>abc</groupId>
<artifactId>abc</artifactId>
<version>936</version>
<scope>system</scope>
<systemPath>path</systemPath>
</dependency>
</dependencies>
</project>
當我嘗試使用mvn compile
進行編譯時,它會創建一個目標文件夾。
ex - target/classes/com/hcc
如何在創建包時包含 META-INF 文件夾,即 mvn 包,以便我的 jar 文件包含目標文件夾文件和META-INF
文件夾?
在pom.xml
的 build 部分中,在 maven war 插件聲明下,您可以添加必要的配置,在其中將 Web 資源指定為目錄及其輸出路徑:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>${maven-war-plugin.version}</version>
<configuration>
<webResources>
<resource>
<directory>META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
或者通過將其添加為直接在 build 下的資源:
<build>
....
<resources>
<resource>
<directory>META-INF</directory>
</resource>
</resources>
</build>
在我的 pom.xml 的構建部分,我添加了一個資源標簽和相應的配置,以便在打包時復制 jar 中的自定義文件。
<resource>
<directory>META-INF</directory>
<includes>
<include>**services/**</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.