我已经用maven创建了一个java项目。在我的项目中(在 src/main/resources 下),我想将一些资源文件复制到 target/classes 中。
我将这些行添加到我的 pom xml 中:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>
当我通过命令行运行mvn resources:resources时,我得到资源文件正在被复制到目标/类中(因此生命周期中的资源阶段正在工作)。但是,当我在 cmd 中输入 mvn install:install 时,资源文件不会被复制到目标/类中。
我得到:
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mqm-data-population ---
[INFO] Installing C:\xxx\xlation\pom.xml to C:\Users\xxx\xon-12.50.14-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.278 s
生命周期中的安装阶段似乎不会调用资源阶段或类似的东西..
我认为这可能与资源插件有关,所以我添加了:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>
这也没有帮助......
有人可以帮忙吗? 谢谢。
<小时/>已解决
<小时/>经过在线快速搜索后,我发现了为什么资源文件没有被复制到我的目标/类中。我需要使用 Maven 资源插件,并指出我希望将资源复制到目标/类中的阶段(在我的例子中,是“安装”阶段...)。
查看这里后: https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
我将其添加到我的 pom.xml 中,并且正在工作......
最佳答案
可能您的默认配置文件未激活,请通过添加 true 进行修改
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
关于java - Maven安装生命周期阶段不会调用资源阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32221565/