天天看點

Maven 三種archetype說明

建立Maven project項目時,需要選擇archetype。

那麼,什麼是archetype?

archetype的意思就是模闆原型的意思,原型是一個Maven項目模闆工具包。一個原型被定義為從其中相同類型的所有其它事情是由一個原始圖案或模型。名稱配合,因為我們正在努力提供一種系統,該系統提供了一種生成Maven項目的一緻的手段。原型将幫助作者為使用者建立Maven項目模闆,并為使用者提供了手段,産生的這些項目模闆參數化的版本。

建立Maven項目時,網上建議的分别是

1、cocoon-22-archetype-webapp

2、maven-archetype-quickstart

3、maven-archetype-webapp

那麼為什麼是這三種模闆呢?這三種模闆分别代表什麼意思呢?

1、cocoon-22-archetype-webapp

建好項目後,項目的結構如下:

Maven 三種archetype說明

可以看到,這個項目結構裡包含了applicationContext.xml、log4j.xml、web.xml

pom.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<!-- $Id: pom.xml 642118 2008-03-28 08:04:16Z reinhard $ -->
<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>
  <packaging>war</packaging>

  <name>springboot-cocoon</name>
  <groupId>com.study.cx</groupId>
  <artifactId>springboot-cocoon</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.7</version>
        <configuration>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8888</port>
              <maxIdleTime>30000</maxIdleTime>
            </connector>
          </connectors>
          <webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}</webAppSourceDirectory>
          <contextPath>/</contextPath>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!--dependency>
      <groupId>com.study.cx</groupId>
      <artifactId>[the artifact id of the block to be mounted]</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency-->
  </dependencies>

</project>
           

2、 maven-archetype-quickstart

建好項目後,項目的結構如下:

Maven 三種archetype說明

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

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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.study.cx</groupId>
  <artifactId>springboot-quickstart</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>springboot-quickstart</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
           

3、 maven-archetype-webapp

建好項目後,項目的結構如下:

Maven 三種archetype說明

在這個項目裡,有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)