使用maven远程资源插件并指定resourcesDirectory
在使用maven远程资源插件时,我试图覆盖默认的资源目录(src/main/resources)。但是,下面示例中的指定值似乎没有被考虑在内。如果有人能给我一些建议,我将不胜感激使用maven远程资源插件并指定resourcesDirectory,maven,maven-2,maven-3,maven-plugin,maven-remote-resources,Maven,Maven 2,Maven 3,Maven Plugin,Maven Remote Resources,在使用maven远程资源插件时,我试图覆盖默认的资源目录(src/main/resources)。但是,下面示例中的指定值似乎没有被考虑在内。如果有人能给我一些建议,我将不胜感激 <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/
<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>my.resource.library</groupId>
<artifactId>resource-library</artifactId>
<version>1.0</version>
<name>ResourceLibrary</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<resourcesDirectory>${basedir}/common</resourcesDirectory>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
编辑:我认为这实际上可能是一个bug,所以我提出:为什么需要maven远程资源插件 如果您的目标是覆盖默认资源目录,那么您可以使用,因为它更灵活。举个例子 备选方案 您还可以使用resources插件提供的
resources
目标,并在pom文件的块中指定资源。例如
编辑 关于maven远程资源插件,请参见以下页面: 这将触发对该项目的$basedir/src/main/resources目录的扫描,并创建$basedir/target/classes/META-INF/maven/remote-resources.xml清单文件 这意味着该插件将创建
远程资源.xml
文件,但并不意味着它将为您复制资源
我使用插件配置创建了一个空的maven项目,它实际上创建了一个remote-resources.xml文件。此外,它没有复制${basedir}/common下的文件
为此,只需在build部分指定资源。例如:
<build>
<resources>
<resource>
<directory>${basedir}/common</directory>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<resourcesDirectory>${basedir}/common</resourcesDirectory>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
${basedir}/common
${basedir}/src/main/resources
org.apache.maven.plugins
maven远程资源插件
1.5
捆
${basedir}/common
**/*
kly没有为您复制资源是正确的(很抱歉,我还不能发表评论-声誉不够)
对于“bundle”目标,您只需要生成包含资源列表的清单。清单必须与资源本身一起打包在工件中,只有在您还使用复制资源将它们放在target/classes目录中时,才会在实例中发生这种情况
然后,您必须在您希望使用资源的任何其他项目中使用“流程”目标,并列出您的捆绑包。这不是原因,但您是否尝试在
?
@GeroldBroser中添加文件扩展名谢谢您的提醒。我刚刚尝试了以下内容,但似乎都不起作用:common.txt
,***.txt
,***.txt
。您能提供生成的输出吗?@GeroldBroser我已经在我的原始帖子中添加了一些生成的调试输出。谢谢您的建议。我之所以使用远程资源插件,是因为我希望能够将资源集中到一个可以被其他项目包含的项目中。目标似乎意味着该插件应该包含这些资源:“捆绑应该被视为远程资源的资源。”@JiteshVassa默认情况下,它确实包含这些资源,它只包括src/main/resources目录中的资源,如中所指定。然而,这个行为本身并不是由这个插件驱动的。在您的例子中,您希望它包含${basedir}/common
中的资源,因此您需要利用我介绍的方式添加额外的行为。另外,有些插件确实允许您指定要复制的资源,比如复制资源。我认为这一个不能做到这一点,“resourcesDirectory”的名字和它的名字让人们认为它会复制资源。但事实并非如此。因此,人们可以说这是一个bug。
<build>
<resources>
<resource>
<directory>${basedir}/common</directory>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<resourcesDirectory>${basedir}/common</resourcesDirectory>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>