我现在正在尝试创建一个使用 spring + mybatis
框架的 Maven 原型(prototype)。有一个mybatis xml文件:src/main/resources/archetype-resources/src/main/resources/sql/myapp/DemoUser.xml
,并执行以下命令使用此原型(prototype)创建新项目。
mvn archetype:generate ... -DartifactId=foo.bar -Dpackage=com.foo.bar ...
我想将myapp
替换为bar
,即我想将sql/bar
文件夹中的mybatis xml文件,如何实现?
最佳答案
我的方法是在src/main/resources/META-INF/maven/archetype-metadata.xml
中添加此属性
<requiredProperty key="appName">
<defaultValue>${appName}</defaultValue>
</requiredProperty>
然后在src/main/resources/archetype-resources/pom.xml
中添加
#set ($artifactId = "${artifactId}")
#set ($index = $artifactId.indexOf('.'))
#set ($index = $index + 1)
#set ($appName = $artifactId.substring($index))
并记住将文件夹名称更改为
src/main/resources/archetype-resources/src/main/resources/sql/__appName__/DemoUser.xml
因此,当您现在执行 mvn archetype:generate ... -DartifactId=foo.bar ...
时,您可以获得
│ └── resources
│ └── sql
│ └── bar
│ └── DemoUser.xml
引用文档:http://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html
关于maven - 使用maven archetype创建新项目如何指定自定义文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38341846/