使用Maven原型创建新项目如何指定自定义文件夹名称 [英] create new project using maven archetype how to specify custom folder name

查看:405
本文介绍了使用Maven原型创建新项目如何指定自定义文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在尝试创建一个使用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原型创建新项目如何指定自定义文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