问题描述
我现在正在尝试创建一个使用spring + mybatis
框架的Maven原型.有一个mybatis xml文件:src/main/resources/archetype-resources/src/main/resources/sql/myapp/DemoUser.xml
,然后执行以下命令以使用该原型创建新项目.
I'm now trying to create a maven archetype which uses spring + mybatis
framework. There is a mybatis xml file: src/main/resources/archetype-resources/src/main/resources/sql/myapp/DemoUser.xml
, and execute below command to create new project using this archetype.
mvn archetype:generate ... -DartifactId=foo.bar -Dpackage=com.foo.bar ...
我想将myapp
替换为bar
,也就是说我想将mybatis xml文件放在sql/bar
文件夹中,如何实现呢?
I want to replace myapp
to bar
, that is I want to mybatis xml file in sql/bar
folder, how to implement this?
推荐答案
我的方法是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))
并记住将文件夹名称更改为
and remember to change folder name to
src/main/resources/archetype-resources/src/main/resources/sql/__appName__/DemoUser.xml
因此,当您现在执行mvn archetype:generate ... -DartifactId=foo.bar ...
时,您将获得
So when you execute mvn archetype:generate ... -DartifactId=foo.bar ...
now, you could get
│ └── resources
│ └── sql
│ └── bar
│ └── DemoUser.xml
参考文档: http://maven.apache .org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html
这篇关于使用Maven原型创建新项目如何指定自定义文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!