【发布时间】:2022-01-25 20:53:22
【问题描述】:
我从我的 pom.xml 中的doc 复制粘贴了以下 sn-p
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/resources</outputDirectory>
<resources>
<resource>
<directory>${basedir}/template</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
但当我尝试触发部署时收到以下消息:
$ mvn resources:copy-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.test:myproject >------------------------
[INFO] Building myproject-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:copy-resources (default-cli) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.440 s
[INFO] Finished at: 2021-12-26T12:30:59+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources (default-cli) on project myproject: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
这是我的目录结构:
./resources
./template
./template/test.txt
./pom.xml
如何更改资源的目标文件夹?为什么maven没有解析插件中的配置指令?
【问题讨论】:
-
首先为什么要更改目标文件夹,因为资源目录旨在打包到生成的工件中?你想完成什么?
-
仅用于学习目的。我有一些外部文件要参数化,我的目标是只使用 maven 完成工作。我知道这不是正确的工具,但我想强制项目配置完成额外的琐事。无论如何,我研究 maven 的主要原因是在构建时参数化源代码,即在构建时解析变量,例如 -D 在启动时。不确定使用预处理是否可行
-
如果您确实需要对源代码进行一些参数化,有更好的解决方案,例如:mojohaus.org/templating-maven-plugin
-
是的,我在 java 源代码中使用了 template-maven-plugin。但我需要参数化一些数据文件,这就是我使用资源插件的原因。
标签: java maven deployment