Java 如何在maven中从外部jar复制资源?
我有一个基于maven的多模块项目,具有以下模块结构:Java 如何在maven中从外部jar复制资源?,java,spring,maven,pom.xml,Java,Spring,Maven,Pom.xml,我有一个基于maven的多模块项目,具有以下模块结构: -- --A pom.xml --B pom.xml -pom.xml 我在parent.pom文件中添加了一个依赖项。现在我想使用A模块中添加的依赖项中的资源 有没有办法使用maven只将外部资源复制到a模块 为此,我尝试使用maven远程资源插件,但它没有看到外部资源。您必须向应该使用它的模块添加依赖项。然后您可以使用从该依赖项获取资源。您可以在第节的父POM中定义模块A和B的依赖项。然后在第节的子POM(A或B)中引
--
--A
pom.xml
--B
pom.xml
-pom.xml
我在parent.pom文件中添加了一个依赖项。现在我想使用A模块中添加的依赖项中的资源
有没有办法使用maven只将外部资源复制到a模块
为此,我尝试使用maven远程资源插件,但它没有看到外部资源。您必须向应该使用它的模块添加依赖项。然后您可以使用从该依赖项获取资源。您可以在第节的父POM中定义模块A和B的依赖项。然后在第节的子POM(A或B)中引用它们。通过这种方式,您可以确保在所有子模块中只使用给定依赖项的一个版本
maven中有关依赖关系管理的所有信息都记录在中,因此我找到了下一个解决方案。它不是最优的,但它可以工作,并且做我想做的事情。 它从外部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>
org.apache.maven.plugins
maven依赖插件
3.1.1
打开
生成源
打开
com.group.id
工件id
${version}
罐子
假的
**/前端/*.json
${project.build.directory}/classes/i18n
真的
假的
真的
com.coderplus.maven.plugins
复制重命名maven插件
1
复制和重命名文件
生成源
改名
${project.build.directory}/classes/i18n/META-INF/resources/i18n/frontend
${project.build.directory}/classes/i18n/frontend/
org.apache.maven.plugins
maven antrun插件
1.8
生成源
跑