【发布时间】:2015-06-02 10:49:36
【问题描述】:
在处理项目时,我的要求是创建一个模块。
命令如下:
mvn archetype:generate \
-DarchetypeCatalog=local \
-DartifactId=test-module
并且目标应该具有以下文件结构
test-module
|--pom.xml
`--src
`--main
|--install
| `--install.sh
`--scripts
`--test_module.sh
我的全部目标是创建另一个派生自 artifactId 的变量(比如 artifactIdWithUnderscore),将所有连字符 - 替换为 underscope _。这样我就可以使用更新的变量来创建文件。
例子:
+------------------+---------------------------------+
|INPUT - artifactId|OUTPUT - artifactIdWithUnderscore|
+------------------+---------------------------------+
| test-module | test_module |
| temp | temp |
| test-temp-module | test_temp_module |
+------------------+---------------------------------+
我尝试通过在 archetype-metadata.xml
中添加以下条目来创建一个新变量作为 artifactIdWithUnderscore选项 1:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${StringUtils.replace(${artifactId}, "-", "_")}</defaultValue>
</requiredProperty>
输出:
${StringUtils.replace(${artifactId}, "-", "_")}
选项 2:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
输出:
maven_archetype_script
上述artifactId的值来自archetype项目本身的POM。
选项 3:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId}.replaceAll("-", "_")</defaultValue>
</requiredProperty>
输出:
test-module.replaceAll("-", "_")
请告诉我如何实现这一目标。
编辑:
选项 4:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${__artifactId__.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
输出:
INFO: Null reference [template 'artifactIdWithUnderscore', line 1, column 1] : ${__artifactId__.replaceAll("-", "_")} cannot be resolved.
Define value for property 'artifactIdWithUnderscore': ${__artifactId__.replaceAll("-", "_")}: :
【问题讨论】:
-
你能给我们看看你的
archetype.properties文件吗? -
@MattEckert,我没有
archetype.properties文件。使用archetype-metadata.xml。
标签: maven maven-archetype