Maven 三種archetype(模板原型)說明

新建Maven project項目時,須要選擇archetype。html

那麼,什麼是archetype?java

archetype的意思就是模板原型的意思,原型是一個Maven項目模板工具包。一個原型被定義爲從其中相同類型的全部其它事情是由一個原始圖案或模型。名稱配合,由於咱們正在努力提供一種系統,該系統提供了一種生成Maven項目的一致的手段。原型將幫助做者爲用戶建立Maven項目模板,併爲用戶提供了手段,產生的這些項目模板參數化的版本。web

 

創建Maven項目時,網上建議的分別是 spring

一、cocoon-22-archetype-webappexpress

二、maven-archetype-quickstartapache

三、maven-archetype-webappspringboot

那麼爲何是這三種模板呢?這三種模板分別表明什麼意思呢?app

 

一、cocoon-22-archetype-webappless

建好項目後,項目的結構以下:webapp

 

 

能夠看到,這個項目結構裏包含了applicationContext.xml、log4j.xml、web.xml

pom.xml的內容以下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!--
 3  Licensed to the Apache Software Foundation (ASF) under one  4  or more contributor license agreements. See the NOTICE file  5   distributed with this work for additional information  6   regarding copyright ownership.  The ASF licenses this file  7   to you under the Apache License, Version 2.0 (the  8   "License"); you may not use this file except in compliance  9  with the License. You may obtain a copy of the License at 10    http://www.apache.org/licenses/LICENSE-2.0
11  Unless required by applicable law or agreed to in writing, 12  software distributed under the License is distributed on an 13   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14   KIND, either express or implied.  See the License for the 15  specific language governing permissions and limitations 16  under the License. 17 -->
18 <!-- $Id: pom.xml 642118 2008-03-28 08:04:16Z reinhard $ -->
19 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20  
21   <modelVersion>4.0.0</modelVersion>
22   <packaging>war</packaging>
23  
24   <name>springboot-cocoon</name>
25   <groupId>com.study.cx</groupId>
26   <artifactId>springboot-cocoon</artifactId>
27   <version>0.0.1-SNAPSHOT</version>
28  
29   <build>
30     <plugins>
31       <plugin>
32         <groupId>org.mortbay.jetty</groupId>
33         <artifactId>maven-jetty-plugin</artifactId>
34         <version>6.1.7</version>
35         <configuration>
36           <connectors>
37             <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
38               <port>8888</port>
39               <maxIdleTime>30000</maxIdleTime>
40             </connector>
41           </connectors>
42           <webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}</webAppSourceDirectory>
43           <contextPath>/</contextPath>
44         </configuration>
45       </plugin>
46     </plugins>
47   </build>
48  
49   <dependencies>
50     <!--dependency>
51       <groupId>com.study.cx</groupId>
52       <artifactId>[the artifact id of the block to be mounted]</artifactId>
53       <version>0.0.1-SNAPSHOT</version>
54     </dependency-->
55   </dependencies>
56  
57 </project>

 



二、maven-archetype-quickstart
建好項目後,項目的結構以下:

 

 

在這個項目裏,除了pom.xml外,沒有其餘的xml了,可是有main、test兩個包,包裏放了一個App、AppTest類

pom.xml的內容以下:

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 3   <modelVersion>4.0.0</modelVersion>
 4  
 5   <groupId>com.study.cx</groupId>
 6   <artifactId>springboot-quickstart</artifactId>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <packaging>jar</packaging>
 9  
10   <name>springboot-quickstart</name>
11   <url>http://maven.apache.org</url>
12  
13   <properties>
14     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15   </properties>
16  
17   <dependencies>
18     <dependency>
19       <groupId>junit</groupId>
20       <artifactId>junit</artifactId>
21       <version>3.8.1</version>
22       <scope>test</scope>
23     </dependency>
24   </dependencies>
25 </project>

 

三、maven-archetype-webapp
建好項目後,項目的結構以下:

 


在這個項目裏,有WEB-INF目錄,而且有web.xml和一個index.jsp

