黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

Maven 項(xiàng)目模板

maven 項(xiàng)目模板

maven 使用 archetype(原型) 來(lái)創(chuàng)建自定義的項(xiàng)目結(jié)構(gòu),形成 maven 項(xiàng)目模板。

maven 使用下面的命令來(lái)快速創(chuàng)建 java 項(xiàng)目:

mvn archetype:generate

 

1. 什么是 archetype

archetype 也就是原型,是一個(gè) maven 插件,準(zhǔn)確說(shuō)是一個(gè)項(xiàng)目模板,它的任務(wù)是根據(jù)模板創(chuàng)建一個(gè)項(xiàng)目結(jié)構(gòu)。我們將使用 quickstart 原型插件創(chuàng)建一個(gè)簡(jiǎn)單的 java 應(yīng)用程序。

 

2. 使用項(xiàng)目模板

讓我們打開(kāi)命令控制臺(tái),跳轉(zhuǎn)到 c:\> mvn 目錄并執(zhí)行以下 mvn 命令:

c:\mvn> mvn archetype:generate 

maven 將開(kāi)始處理,并要求選擇所需的原型:

[info] scanning for projects...
[info] searching repository for plugin with prefix: 'archetype'.
[info] -------------------------------------------------------------------
[info] building maven default project
[info]task-segment: [archetype:generate] (aggregator-style)
[info] -------------------------------------------------------------------
[info] preparing archetype:generate
...
600: remote -> org.trailsframework:trails-archetype (-)
601: remote -> org.trailsframework:trails-secure-archetype (-)
602: remote -> org.tynamo:tynamo-archetype (-)
603: remote -> org.wicketstuff.scala:wicket-scala-archetype (-)
604: remote -> org.wicketstuff.scala:wicketstuff-scala-archetype 
basic setup for a project that combines scala and wicket,
depending on the wicket-scala project. 
includes an example specs test.)
605: remote -> org.wikbook:wikbook.archetype (-)
606: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-glassfish (-)
607: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-spring (-)
608: remote -> org.xwiki.commons:xwiki-commons-component-archetype 
(make it easy to create a maven project for creating xwiki components.)
609: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro 
(make it easy to create a maven project for creating xwiki rendering macros.)
610: remote -> org.zkoss:zk-archetype-component (the zk component archetype)
611: remote -> org.zkoss:zk-archetype-webapp (the zk wepapp archetype)
612: remote -> ru.circumflex:circumflex-archetype (-)
613: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)
614: remote -> sk.seges.sesam:sesam-annotation-archetype (-)
choose a number or apply filter 
(format: [groupid:]artifactid, case sensitive contains): 203:

按下 enter 選擇默認(rèn)選項(xiàng) (203:maven-archetype-quickstart)。

 

3. maven 將詢問(wèn)原型的版本

choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
choose a number: 6:

按下 enter 選擇默認(rèn)選項(xiàng) (6:maven-archetype-quickstart:1.1)

maven 將詢問(wèn)項(xiàng)目細(xì)節(jié)。按要求輸入項(xiàng)目細(xì)節(jié)。如果要使用默認(rèn)值則直接按 enter 鍵。你也可以輸入自己的值。

define value for property 'groupid': : com.companyname.insurance
define value for property 'artifactid': : health
define value for property 'version': 1.0-snapshot
define value for property 'package': com.companyname.insurance

maven 將要求確認(rèn)項(xiàng)目細(xì)節(jié),按 enter 或按 y

confirm properties configuration:
groupid: com.companyname.insurance
artifactid: health
version: 1.0-snapshot
package: com.companyname.insurance
y:

現(xiàn)在 maven 將開(kāi)始創(chuàng)建項(xiàng)目結(jié)構(gòu),顯示如下:

[info] -----------------------------------------------------------------------
[info] using following parameters for creating project 
from old (1.x) archetype: maven-archetype-quickstart:1.1
[info] -----------------------------------------------------------------------
[info] parameter: groupid, value: com.companyname.insurance
[info] parameter: packagename, value: com.companyname.insurance
[info] parameter: package, value: com.companyname.insurance
[info] parameter: artifactid, value: health
[info] parameter: basedir, value: c:\mvn
[info] parameter: version, value: 1.0-snapshot
[info] project created from old (1.x) archetype in dir: c:\mvn\health
[info] -----------------------------------------------------------------------
[info] build successful
[info] -----------------------------------------------------------------------
[info] total time: 4 minutes 12 seconds
[info] finished at: fri jul 13 11:10:12 ist 2012
[info] final memory: 20m/90m
[info] -----------------------------------------------------------------------

 

4. 創(chuàng)建的項(xiàng)目

現(xiàn)在轉(zhuǎn)到 c:\ > mvn 目錄。你會(huì)看到一個(gè)名為 health 的 java 應(yīng)用程序項(xiàng)目,就像在項(xiàng)目創(chuàng)建的時(shí)候建立的 artifactid 名稱一樣。 maven 將創(chuàng)建一個(gè)有標(biāo)準(zhǔn)目錄布局的項(xiàng)目,如下所示:

 

5. 創(chuàng)建 pom.xml

maven 為項(xiàng)目自動(dòng)生成一個(gè) 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.companyname.insurance</groupid>
  <artifactid>health</artifactid>
  <version>1.0-snapshot</version>
  <packaging>jar</packaging>
  <name>health</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>

 

6. app.java

maven 會(huì)自動(dòng)生成一個(gè)測(cè)試的 java 文件 app.java。

路徑:c:\mvn\consumerbanking\src\main\java\com\companyname\bank

package com.companyname.insurance;
 
/**
* hello world!
*
*/
public class app 
{
    public static void main( string[] args )
    {
        system.out.println( "hello world!" );
    }
}

 

7. apptest.java

maven 會(huì)自動(dòng)生成一個(gè) java 文件 apptest.java。

路徑為: c:\mvn\consumerbanking\src\test\java\com\companyname\bank

package com.companyname.insurance;
 
import junit.framework.test;
import junit.framework.testcase;
import junit.framework.testsuite;
 
/**
* unit test for simple app.
*/
public class apptest 
   extends testcase
{
   /**
   * create the test case
   *
   * @param testname name of the test case
   */
  public apptest( string testname )
  {
      super( testname );
  }
 
  /**
  * @return the suite of tests being tested
  */
  public static test suite()
  {
      return new testsuite( apptest.class );
  }
 
  /**
  * rigourous test :-)
  */
  public void testapp()
  {
      asserttrue( true );
  }
}

就這樣?,F(xiàn)在你可以看到 maven 的強(qiáng)大之處。你可以用 maven 簡(jiǎn)單的命令創(chuàng)建任何類型的項(xiàng)目,并且可以啟動(dòng)您的開(kāi)發(fā)。

下一節(jié):maven 項(xiàng)目文檔

maven 教程

相關(guān)文章