zoukankan      html  css  js  c++  java
  • Maven的第一个小程序

    这里是介绍关于maven的第一个小程序

    关于maven的安装 : Install Maven in your computer

    先看看目录结构:

    这是本来的项目目录结构,由于maven有自己的目录结构,所以,下面的是加入maven元素后的目录结构:

    即:

    pom.xml文件要和src目录在同一级

    在src目录下面,分别为main目录和test目录

    在main目录下面存放项目中的模块类,如这里的com.b510.maven.hello.Hello.java

    在test目录下面存放项目模块的测试类,如这里的com.b510.maven.hello.test.HelloTest.java

    NOTE:

    你所看到的有红色X标示错误提示,这是在Eclipse中的提示,这个可以不用理会。

    接下来才是关键:

    /maven_project/pom.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     4     <modelVersion>4.0.0</modelVersion>
     5 
     6     <groupId>com.b510.maven.hello</groupId>
     7     <artifactId>hello-first</artifactId>
     8     <version>SNAPSHOT-0.0.1</version>
     9     
    10     <dependencies>
    11         <dependency>
    12             <groupId>junit</groupId>
    13             <artifactId>junit</artifactId>    
    14             <version>4.10</version>
    15             <scope>test</scope>
    16         </dependency>
    17     </dependencies>
    18 </project>

    pom.xml文件,是project object manager的首字母缩写。即项目对象管理。

    在pom.xml文件中,对于我们写的com.b510.maven.hello.Hello.java类,他的groupId = com.b510.maven.hello, artifactId = hello-first, version = SNAPSHOT-0.0.1

    而我们的测试类,所依赖的包为junit,它属于test域。

    下面是Hello类和HelloTest类

    /maven_project/src/com/b510/maven/hello/Hello.java

     1 /**
     2  * 
     3  */
     4 package com.b510.maven.hello;
     5 
     6 /**
     7  * @author Hongten
     8  * @created 2014-7-5
     9  */
    10 public class Hello {
    11 
    12     public static void main(String[] args) {
    13         System.out.println("This is a test message!");
    14         String str = new Hello().sayHello("Hongten", 20);
    15         System.out.println(str);
    16     }
    17     
    18     public String sayHello(String name, int age){
    19         return "I'm " + name + ", I'm " + age + ", Hello";
    20     }
    21 }

    /maven_project/src/com/b510/maven/hello/test/HelloTest.java

     1 /**
     2  * 
     3  */
     4 package com.b510.maven.hello.test;
     5 
     6 import static org.junit.Assert.*;
     7 
     8 import org.junit.Test;
     9 
    10 import com.b510.maven.hello.Hello;
    11 
    12 /**
    13  * @author Hongten
    14  * @created 2014-7-5
    15  */
    16 public class HelloTest {
    17 
    18     @Test
    19     public void testSayHello() {
    20         Hello hello = new Hello();
    21         assertEquals(hello.sayHello("Hongten", 20), "I'm Hongten, I'm 20, Hello");
    22     }
    23 
    24 }

    两个类都是很简单的类。

    现在我们启动windows的控制台。即运行--> cmd,或Ctrl+R --> cmd

    进入到项目的根目录:D:Developmentworkspacemaven_project  

    1.运行命令:mvn compile

    由于我们本地仓库中没有编译所需要的资源,所有,maven会到远程仓库中去获取资源到本地

    下面是控制台运行效果:这里只是截取了部分log

      1 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-p
      2 arameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6.pom
      3 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-pa
      4 rameter-documenter/2.0.6/maven-plugin-parameter-documenter-2.0.6.pom (2 KB at 3.
      5 8 KB/sec)
      6 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
      7 n-reporting-api/2.0.6/maven-reporting-api-2.0.6.pom
      8 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
      9 -reporting-api/2.0.6/maven-reporting-api-2.0.6.pom (2 KB at 3.8 KB/sec)
     10 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
     11 n-reporting/2.0.6/maven-reporting-2.0.6.pom
     12 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
     13 -reporting/2.0.6/maven-reporting-2.0.6.pom (2 KB at 3.2 KB/sec)
     14 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
     15 nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.pom
     16 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-sin
     17 k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.pom (424 B at 0.9 KB/sec)
     18 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia/1.
     19 0-alpha-7/doxia-1.0-alpha-7.pom
     20 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia/1.0
     21 -alpha-7/doxia-1.0-alpha-7.pom (4 KB at 8.4 KB/sec)
     22 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-di
     23 agnostics/2.0.6/maven-error-diagnostics-2.0.6.pom
     24 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-dia
     25 gnostics/2.0.6/maven-error-diagnostics-2.0.6.pom (2 KB at 3.3 KB/sec)
     26 Downloading: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/com
     27 mons-cli-1.0.pom
     28 Downloaded: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/comm
     29 ons-cli-1.0.pom (3 KB at 4.4 KB/sec)
     30 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-d
     31 escriptor/2.0.6/maven-plugin-descriptor-2.0.6.pom
     32 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-de
     33 scriptor/2.0.6/maven-plugin-descriptor-2.0.6.pom (2 KB at 4.0 KB/sec)
     34 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
     35 ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.pom
     36 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
     37 activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.pom (7 KB at 13.6
     38 KB/sec)
     39 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/
     40 2.0.6/maven-monitor-2.0.6.pom
     41 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/2
     42 .0.6/maven-monitor-2.0.6.pom (2 KB at 2.4 KB/sec)
     43 Downloading: http://repo.maven.apache.org/maven2/classworlds/classworlds/1.1/cla
     44 ssworlds-1.1.pom
     45 Downloaded: http://repo.maven.apache.org/maven2/classworlds/classworlds/1.1/clas
     46 sworlds-1.1.pom (4 KB at 6.7 KB/sec)
     47 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     48 s/2.0.5/plexus-utils-2.0.5.pom
     49 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     50 /2.0.5/plexus-utils-2.0.5.pom (4 KB at 6.6 KB/sec)
     51 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
     52 6/plexus-2.0.6.pom
     53 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.6
     54 /plexus-2.0.6.pom (17 KB at 21.9 KB/sec)
     55 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-f
     56 iltering/1.1/maven-filtering-1.1.pom
     57 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-fi
     58 ltering/1.1/maven-filtering-1.1.pom (6 KB at 11.5 KB/sec)
     59 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
     60 hared-components/17/maven-shared-components-17.pom
     61 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-sh
     62 ared-components/17/maven-shared-components-17.pom (9 KB at 15.3 KB/sec)
     63 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     64 s/1.5.15/plexus-utils-1.5.15.pom
     65 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     66 /1.5.15/plexus-utils-1.5.15.pom (7 KB at 8.1 KB/sec)
     67 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
     68 2/plexus-2.0.2.pom
     69 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.2
     70 /plexus-2.0.2.pom (12 KB at 13.9 KB/sec)
     71 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
     72 rpolation/1.12/plexus-interpolation-1.12.pom
     73 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
     74 polation/1.12/plexus-interpolation-1.12.pom (889 B at 1.5 KB/sec)
     75 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
     76 onents/1.1.14/plexus-components-1.1.14.pom
     77 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
     78 nents/1.1.14/plexus-components-1.1.14.pom (6 KB at 10.1 KB/sec)
     79 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-buil
     80 d-api/0.0.4/plexus-build-api-0.0.4.pom
     81 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-build
     82 -api/0.0.4/plexus-build-api-0.0.4.pom (3 KB at 4.7 KB/sec)
     83 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
     84 /10/spice-parent-10.pom
     85 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
     86 10/spice-parent-10.pom (3 KB at 5.3 KB/sec)
     87 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
     88 /3/forge-parent-3.pom
     89 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
     90 3/forge-parent-3.pom (5 KB at 8.6 KB/sec)
     91 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     92 s/1.5.8/plexus-utils-1.5.8.pom
     93 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     94 /1.5.8/plexus-utils-1.5.8.pom (8 KB at 13.4 KB/sec)
     95 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
     96 rpolation/1.13/plexus-interpolation-1.13.pom
     97 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
     98 polation/1.13/plexus-interpolation-1.13.pom (890 B at 1.4 KB/sec)
     99 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    100 onents/1.1.15/plexus-components-1.1.15.pom
    101 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
    102 nents/1.1.15/plexus-components-1.1.15.pom (3 KB at 4.2 KB/sec)
    103 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.
    104 3/plexus-2.0.3.pom
    105 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/2.0.3
    106 /plexus-2.0.3.pom (16 KB at 17.3 KB/sec)
    107 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
    108 nk-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
    109 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
    110 ractivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
    111 Downloading: http://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.j
    112 ar
    113 Downloading: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/com
    114 mons-cli-1.0.jar
    115 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
    116 n-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
    117 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-sin
    118 k-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar (6 KB at 10.5 KB/sec)
    119 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
    120 s/2.0.5/plexus-utils-2.0.5.jar
    121 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
    122 -reporting-api/2.0.6/maven-reporting-api-2.0.6.jar (10 KB at 11.1 KB/sec)
    123 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-f
    124 iltering/1.1/maven-filtering-1.1.jar
    125 Downloaded: http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/comm
    126 ons-cli-1.0.jar (30 KB at 27.5 KB/sec)
    127 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-buil
    128 d-api/0.0.4/plexus-build-api-0.0.4.jar
    129 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
    130 activity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar (14 KB at 10.4
    131  KB/sec)
    132 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
    133 rpolation/1.13/plexus-interpolation-1.13.jar
    134 Downloaded: http://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.ja
    135 r (119 KB at 73.9 KB/sec)
    136 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-build
    137 -api/0.0.4/plexus-build-api-0.0.4.jar (7 KB at 11.8 KB/sec)
    138 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-fi
    139 ltering/1.1/maven-filtering-1.1.jar (43 KB at 38.9 KB/sec)
    140 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
    141 /2.0.5/plexus-utils-2.0.5.jar (218 KB at 91.8 KB/sec)
    142 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
    143 polation/1.13/plexus-interpolation-1.13.jar (60 KB at 28.9 KB/sec)
    144 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
    145 . build is platform dependent!
    146 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
    147 tsrcmain
    esources
    148 [INFO]
    149 [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
    150 --
    151 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-a
    152 pi/2.0.9/maven-plugin-api-2.0.9.pom
    153 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-ap
    154 i/2.0.9/maven-plugin-api-2.0.9.pom (2 KB at 3.1 KB/sec)
    155 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0.9/ma
    156 ven-2.0.9.pom
    157 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven/2.0.9/mav
    158 en-2.0.9.pom (19 KB at 26.6 KB/sec)
    159 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/8
    160 /maven-parent-8.pom
    161 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/8/
    162 maven-parent-8.pom (24 KB at 34.4 KB/sec)
    163 Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/4/apache-4.po
    164 m
    165 Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/4/apache-4.pom
    166  (5 KB at 9.5 KB/sec)
    167 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
    168 /2.0.9/maven-artifact-2.0.9.pom
    169 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/
    170 2.0.9/maven-artifact-2.0.9.pom (2 KB at 3.4 KB/sec)
    171 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
    172 s/1.5.1/plexus-utils-1.5.1.pom
    173 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
    174 /1.5.1/plexus-utils-1.5.1.pom (3 KB at 4.8 KB/sec)
    175 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/2.0
    176 .9/maven-core-2.0.9.pom
    177 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-core/2.0.
    178 9/maven-core-2.0.9.pom (8 KB at 11.0 KB/sec)
    179 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
    180 /2.0.9/maven-settings-2.0.9.pom
    181 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/
    182 2.0.9/maven-settings-2.0.9.pom (3 KB at 4.2 KB/sec)
    183 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.
    184 0.9/maven-model-2.0.9.pom
    185 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.0
    186 .9/maven-model-2.0.9.pom (4 KB at 6.5 KB/sec)
    187 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-p
    188 arameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9.pom
    189 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-pa
    190 rameter-documenter/2.0.9/maven-plugin-parameter-documenter-2.0.9.pom (2 KB at 4.
    191 2 KB/sec)
    192 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
    193 2.0.9/maven-profile-2.0.9.pom
    194 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/2
    195 .0.9/maven-profile-2.0.9.pom (3 KB at 4.2 KB/sec)
    196 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
    197 ry-metadata/2.0.9/maven-repository-metadata-2.0.9.pom
    198 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-repositor
    199 y-metadata/2.0.9/maven-repository-metadata-2.0.9.pom (2 KB at 3.9 KB/sec)
    200 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-di
    201 agnostics/2.0.9/maven-error-diagnostics-2.0.9.pom
    202 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-error-dia
    203 gnostics/2.0.9/maven-error-diagnostics-2.0.9.pom (2 KB at 3.6 KB/sec)
    204 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
    205 2.0.9/maven-project-2.0.9.pom
    206 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-project/2
    207 .0.9/maven-project-2.0.9.pom (3 KB at 5.5 KB/sec)
    208 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
    209 -manager/2.0.9/maven-artifact-manager-2.0.9.pom
    210 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact-
    211 manager/2.0.9/maven-artifact-manager-2.0.9.pom (3 KB at 5.2 KB/sec)
    212 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-r
    213 egistry/2.0.9/maven-plugin-registry-2.0.9.pom
    214 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-re
    215 gistry/2.0.9/maven-plugin-registry-2.0.9.pom (2 KB at 3.8 KB/sec)
    216 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-d
    217 escriptor/2.0.9/maven-plugin-descriptor-2.0.9.pom
    218 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-de
    219 scriptor/2.0.9/maven-plugin-descriptor-2.0.9.pom (3 KB at 3.9 KB/sec)
    220 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/
    221 2.0.9/maven-monitor-2.0.9.pom
    222 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-monitor/2
    223 .0.9/maven-monitor-2.0.9.pom (2 KB at 2.5 KB/sec)
    224 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
    225 n/1.0/maven-toolchain-1.0.pom
    226 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain
    227 /1.0/maven-toolchain-1.0.pom (4 KB at 6.3 KB/sec)
    228 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
    229 s/3.0/plexus-utils-3.0.pom
    230 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
    231 /3.0/plexus-utils-3.0.pom (4 KB at 7.8 KB/sec)
    232 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
    233 /16/spice-parent-16.pom
    234 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
    235 16/spice-parent-16.pom (9 KB at 16.7 KB/sec)
    236 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
    237 /5/forge-parent-5.pom
    238 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
    239 5/forge-parent-5.pom (9 KB at 15.8 KB/sec)
    240 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    241 iler-api/1.9.1/plexus-compiler-api-1.9.1.pom
    242 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    243 ler-api/1.9.1/plexus-compiler-api-1.9.1.pom (867 B at 1.8 KB/sec)
    244 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    245 iler/1.9.1/plexus-compiler-1.9.1.pom
    246 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    247 ler/1.9.1/plexus-compiler-1.9.1.pom (4 KB at 7.8 KB/sec)
    248 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    249 onents/1.1.20/plexus-components-1.1.20.pom
    250 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
    251 nents/1.1.20/plexus-components-1.1.20.pom (3 KB at 6.0 KB/sec)
    252 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/
    253 plexus-3.1.pom
    254 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/p
    255 lexus-3.1.pom (19 KB at 26.7 KB/sec)
    256 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent
    257 /17/spice-parent-17.pom
    258 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/
    259 17/spice-parent-17.pom (7 KB at 13.9 KB/sec)
    260 Downloading: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent
    261 /10/forge-parent-10.pom
    262 Downloaded: http://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/
    263 10/forge-parent-10.pom (14 KB at 19.0 KB/sec)
    264 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    265 iler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom
    266 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    267 ler-manager/1.9.1/plexus-compiler-manager-1.9.1.pom (692 B at 1.3 KB/sec)
    268 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    269 iler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom
    270 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    271 ler-javac/1.9.1/plexus-compiler-javac-1.9.1.pom (688 B at 1.4 KB/sec)
    272 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    273 ilers/1.9.1/plexus-compilers-1.9.1.pom
    274 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    275 lers/1.9.1/plexus-compilers-1.9.1.pom (2 KB at 2.6 KB/sec)
    276 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
    277 s/3.0/plexus-utils-3.0.jar
    278 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    279 iler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar
    280 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    281 iler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar
    282 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
    283 iler-api/1.9.1/plexus-compiler-api-1.9.1.jar
    284 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    285 ler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar (5 KB at 6.3 KB/sec)
    286 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    287 ler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar (14 KB at 15.0 KB/sec)
    288 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compi
    289 ler-api/1.9.1/plexus-compiler-api-1.9.1.jar (21 KB at 22.5 KB/sec)
    290 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
    291 /3.0/plexus-utils-3.0.jar (221 KB at 89.4 KB/sec)
    292 [INFO] Nothing to compile - all classes are up to date
    293 [INFO] ------------------------------------------------------------------------
    294 [INFO] BUILD SUCCESS
    295 [INFO] ------------------------------------------------------------------------
    296 [INFO] Total time: 01:06 min
    297 [INFO] Finished at: 2014-07-06T10:39:32+08:00
    298 [INFO] Final Memory: 3M/7M
    299 [INFO] ------------------------------------------------------------------------
    300 D:Developmentworkspacemaven_project>

    我们看到maven执行了命令,并且从远程仓库下载了资源进行对项目进行编译,最后成功了。

    这些远程资源会下载到我们电脑的:C:UsersAdministrator.m2 epository  目录下面

    然而,当我们的本地仓库中已经有了这些资源,在第二次执行上面的命令的时候,就不会到远程仓库中去获取资源,而是直接到本地仓库中获取。

    下面是再次执行上面的命令:

     1 Microsoft Windows [版本 6.1.7601]
     2 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
     3 
     4 C:UsersAdministrator>D:
     5 
     6 D:>cd D:Developmentworkspacemaven_project
     7 
     8 D:Developmentworkspacemaven_project>mvn compile
     9 [INFO] Scanning for projects...
    10 [INFO]
    11 [INFO] ------------------------------------------------------------------------
    12 [INFO] Building hello-first SNAPSHOT-0.0.1
    13 [INFO] ------------------------------------------------------------------------
    14 [INFO]
    15 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
    16 t ---
    17 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
    18 . build is platform dependent!
    19 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
    20 tsrcmain
    esources
    21 [INFO]
    22 [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
    23 --
    24 [INFO] Nothing to compile - all classes are up to date
    25 [INFO] ------------------------------------------------------------------------
    26 [INFO] BUILD SUCCESS
    27 [INFO] ------------------------------------------------------------------------
    28 [INFO] Total time: 0.699 s
    29 [INFO] Finished at: 2014-07-06T10:45:33+08:00
    30 [INFO] Final Memory: 3M/7M
    31 [INFO] ------------------------------------------------------------------------
    32 D:Developmentworkspacemaven_project>

    2.执行命令:mvn test

      1 D:Developmentworkspacemaven_project>mvn test
      2 [INFO] Scanning for projects...
      3 [INFO]
      4 [INFO] ------------------------------------------------------------------------
      5 [INFO] Building hello-first SNAPSHOT-0.0.1
      6 [INFO] ------------------------------------------------------------------------
      7 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
      8 surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom
      9 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-s
     10 urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom (11 KB at 12.7 KB/sec)
     11 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
     12 ire/2.12.4/surefire-2.12.4.pom
     13 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
     14 re/2.12.4/surefire-2.12.4.pom (14 KB at 29.1 KB/sec)
     15 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     16 surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar
     17 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-s
     18 urefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar (30 KB at 33.1 KB/sec)
     19 Downloading: http://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.jar
     20 
     21 Downloading: http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1/
     22 hamcrest-core-1.1.jar
     23 Downloaded: http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.1/h
     24 amcrest-core-1.1.jar (75 KB at 48.7 KB/sec)
     25 Downloaded: http://repo.maven.apache.org/maven2/junit/junit/4.10/junit-4.10.jar
     26 (248 KB at 114.4 KB/sec)
     27 [INFO]
     28 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
     29 t ---
     30 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     31 . build is platform dependent!
     32 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     33 tsrcmain
    esources
     34 [INFO]
     35 [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
     36 --
     37 [INFO] Nothing to compile - all classes are up to date
     38 [INFO]
     39 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
     40 llo-first ---
     41 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     42 . build is platform dependent!
     43 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     44 tsrc	est
    esources
     45 [INFO]
     46 [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
     47 -first ---
     48 [INFO] Nothing to compile - all classes are up to date
     49 [INFO]
     50 [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
     51 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
     52 ire-booter/2.12.4/surefire-booter-2.12.4.pom
     53 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
     54 re-booter/2.12.4/surefire-booter-2.12.4.pom (3 KB at 6.2 KB/sec)
     55 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
     56 ire-api/2.12.4/surefire-api-2.12.4.pom
     57 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
     58 re-api/2.12.4/surefire-api-2.12.4.pom (3 KB at 5.2 KB/sec)
     59 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven
     60 -surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
     61 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-
     62 surefire-common/2.12.4/maven-surefire-common-2.12.4.pom (6 KB at 11.1 KB/sec)
     63 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
     64 aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
     65 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
     66 ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom (2 KB at 3.4 KB/sec)
     67 
     68 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
     69 aven-plugin-tools/3.1/maven-plugin-tools-3.1.pom
     70 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
     71 ven-plugin-tools/3.1/maven-plugin-tools-3.1.pom (16 KB at 23.3 KB/sec)
     72 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     73 s/3.0.8/plexus-utils-3.0.8.pom
     74 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     75 /3.0.8/plexus-utils-3.0.8.pom (4 KB at 6.6 KB/sec)
     76 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.2/
     77 plexus-3.2.pom
     78 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.2/p
     79 lexus-3.2.pom (19 KB at 25.1 KB/sec)
     80 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
     81 n-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
     82 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
     83 -reporting-api/2.0.9/maven-reporting-api-2.0.9.pom (2 KB at 3.4 KB/sec)
     84 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
     85 n-reporting/2.0.9/maven-reporting-2.0.9.pom
     86 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
     87 -reporting/2.0.9/maven-reporting-2.0.9.pom (2 KB at 3.0 KB/sec)
     88 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchai
     89 n/2.0.9/maven-toolchain-2.0.9.pom
     90 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain
     91 /2.0.9/maven-toolchain-2.0.9.pom (4 KB at 7.0 KB/sec)
     92 Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
     93 3/3.1/commons-lang3-3.1.pom
     94 Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3
     95 /3.1/commons-lang3-3.1.pom (17 KB at 17.9 KB/sec)
     96 Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-pare
     97 nt/22/commons-parent-22.pom
     98 Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-paren
     99 t/22/commons-parent-22.pom (41 KB at 31.6 KB/sec)
    100 Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.po
    101 m
    102 Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom
    103  (15 KB at 29.1 KB/sec)
    104 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
    105 ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom
    106 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-co
    107 mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.pom (4 KB at 7.8 KB/
    108 sec)
    109 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
    110 hared-components/12/maven-shared-components-12.pom
    111 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-sh
    112 ared-components/12/maven-shared-components-12.pom (10 KB at 13.2 KB/sec)
    113 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/1
    114 3/maven-parent-13.pom
    115 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/13
    116 /maven-parent-13.pom (23 KB at 32.1 KB/sec)
    117 Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/6/apache-6.po
    118 m
    119 Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/6/apache-6.pom
    120  (13 KB at 25.5 KB/sec)
    121 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-cont
    122 ainer-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.pom
    123 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-conta
    124 iner-default/1.0-alpha-9/plexus-container-default-1.0-alpha-9.pom (2 KB at 2.6 K
    125 B/sec)
    126 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
    127 ire-booter/2.12.4/surefire-booter-2.12.4.jar
    128 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven
    129 -surefire-common/2.12.4/maven-surefire-common-2.12.4.jar
    130 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
    131 ommon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar
    132 Downloading: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang
    133 3/3.1/commons-lang3-3.1.jar
    134 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
    135 ire-api/2.12.4/surefire-api-2.12.4.jar
    136 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-co
    137 mmon-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar (31 KB at 34.4 K
    138 B/sec)
    139 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
    140 s/3.0.8/plexus-utils-3.0.8.jar
    141 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
    142 re-booter/2.12.4/surefire-booter-2.12.4.jar (34 KB at 31.9 KB/sec)
    143 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
    144 n-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
    145 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
    146 re-api/2.12.4/surefire-api-2.12.4.jar (115 KB at 75.2 KB/sec)
    147 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/m
    148 aven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar
    149 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven
    150 -reporting-api/2.0.9/maven-reporting-api-2.0.9.jar (10 KB at 18.7 KB/sec)
    151 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/ma
    152 ven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar (14 KB at 28.4 KB/se
    153 c)
    154 Downloaded: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3
    155 /3.1/commons-lang3-3.1.jar (309 KB at 145.2 KB/sec)
    156 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-
    157 surefire-common/2.12.4/maven-surefire-common-2.12.4.jar (257 KB at 117.9 KB/sec)
    158 
    159 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
    160 /3.0.8/plexus-utils-3.0.8.jar (227 KB at 116.0 KB/sec)
    161 [INFO] Surefire report directory: D:Developmentworkspacemaven_project	arget
    162 surefire-reports
    163 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
    164 ire-junit4/2.12.4/surefire-junit4-2.12.4.pom
    165 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
    166 re-junit4/2.12.4/surefire-junit4-2.12.4.pom (3 KB at 5.1 KB/sec)
    167 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
    168 ire-providers/2.12.4/surefire-providers-2.12.4.pom
    169 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
    170 re-providers/2.12.4/surefire-providers-2.12.4.pom (3 KB at 4.6 KB/sec)
    171 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/suref
    172 ire-junit4/2.12.4/surefire-junit4-2.12.4.jar
    173 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefi
    174 re-junit4/2.12.4/surefire-junit4-2.12.4.jar (37 KB at 33.0 KB/sec)
    175 
    176 -------------------------------------------------------
    177  T E S T S
    178 -------------------------------------------------------
    179 Running com.b510.maven.hello.test.HelloTest
    180 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec
    181 
    182 Results :
    183 
    184 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    185 
    186 [INFO] ------------------------------------------------------------------------
    187 [INFO] BUILD SUCCESS
    188 [INFO] ------------------------------------------------------------------------
    189 [INFO] Total time: 22.319 s
    190 [INFO] Finished at: 2014-07-06T10:46:53+08:00
    191 [INFO] Final Memory: 4M/8M
    192 [INFO] ------------------------------------------------------------------------
    193 D:Developmentworkspacemaven_project>

    上面是进行测试用例的编译和测试

    下面进行打包操作

    3.执行命令:mvn package

      1 Microsoft Windows [版本 6.1.7601]
      2 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
      3 
      4 C:UsersAdministrator>D:
      5 
      6 D:>cd D:Developmentworkspacemaven_project
      7 
      8 D:Developmentworkspacemaven_project>mvn package
      9 [INFO] Scanning for projects...
     10 [INFO]
     11 [INFO] ------------------------------------------------------------------------
     12 [INFO] Building hello-first SNAPSHOT-0.0.1
     13 [INFO] ------------------------------------------------------------------------
     14 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     15 jar-plugin/2.4/maven-jar-plugin-2.4.pom
     16 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-j
     17 ar-plugin/2.4/maven-jar-plugin-2.4.pom (6 KB at 3.2 KB/sec)
     18 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     19 jar-plugin/2.4/maven-jar-plugin-2.4.jar
     20 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-j
     21 ar-plugin/2.4/maven-jar-plugin-2.4.jar (34 KB at 36.3 KB/sec)
     22 [INFO]
     23 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
     24 t ---
     25 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     26 . build is platform dependent!
     27 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     28 tsrcmain
    esources
     29 [INFO]
     30 [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
     31 --
     32 [INFO] Nothing to compile - all classes are up to date
     33 [INFO]
     34 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
     35 llo-first ---
     36 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     37 . build is platform dependent!
     38 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     39 tsrc	est
    esources
     40 [INFO]
     41 [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
     42 -first ---
     43 [INFO] Nothing to compile - all classes are up to date
     44 [INFO]
     45 [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
     46 [INFO] Surefire report directory: D:Developmentworkspacemaven_project	arget
     47 surefire-reports
     48 
     49 -------------------------------------------------------
     50  T E S T S
     51 -------------------------------------------------------
     52 Running com.b510.maven.hello.test.HelloTest
     53 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 sec
     54 
     55 Results :
     56 
     57 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
     58 
     59 [INFO]
     60 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello-first ---
     61 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
     62 /2.5/maven-archiver-2.5.pom
     63 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/
     64 2.5/maven-archiver-2.5.pom (5 KB at 9.1 KB/sec)
     65 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
     66 iver/2.1/plexus-archiver-2.1.pom
     67 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archi
     68 ver/2.1/plexus-archiver-2.1.pom (3 KB at 5.5 KB/sec)
     69 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
     70 .0.2/plexus-io-2.0.2.pom
     71 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.
     72 0.2/plexus-io-2.0.2.pom (2 KB at 3.5 KB/sec)
     73 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
     74 onents/1.1.19/plexus-components-1.1.19.pom
     75 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
     76 nents/1.1.19/plexus-components-1.1.19.pom (3 KB at 5.1 KB/sec)
     77 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0.
     78 1/plexus-3.0.1.pom
     79 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.0.1
     80 /plexus-3.0.1.pom (19 KB at 34.7 KB/sec)
     81 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
     82 rpolation/1.15/plexus-interpolation-1.15.pom
     83 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
     84 polation/1.15/plexus-interpolation-1.15.pom (1018 B at 2.0 KB/sec)
     85 Downloading: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
     86 ommons-lang-2.1.pom
     87 Downloaded: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/co
     88 mmons-lang-2.1.pom (10 KB at 20.3 KB/sec)
     89 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver
     90 /2.5/maven-archiver-2.5.jar
     91 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
     92 .0.2/plexus-io-2.0.2.jar
     93 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inte
     94 rpolation/1.15/plexus-interpolation-1.15.jar
     95 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
     96 iver/2.1/plexus-archiver-2.1.jar
     97 Downloading: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/c
     98 ommons-lang-2.1.jar
     99 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/
    100 2.5/maven-archiver-2.5.jar (22 KB at 39.7 KB/sec)
    101 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2.
    102 0.2/plexus-io-2.0.2.jar (57 KB at 54.0 KB/sec)
    103 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-inter
    104 polation/1.15/plexus-interpolation-1.15.jar (60 KB at 50.3 KB/sec)
    105 Downloaded: http://repo.maven.apache.org/maven2/commons-lang/commons-lang/2.1/co
    106 mmons-lang-2.1.jar (203 KB at 117.4 KB/sec)
    107 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-archi
    108 ver/2.1/plexus-archiver-2.1.jar (181 KB at 104.1 KB/sec)
    109 [INFO] Building jar: D:Developmentworkspacemaven_project	argethello-first-S
    110 NAPSHOT-0.0.1.jar
    111 [INFO] ------------------------------------------------------------------------
    112 [INFO] BUILD SUCCESS
    113 [INFO] ------------------------------------------------------------------------
    114 [INFO] Total time: 9.989 s
    115 [INFO] Finished at: 2014-07-06T10:49:01+08:00
    116 [INFO] Final Memory: 4M/8M
    117 [INFO] ------------------------------------------------------------------------
    118 D:Developmentworkspacemaven_project>

    执行命令后,我们再来看看项目的结构:

    这时候,我们发现,项目中多了target目录,这是maven生成了目录。

    请注意看:hello-first-SNAPSHOT-0.0.1.jar文件,这个是根据我们在pom.xml中配置的artifactId = hello-first, version = SNAPSHOT-0.0.1所生成的。

    4.执行命令:mvn clean

    即清除掉target目录即target目录下面的所有文件

     1 D:Developmentworkspacemaven_project>mvn clean
     2 [INFO] Scanning for projects...
     3 [INFO]
     4 [INFO] ------------------------------------------------------------------------
     5 [INFO] Building hello-first SNAPSHOT-0.0.1
     6 [INFO] ------------------------------------------------------------------------
     7 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     8 clean-plugin/2.5/maven-clean-plugin-2.5.pom
     9 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-c
    10 lean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 5.0 KB/sec)
    11 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    12 clean-plugin/2.5/maven-clean-plugin-2.5.jar
    13 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-c
    14 lean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 37.2 KB/sec)
    15 [INFO]
    16 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-first ---
    17 [INFO] Deleting D:Developmentworkspacemaven_project	arget
    18 [INFO] ------------------------------------------------------------------------
    19 [INFO] BUILD SUCCESS
    20 [INFO] ------------------------------------------------------------------------
    21 [INFO] Total time: 2.066 s
    22 [INFO] Finished at: 2014-07-06T10:55:13+08:00
    23 [INFO] Final Memory: 2M/5M
    24 [INFO] ------------------------------------------------------------------------
    25 D:Developmentworkspacemaven_project>

    5.命令:mvn install

    是把我们的资源加载到本地仓库中。

      1 Microsoft Windows [版本 6.1.7601]
      2 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
      3 
      4 C:UsersAdministrator>D:
      5 
      6 D:>cd D:Developmentworkspacemaven_project
      7 
      8 D:Developmentworkspacemaven_project>mvn install
      9 [INFO] Scanning for projects...
     10 [INFO]
     11 [INFO] ------------------------------------------------------------------------
     12 [INFO] Building hello-first SNAPSHOT-0.0.1
     13 [INFO] ------------------------------------------------------------------------
     14 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     15 install-plugin/2.4/maven-install-plugin-2.4.pom
     16 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-i
     17 nstall-plugin/2.4/maven-install-plugin-2.4.pom (7 KB at 3.4 KB/sec)
     18 Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
     19 install-plugin/2.4/maven-install-plugin-2.4.jar
     20 Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-i
     21 nstall-plugin/2.4/maven-install-plugin-2.4.jar (27 KB at 37.0 KB/sec)
     22 [INFO]
     23 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-firs
     24 t ---
     25 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     26 . build is platform dependent!
     27 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     28 tsrcmain
    esources
     29 [INFO]
     30 [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hello-first -
     31 --
     32 [WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
     33 d is platform dependent!
     34 [INFO] Compiling 1 source file to D:Developmentworkspacemaven_project	arget
     35 classes
     36 [INFO]
     37 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ he
     38 llo-first ---
     39 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
     40 . build is platform dependent!
     41 [INFO] skip non existing resourceDirectory D:Developmentworkspacemaven_projec
     42 tsrc	est
    esources
     43 [INFO]
     44 [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hello
     45 -first ---
     46 [WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
     47 d is platform dependent!
     48 [INFO] Compiling 1 source file to D:Developmentworkspacemaven_project	arget
     49 test-classes
     50 [INFO]
     51 [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-first ---
     52 [INFO] Surefire report directory: D:Developmentworkspacemaven_project	arget
     53 surefire-reports
     54 
     55 -------------------------------------------------------
     56  T E S T S
     57 -------------------------------------------------------
     58 Running com.b510.maven.hello.test.HelloTest
     59 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 sec
     60 
     61 Results :
     62 
     63 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
     64 
     65 [INFO]
     66 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hello-first ---
     67 [INFO] Building jar: D:Developmentworkspacemaven_project	argethello-first-S
     68 NAPSHOT-0.0.1.jar
     69 [INFO]
     70 [INFO] --- maven-install-plugin:2.4:install (default-install) @ hello-first ---
     71 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     72 s/3.0.5/plexus-utils-3.0.5.pom
     73 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     74 /3.0.5/plexus-utils-3.0.5.pom (3 KB at 5.2 KB/sec)
     75 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-dige
     76 st/1.0/plexus-digest-1.0.pom
     77 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-diges
     78 t/1.0/plexus-digest-1.0.pom (2 KB at 1.8 KB/sec)
     79 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-comp
     80 onents/1.1.7/plexus-components-1.1.7.pom
     81 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compo
     82 nents/1.1.7/plexus-components-1.1.7.pom (5 KB at 10.2 KB/sec)
     83 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.
     84 8/plexus-1.0.8.pom
     85 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8
     86 /plexus-1.0.8.pom (8 KB at 10.1 KB/sec)
     87 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-cont
     88 ainer-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
     89 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-conta
     90 iner-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (8 KB at 15.1
     91 KB/sec)
     92 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
     93 s/3.0.5/plexus-utils-3.0.5.jar
     94 Downloading: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-dige
     95 st/1.0/plexus-digest-1.0.jar
     96 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-diges
     97 t/1.0/plexus-digest-1.0.jar (12 KB at 16.1 KB/sec)
     98 Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils
     99 /3.0.5/plexus-utils-3.0.5.jar (226 KB at 115.9 KB/sec)
    100 [INFO] Installing D:Developmentworkspacemaven_project	argethello-first-SNAP
    101 SHOT-0.0.1.jar to C:UsersAdministrator.m2
    epositorycom510mavenhellohel
    102 lo-firstSNAPSHOT-0.0.1hello-first-SNAPSHOT-0.0.1.jar
    103 [INFO] Installing D:Developmentworkspacemaven_projectpom.xml to C:UsersAdm
    104 inistrator.m2
    epositorycom510mavenhellohello-firstSNAPSHOT-0.0.1hello-
    105 first-SNAPSHOT-0.0.1.pom
    106 [INFO] ------------------------------------------------------------------------
    107 [INFO] BUILD SUCCESS
    108 [INFO] ------------------------------------------------------------------------
    109 [INFO] Total time: 10.014 s
    110 [INFO] Finished at: 2014-07-06T10:57:39+08:00
    111 [INFO] Final Memory: 5M/10M
    112 [INFO] ------------------------------------------------------------------------
    113 D:Developmentworkspacemaven_project>

    下面是运行后的效果:

    这样做有什么用呢?

    既然加载到了本地仓库,那么就类似于本地仓库中的junit模块一样,我们在使用junit的时候,只是在pom.xml文件中配置一下,并不需要引入junit的相关jar包,同理。

    我们要使用/maven_project/src/com/b510/maven/hello/Hello.java类的时候,也不用引入该类的jar文件,只需要在pom.xml文件中配置即可。

    如:

    1 <dependencies>
    2     <dependency>
    3         <groupId>com.b510.maven.hello</groupId>
    4         <artifactId>hello-first</artifactId>
    5         <version>SNAPSHOT-0.0.1</version>
    6     </dependency>
    7 </dependencies>

    第一个maven小程序,就差不多是这些,good luck!

    ========================================================

    多读一些书,英语很重要。

    More reading,and english is important.

    I'm Hongten

    hongten

    ========================================================

  • 相关阅读:
    自省改过
    c语言学习教程1之预定义代码
    tqdm进度条管理
    React-i18next切换中英文
    React怎样实现点击其他地方隐藏弹出的菜单
    遍历对象再取值,获得新值
    Web 用户体验设计提升指南
    antd vue form
    echarts 内容显示值在图中显示,不显示交互效果,只是静态图
    element-ui中el-table根据浏览器的缩放自适应宽度
  • 原文地址:https://www.cnblogs.com/hongten/p/hongten_maven_first_program.html
Copyright © 2011-2022 走看看