关于maven:第十一篇-Maven-项目模板之Spring-Cloud直播商城-b2b2c电子商务技术总结

79次阅读

共计 5188 个字符,预计需要花费 13 分钟才能阅读完成。

Maven 我的项目模板
Maven 应用 archetype(原型) 来创立自定义的我的项目构造,造成 Maven 我的项目模板。

在后面章节咱们学到 Maven 应用上面的命令来疾速创立 java 我的项目:
mvn archetype:generate
什么是 archetype?
archetype 也就是原型,是一个 Maven 插件,精确说是一个我的项目模板,它的工作是依据模板创立一个我的项目构造。咱们将应用 quickstart 原型插件创立一个简略的 java 应用程序。

应用我的项目模板
让咱们关上命令控制台,跳转到 C:\> MVN 目录并执行以下 mvn 命令:
C:\MVN> mvn archetype:generate
Maven 将开始解决,并要求抉择所需的原型:

[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 抉择默认选项 (203:maven-archetype-quickstart)。
Maven 将询问原型的版本

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 抉择默认选项 (6:maven-archetype-quickstart:1.1)

Maven 将询问我的项目细节。按要求输出我的项目细节。如果要应用默认值则间接按 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 将要求确认我的项目细节,按 Enter 或按 Y

Confirm properties configuration:
groupId: com.companyname.insurance
artifactId: health
version: 1.0-SNAPSHOT
package: com.companyname.insurance
Y:

当初 Maven 将开始创立我的项目构造,显示如下:

[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] -----------------------------------------------------------------------

创立的我的项目
当初转到 C:\ > MVN 目录。你会看到一个名为 health 的 java 应用程序我的项目,就像在我的项目创立的时候建设的 artifactId 名称一样。Maven 将创立一个有规范目录布局的我的项目,如下所示:创立 pom.xml
Maven 为我的项目主动生成一个 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>

App.java
Maven 会主动生成一个测试的 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!");
    }
}

AppTest.java
Maven 会主动生成一个 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);
  }
}

就这样。当初你能够看到 Maven 的弱小之处。你能够用 maven 简略的命令创立任何类型的我的项目,并且能够启动您的开发。

正文完
 0