使用Maven Archetype插件构建Maven工程原型模板的实例
程序员文章站
2024-02-25 08:37:46
创建原型模板
1、在空目录运行archetype:generate上面的命令,待下载完必要的jar包后,首先需要输入内置的原型编号;
choose archet...
创建原型模板
1、在空目录运行archetype:generate上面的命令,待下载完必要的jar包后,首先需要输入内置的原型编号;
choose archetype: 1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (an archetype which contains a sample archetype.) 2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (an archetype which contains a simplifed sample j2ee application.) 3: internal -> org.apache.maven.archetypes:maven-archetype-plugin (an archetype which contains a sample maven plugin.) 4: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (an archetype which contains a sample maven plugin site. this archetype can be layered upon an existing maven plugin project.) 5: internal -> org.apache.maven.archetypes:maven-archetype-portlet (an archetype which contains a sample jsr-268 portlet.) 6: internal -> org.apache.maven.archetypes:maven-archetype-profiles () 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (an archetype which contains a sample maven project.) 8: internal -> org.apache.maven.archetypes:maven-archetype-site (an archetype which contains a sample maven site which demonstrates some of the supported document types like apt, xdoc, and fml and demonstrates how to i18n your site. this archetype can be layered upon an existing maven project.) 9: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (an archetype which contains a sample maven site.) 10: internal -> org.apache.maven.archetypes:maven-archetype-webapp (an archetype which contains a sample maven webapp project.) choose a number or apply filter (format: [groupid:]artifactid, case sensitive contains): 7:
2、输入任意编号后,继续下载必要jar包,之后要求分别输入groupid,artifactid,version,package,并确认
define value for property 'groupid': com.aaa define value for property 'artifactid': bbb define value for property 'version' 1.0-snapshot: : 1.0 define value for property 'package' com.aaa: : project y: : [info] ---------------------------------------------------------------------------- [info] using following parameters for creating project from old (1.x) archetype: maven-archetype-archetype:1.0 [info] ---------------------------------------------------------------------------- [info] parameter: basedir, value: e:\code\test [info] parameter: package, value: project [info] parameter: groupid, value: com.aaa [info] parameter: artifactid, value: bbb [info] parameter: packagename, value: project [info] parameter: version, value: 1.0 [info] project created from old (1.x) archetype in dir: e:\code\test\bbb [info] ------------------------------------------------------------------------ [info] build success [info] ------------------------------------------------------------------------ [info] total time: 11:12 min [info] finished at: 2017-12-02t22:00:49+08:00 [info] final memory: 17m/58m [info] ------------------------------------------------------------------------
3、浏览maven工程
|-- pom.xml `-- src |-- main | `-- java | `-- com | `-- aaa | `-- bbb | `-- app.java `-- test `-- java `-- com `-- aaa `-- bbb `-- apptest.java
4、内置原型过多时,可以使用-dfilter命令过滤
mvn archetype:generate -dfilter=j2ee
5、在maven工程的pom.xml目录运行mvn archetype:create-from-project, 将会在target/generated-sources/archetype目录下生成原型工程目录
6、在原型工程pom.xml文件下,执行mvn install来把原型jar包上传到本地仓库
7、这时的原型就可以使用了,在空目录执行mvn archetype:generate -darchetypecatalog=local
mvn archetype:generate -darchetypecatalog=local [info] scanning for projects... [info] [info] ------------------------------------------------------------------------ [info] building maven stub project (no pom) 1 [info] ------------------------------------------------------------------------ [info] [info] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>> [info] [info] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<< [info] [info] [info] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom --- [info] generating project in interactive mode [info] no archetype defined. using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) choose archetype: 1: local -> com.aaa:bbb-archetype (bbb-archetype) choose a number or apply filter (format: [groupid:]artifactid, case sensitive contains): :
接下来就和第一步一样的流程了。
以上这篇使用maven archetype插件构建maven工程原型模板的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。