gpt4 book ai didi

java - 如何在maven中从外部jar复制资源?

转载 作者:太空宇宙 更新时间:2023-11-04 10:10:30 25 4
gpt4 key购买 nike

我有一个基于多模块 Maven 的项目,具有以下模块结构:

--
--A
pom.xml
--B
pom.xml
-pom.xml

我在 .pom 文件中添加了依赖项。现在我想使用 A 模块中添加的依赖项中的资源。

有没有办法使用 maven 仅将外部资源复制到 A 模块?

我尝试使用maven-remote-resources-plugin来实现此目的,但它看不到外部资源。

最佳答案

所以我找到了下一个解决方案。它不是最佳的,但它可以工作并且可以满足我的要求。它从外部jar(maven依赖)中提取资源文件并将其复制到类路径资源中。

这不是最佳选择,因为在文件移动到所需位置后我必须删除空目录。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>${version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<includes>**/frontend/*.json</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/classes/i18n</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>copy-and-rename-file</id>
<phase>generate-sources</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/classes/i18n/META-INF/resources/i18n/frontend
</sourceFile>
<destinationFile>${project.build.directory}/classes/i18n/frontend/
</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete dir="${project.build.outputDirectory}/i18n/META-INF" includeemptydirs="true"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - 如何在maven中从外部jar复制资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52406411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com