pom.xml的內容以下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.study.cx</groupId>
  <artifactId>srpingboot-mavenWebapp</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>srpingboot-mavenWebapp Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>srpingboot-mavenWebapp</finalName>
  </build>
</project>

  

 

 


maven提供的41個骨架原型分別是:

1: appfuse-basic-jsf (建立一個基於Hibernate,Spring和JSF的Web應用程序的原型) 
2: appfuse-basic-spring(建立一個基於Hibernate,Spring和Spring MVC的Web應用程序的原型) 
3: appfuse-basic-struts(建立一個基於Hibernate,Spring和Struts 2的Web應用程序的原型) 
4: appfuse-basic-tapestry(建立一個基於Hibernate,Spring 和 Tapestry 4的Web應用程序的原型) 
5: appfuse-core(建立一個基於Hibernate,Spring 和 XFire的jar應用程序的原型) 
6: appfuse-modular-jsf(建立一個基於Hibernate,Spring和JSF的模塊化應用原型) 
7: appfuse-modular-spring(建立一個基於Hibernate, Spring 和 Spring MVC 的模塊化應用原型) 
8: appfuse-modular-struts(建立一個基於Hibernate, Spring 和 Struts 2 的模塊化應用原型) 
9: appfuse-modular-tapestry (建立一個基於 Hibernate, Spring 和 Tapestry 4 的模塊化應用原型) 
10: maven-archetype-j2ee-simple(一個簡單的J2EE的Java應用程序) 
11: maven-archetype-marmalade-mojo(一個Maven的 插件開發項目 using marmalade) 
12: maven-archetype-mojo(一個Maven的Java插件開發項目) 
13: maven-archetype-portlet(一個簡單的portlet應用程序) 
14: maven-archetype-profiles() 
15:maven-archetype-quickstart() 
16: maven-archetype-site-simple(簡單的網站生成項目) 
17: maven-archetype-site(更復雜的網站項目) 
18:maven-archetype-webapp(一個簡單的Java Web應用程序) 
19: jini-service-archetype(Archetype for Jini service project creation) 
20: softeu-archetype-seam(JSF+Facelets+Seam Archetype) 
21: softeu-archetype-seam-simple(JSF+Facelets+Seam (無殘留) 原型) 
22: softeu-archetype-jsf(JSF+Facelets 原型) 
23: jpa-maven-archetype(JPA 應用程序) 
24: spring-osgi-bundle-archetype(Spring-OSGi 原型) 
25: confluence-plugin-archetype(Atlassian 聚合插件原型) 
26: jira-plugin-archetype(Atlassian JIRA 插件原型) 
27: maven-archetype-har(Hibernate 存檔) 
28: maven-archetype-sar(JBoss 服務存檔) 
29: wicket-archetype-quickstart(一個簡單的Apache Wicket的項目) 
30: scala-archetype-simple(一個簡單的scala的項目) 
31: lift-archetype-blank(一個 blank/empty liftweb 項目) 
32: lift-archetype-basic(基本(liftweb)項目) 
33: cocoon-22-archetype-block-plain([http://cocoapacorg2/maven-plugins/]) 
34: cocoon-22-archetype-block([http://cocoapacorg2/maven-plugins/]) 
35:cocoon-22-archetype-webapp([http://cocoapacorg2/maven-plugins/]) 
36: myfaces-archetype-helloworld(使用MyFaces的一個簡單的原型) 
37: myfaces-archetype-helloworld-facelets(一個使用MyFaces和Facelets的簡單原型) 
38: myfaces-archetype-trinidad(一個使用MyFaces和Trinidad的簡單原型) 
39: myfaces-archetype-jsfcomponents(一種使用MyFaces建立定製JSF組件的簡單的原型) 
40: gmaven-archetype-basic(Groovy的基本原型) 
41: gmaven-archetype-mojo(Groovy mojo 原型)

(41中骨架原文連接:http://www.cnblogs.com/iusmile/archive/2012/11/14/2770118.html)

相關文章
相關標籤/搜索