zno2

6) mvn archetype:create-from-project

cd %old%
mvn archetype:create-from-project
cd %old%/target/generated-sources/archetype 
mvn install
cd %newParent%

mvn archetype:generate -DarchetypeCatalog=local 

 

步骤:
生成原型
安装到本地
使用本地该原型
位置 ~\.m2\repository\cn\zxg\struts-hello-archetype\1.0\struts-hello-archetype-1.0.jar

 

http://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html

 

补充 2020-12-23:

 

 

http://maven.apache.org/archetype/maven-archetype-plugin/index.html

http://maven.apache.org/plugins-archives/maven-help-plugin-2.1.1/usage.html

 

1. 如何快速定位电脑仓库位置?

答:需要用的help plugin ,执行 mvn help:effective-settings

<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">D:\mvnrepository</localRepository>
  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <pluginGroup>org.apache.maven.plugins</pluginGroup>
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
</settings>

 

2. 如何通过Eclipse 快速根据archetype 创建项目?

答:需要用到 archetype 插件,执行 mvn archetype:crawl   会在localRepository 目录下生成一个  archetype-catalog.xml 

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <archetypes>
    ...
    <archetype>
      <groupId>cn.zno</groupId>
      <artifactId>minidemo-archetype</artifactId>
      <version>1.0-SNAPSHOT</version>
      <description>minidemo</description>
    </archetype>
   ...
  </archetypes>
</archetype-catalog>

然后

Window - Preferences - Maven - Archetypes - Add local catalog - Browse - "选择 archetype-catalog.xml 文件" - ok

然后

new - maven project - Next(don't check "create a simple project") - 下拉框选择刚刚配置的catalog(please check "Include snapshot archetypes" and filter which you want) - Next - ...

 

posted on 2016-08-02 22:12  zno2  阅读(464)  评论(0编辑  收藏  举报

导航