maven自定义模板archetype

最近做springcloud项目,需要用maven项目管理springboot,eclipse自带的maven模板又贼鸡儿蠢,于是就想自己搞个模板。

网上文章很多,这篇写的挺合我心意  ——  maven:从一个已有项目生成一个archetype(未完成)

一.添加maven-archetype-plugin

    在模板maven项目的pom.xml里加入插件maven-archetype-plugin

<build>
	<finalName>spring-template</finalName>
	<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<fork>true</fork>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-archetype-plugin</artifactId>
				<version>2.2</version>
			</plugin>
	</plugins>
</build>

二.mvn archetype:create-from-project

    这个命令如果直接用eclipse——run as执行,会有问题

        

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project spring-template: ${maven.home} is not specified as a directory: 'E:\eclipse_study_workspace\iot-server\spring-template\EMBEDDED'. -> [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/MojoFailureException

 原因是eclipse自带的maven有问题,需要用下载的maven包中的mvn.bat命令,如果bin目录下没有mvn.bat,则复制mvn.cmd改成mvn.bat!

 进入cmd界面,cd到项目路径下,输入mvn archetype:create-from-project,执行即可。target目录下会生成generated-sources文件夹。

三.安装到本地库

  cd 到generated-sources/archetype文件夹下,输入mvn install(将项目保存到本地库中,方便其他项目调用),这样模板就保存到了maven本地库里。

四.更新本地仓库索引  mvn archetype:update-local-catalog

五.使用模板

                       

    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值