maven-remote-resources-plugin 不复制文件,只复制文件夹结构
maven-remote-resources-plugin doesn't copy files, only folder structure
我有一个 Maven 项目,其中一个模块是 java 网络应用程序(A 模块),另一个模块(B 模块)也是一个 java 使用 类 来自 A 模块及其资源。创建一个 jar 并将其安装在 Maven 存储库中,编译 B 模块没问题,但我的问题是将资源从 A 复制到 B。
我正在尝试从 A 模块复制 jsp 和其他文件。按照文档和一些博客,我设法获得了 target\classes\META-INF\maven\remote-resources.xml
,但是当我尝试在 B 模块中复制这些资源时,我只获得了文件夹结构,但里面没有任何文件。
一个模块pom
<profile>
<id>validator</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.basedir}/src/main/webapp</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
B模块pom
<profile>
<id>embedded</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<configuration>
<resourceBundles>
<resourceBundle>my.group:my.artifact:${my.version}</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
</resources>
</build>
</profile>
在输出中我没有收到任何错误,但是 target\maven-shared-archive-resources\
中没有文件,只有模块 A 中的文件夹结构。
知道我做错了什么吗?
好的,我找到了解决办法。
看起来远程 maven-remote-resources-plugin 只适用于 src/main/resources 下的资源所以在我的例子中诀窍是通过资源将 /webapp/* 复制到该文件夹并在复制资源后执行插件我有在插件中指定 <phase>process-resources</phase>
否则它会在资源到位之前执行。
这是配置文件的代码
<profile>
<id>share-resources</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
<!-- This is the one for webapp -->
<resource>
<directory>${project.basedir}/src/main/webapp</directory>
<targetPath>${project.build.outputDirectory}/shared-resources</targetPath>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/shared-resources/**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
获取模块 B 中的资源就像文档中那样
我有一个 Maven 项目,其中一个模块是 java 网络应用程序(A 模块),另一个模块(B 模块)也是一个 java 使用 类 来自 A 模块及其资源。创建一个 jar 并将其安装在 Maven 存储库中,编译 B 模块没问题,但我的问题是将资源从 A 复制到 B。
我正在尝试从 A 模块复制 jsp 和其他文件。按照文档和一些博客,我设法获得了 target\classes\META-INF\maven\remote-resources.xml
,但是当我尝试在 B 模块中复制这些资源时,我只获得了文件夹结构,但里面没有任何文件。
一个模块pom
<profile>
<id>validator</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.basedir}/src/main/webapp</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
B模块pom
<profile>
<id>embedded</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<configuration>
<resourceBundles>
<resourceBundle>my.group:my.artifact:${my.version}</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
</resources>
</build>
</profile>
在输出中我没有收到任何错误,但是 target\maven-shared-archive-resources\
中没有文件,只有模块 A 中的文件夹结构。
知道我做错了什么吗?
好的,我找到了解决办法。
看起来远程 maven-remote-resources-plugin 只适用于 src/main/resources 下的资源所以在我的例子中诀窍是通过资源将 /webapp/* 复制到该文件夹并在复制资源后执行插件我有在插件中指定 <phase>process-resources</phase>
否则它会在资源到位之前执行。
这是配置文件的代码
<profile>
<id>share-resources</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/config/embedded</directory>
</resource>
<!-- This is the one for webapp -->
<resource>
<directory>${project.basedir}/src/main/webapp</directory>
<targetPath>${project.build.outputDirectory}/shared-resources</targetPath>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<excludes>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/META-INF/**</exclude>
</excludes>
<includes>
<include>**/shared-resources/**/*.*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
获取模块 B 中的资源就像文档中那样