欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

使用Maven Archetype插件构建Maven工程原型模板的实例

时间:2020-10-12 19:23:07|栏目:JAVA代码|点击:

创建原型模板

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): :

接下来就和第一步一样的流程了。

上一篇:Java实现操作JSON的便捷工具类完整实例【重写Google的Gson】

栏    目:JAVA代码

下一篇:JAVA获取rabbitmq消息总数过程详解

本文标题:使用Maven Archetype插件构建Maven工程原型模板的实例

本文地址:http://www.codeinn.net/misctech/10434.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有