Maven入门实战

来源:互联网 发布:怀化网络管理招聘 编辑:程序博客网 时间:2024/05/18 01:39
项目一大,管理起来就不太容易了。编译、测试、打包、发布,一个枯燥的周而复始的工作让无数程序员崩溃了一次又一次。于是,ant出现了~构建工程师终于可以轻松一下了。他们欢快得敲着xml式的命令:在xx位置创建一个xx文件夹,把xx文件夹下的源码进行编译,编译完的class文件放在xx位置,在xx位置的已发布包备份一下,然后把新发布的包放到xx位置……

但是项目不同,构建工程师不同,他们写的ant脚本就不同,构建方式就不同,一个新人过来项目组,总是不可避免的要花一部分时间来熟悉新项目的构建方式,浪费了很多无谓的时间,大家怨声载道……于是,maven出现了……

maven认为约定优于配置,它不是为你构建的不同任务编写脚本,它提倡一组标准,一个一般的接口,一个生命周期,一个标准的仓库格式,一个标准的目录布局,等等

一个新人弄懂了一个maven项目的构建方式,也就弄懂了所有的maven项目的构建方式……以后你拿到一个项目之后,你就会自然而然的知道用mvn install来构建它……Maven 的核心财产是声明性构建,依赖管理,仓库管理,基于插件的高度的重用

举个简单的例子,ant啥事都是自己干,像是攒一台组装机,而maven则更像是一品牌机~

maven的目标:就是干掉构建工程师(嘎嘎,开个玩笑)

OK.Let's get started!

1、去maven.apache.org/download.html下载maven,解压缩
2、设置环境变量,M2_HOME=maven根目录;path=%M2_HOME%\bin(Windows方式),用Linux的同学就按照Linux的方式设置一下就好~
3、打开命令行,运行:mvn -v,如果有版本输出,OK,说明你安装成功了
4、初始化maven:运行一下mvn help:system,初始化一下
5、开始一个小项目~
1)mvn archetype:generate,简单解释一下这个命令,archetype是一个maven插件,maven的绝大部分功能都是靠插件来完成的,这个插件提供了一些项目的核心骨架,比如一个简单的项目是这样的目录结构:
view source
print?
01frame-simple
02|-src
03|-main
04|-java
05|-一些带有包结构的java文件
06|-resources
07|-一些配置文件,比如log4j.properties
08|-test
09|-java
10|-resources
11|-pom.xml


但是对于一个web项目,目录结构就会稍有不同,maven要求把jsp文件放在src/main/webapp下,当然,WEB-INF目录也是放在这里

不同的项目,目录结构是不同的,我们称为项目骨架类型不同,mvn archetype:generate
这么命令就会有很多骨架类型让你选择,看到很多输出不要惊慌,选择默认的编号(这个编号就表示一个最简单的骨架类型),回车,接下来让你输入:
groupId/artifactId/version/package

先不要问为什么,groupId输入:com.baidu.testmvn;artifactId输入:testmvn-simple,version
直接按照默认的来就行,直接回车,package输入:com.baidu.testmvn,然后一个新的项目就骨架就搭建起来了

如果我现在要搭建一个web项目,可以直接这样输入一条命令来搞定:
mvn archetype:generate -DgroupId=hx.frame -DartifactId=frame-web -DarchetypeArtifactId=maven-archetype-webapp

groupId/artifactId/version这几个东东组成了maven中的坐标,这个解释起来挺麻烦,大伙可以google一下,maven利用坐标来唯一的定位一个jar包。全球有个maven中央库,那里维护了各种类型各种版本的jar包,他们需要一个唯一的标识来识别嘛是吧,所以坐标就应运而生了。

项目的根下有个pom.xml不知道你注意到没有,这个文件在整个项目中灰常重要,它规定了当前项目依赖于哪些jar包,用了哪些maven插件,使用了什么样的编译参数等等。你打开自己的文件看一下就好了,我就不贴出来了~默认情况下,maven为你引入了一个junit,可惜版本太低,不过没有关系,直接改成4.8的版本就行,在这里稍微这么一改动,maven就知道你要用哪个版本了,这,就是声明式构建的体现哦

6、导入你喜欢的IDE,我习惯用idea,直接File->New Project,选择已经存在的maven项目,导入,O了你可能习惯用eclipse,自己google一下怎么导入吧

在idea右侧有一个maven project的小窗口,里边有一些命令可以直接运行:
view source
print?
1mvn clean
2mvn validate
3mvn compile
4mvn test
5mvn package
6mvn install
7mvn site
8mvn depoly
其实这些命令就推动了maven项目的生命周期~google一下“maven 生命周期”
先清理一下,然后编译一下,测试一把,打个包,发布,是吧,正好也是你平时的做法,对吧,呵呵

maven对于项目的lib库的依赖管理很有一手,具体怎么管理的这里就不展开了,google一下“maven 依赖管理”
不过可以列几个命令share一下:
mvn dependency:list 查看当前项目的已解析依赖
mvn dependency:tree 查看当前项目的依赖树
mvn dependency:analyze 分析当前项目的依赖状况,可以找到一些warning:
a)使用了未声明的依赖
b)没有使用已声明的依赖(这些或许可以删掉,但是要仔细分析,像spring-core,spring-beans看起来是没有用到,但是他们是spring运行必须的)

OK,最后隆重推出一个maven插件,jetty-maven-plugin
这个插件可以启动一个jetty web服务器,启动速度喜人,一旦启动,修改了jsp,页面上可以直接反应出来,修改了servlet代码,运行一下mvn compile也可以立马反应出来,方便开发

在pom.xml中这样配置:
view source
print?
01<build>
02<finalName>frame-web</finalName>
03<plugins>
04<plugin>
05<groupId>org.mortbay.jetty</groupId>
06<artifactId>jetty-maven-plugin</artifactId>
07<version>7.1.6.v20100715</version>
08<configuration>
09<scanIntervalSeconds>3</scanIntervalSeconds>
10<webAppConfig>
11<contextPath>/test</contextPath>
12</webAppConfig>
13</configuration>
14</plugin>
15</plugins>
16</build>
然后命令行运行:mvn jetty:run
访问一下:localhost:8080/test/就可以看到你的index.jsp了
 

Maven入门

刚到公司,部门中导师让我学习一下maven,网上找到IBM的教程,按照步骤,先在命令行中操作,然后在eclipse 里操作一遍,已经有初步了解。下面将原文主要内容整理下来,原文参见网址http://www.ibm.com/developerworks/cn/education/java/j-mavenv2/index.html。其中部分地方有误,可以参看下文解决问题。

1. 新建一个项目,groupid = com.lzy.mvntest , artifactId为NumOps,和版本号一起唯一标识工程。

在命令行下 mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.lzy.mvntest -DartifactId=NumOps
该命令为 Archetype 插件提供您模块的坐标:com.ibm.devworks/NumOps/1.0-SNAPSHOT。
在此情况下,不需要指定版本,因为 Archetype 插件常默认为 1.0-SNAPSHOT。
此命令为项目创建了一个起始的 pom.xml 文件,也创建了规范的 Maven 2 目录结构。


2. 写好对应的java文件以后,在pom.xml文件里面加入以下build信息
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>(这个地方没有加上的话会报错,参考http://maven.apache.org/plugins/maven-compiler-plugin/usage.html)
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
进入到项目文件夹中使mvn compile进行编译

3. 在对应的test目录下面写测试文件,使用命令mvn test进行编译和测试

4. 在项目整合的时候, 每一个均有自己的pom.xml文件,同时在最顶层有主项目的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.ibm.devworks</groupId>
<artifactId>mavenex2</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Example 2</name>
<url>http://maven.apache.org</url>
<modules>
<module>NumOps</module>
<module>OpsImp</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.ibm.devworks</groupId>
<artifactId>OpsImp</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
其中对于junit的依赖,模块中不用重复写,因为继承了主模块的属性。
<modules>标签和打包类型为pom表示这个是一个多模块的项目
<dependencyManagement> 标记不指定此模块依赖的依赖项。
相反,它主要由子模块使用。
子模块能指定 <dependencyManagement> 标记中任何条目的依赖项,而无需指定具体的版本号。
当项目树更改依赖项的版本号时,这很有用,可以使需编辑的条目数目最小化。
在本例中,OpsImp 项目的版本号是使用 ${project.version} 指定的。
在执行 Maven 时,这是一个会被相应值所填充的参数。

5. 使用mvn test 或者mvn complie进行编译,使用mvn install进行打包。
使用mvn help:effective-pom 显示集成后的pom的内容 。

6. eclipse的maven的插件安装以及使用参考命令行下的步骤后较为简单,在此不记录。

7. 因为依赖的组件大部分是在组件库中,有时需要手动添加组件进来。在eclipse里面先要导入自己工程依赖的组件,然后再添加依赖项的功能中找到对应的。具体方法是在项目点右键,import->install or deploy an artifact to a Maven repository,添加后,再项目点右键->maven->add dependency输出刚才导入的依赖组件即可。

如果要手动输入的话按照以下命令:

mvn install:install-file -Dfile=sqljdbc.jar -DgroupId=com.lee -DartifactId=sqljdbc -Dversion=5.1.18 -Dpackaging=jar
其中Dfile是jar包路径,依次是groupid,artifactid和版本号以及打包方式。 执行命令后需要手动将其拷入到本地仓库中,仓库地址参考maven的配置文件。然后在文件中加入相关的dependency标签或者项目即可。

 

1.Configure Maven environment
1) Download Maven
http://maven.apache.org/download.html

apache-maven-3.0.4-bin.tar.gz
http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0.4-bin.tar.gz

2) Unzip apache-maven-3.0.4-bin.tar.gz to C:\CI

3) My Computer --> Property --> Environment Variant--> System Variant-->
Add-->name: M2_HOME value: C:\CI\apache-maven-3.0.4-->OK-->
choose Path-->edit-->add the last:  ;%M2_HOME%\bin-->OK-->OK-->OK

4) Test the Maven
cmd--> mvn -v
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: C:\CI\apache-maven-3.0.4\bin\..
Java version: 1.6.0_31, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_31\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

It shows it is ok.

2.Configure a Java and Maven project : Hello-world (Non-Eclipse IDE)
1) Create a hello-world folder
2) Create a file named pom.xml under hello-world folder
3) Edit pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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.juvenxu.mvnbook</groupId>
 <artifactId>hello-world</artifactId>
 <version>1.0-SNAPSHOT</version>
 <name>Maven Hello World Project</name> 
</project>

4) Create src/main/java folder under hello-world folder
5) Create file com/juvenxu/mvnbook/helloworld/HelloWorld.java under hello-world/src/main/java folder
6) Eidt HelloWorld.java :

package com.juvenxu.mvnbook.helloworld;

public class HelloWorld
{
 public String sayHello()
 {
  return "Hello Maven"; 
 }
 
 public static void main(String[] args)
 {
  System.out.println(new HelloWorld().sayHello());
 }
}

7) cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ hello-world ---
[INFO] Deleting F:\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ hello-world ---
[debug] execute contextualize
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform
dependent!
[INFO] skip non existing resourceDirectory F:\hello-world\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ hello-world ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform depend
ent!
[INFO] Compiling 1 source file to F:\hello-world\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.636s
[INFO] Finished at: Fri Feb 24 09:54:39 CST 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
F:\hello-world>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Hello World Project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ hello-world ---
[INFO] Deleting F:\hello-world\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ hello-world ---
[debug] execute contextualize
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\hello-world\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ hello-world ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\hello-world\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.639s
[INFO] Finished at: Fri Feb 24 09:54:51 CST 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
F:\hello-world>

7) Add Test into project,Edit the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.juvenxu.mvnbook</groupId>
 <artifactId>hello-world</artifactId>
 <version>1.0-SNAPSHOT</version>
 <name>Maven Hello World Project</name> 
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.10</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
</project>

8) Create src/test/java folder under hello-world folder
9) Create file com/juvenxu/mvnbook/helloworld/HelloWorldTest.java under hello-world/src/test/java folder
10) Eidt HelloWorldTest.java :

package com.juvenxu.mvnbook.helloworld;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class HelloWorldTest
{
 @Test
 public void testSayHello()
 {
  HelloWorld helloWorld = new HelloWorld();
  String result = helloWorld.sayHello();
  assertEquals("Hello Maven",result);
 }
}

11) cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>mvn clean test
...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.juvenxu.mvnbook.helloworld.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.241s
[INFO] Finished at: Fri Feb 24 09:58:10 CST 2012
[INFO] Final Memory: 9M/21M
[INFO] ------------------------------------------------------------------------
F:\hello-world>

11) cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>mvn clean package
...
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ hello-world ---
[INFO] Building jar: F:\hello-world\target\hello-world-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.701s
[INFO] Finished at: Fri Feb 24 09:59:10 CST 2012
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------

12) cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>mvn clean install
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ hello-world ---
[INFO] Building jar: F:\hello-world\target\hello-world-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ hello-world ---
[INFO] Installing F:\hello-world\target\hello-world-1.0-SNAPSHOT.jar to C:\Users\NHN\.m2\repository\com\juvenxu\mvnbook\
hello-world\1.0-SNAPSHOT\hello-world-1.0-SNAPSHOT.jar
[INFO] Installing F:\hello-world\pom.xml to C:\Users\NHN\.m2\repository\com\juvenxu\mvnbook\hello-world\1.0-SNAPSHOT\hel
lo-world-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.946s
[INFO] Finished at: Fri Feb 24 10:00:42 CST 2012
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------

13)Configure executable jar,  Edit the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.juvenxu.mvnbook</groupId>
 <artifactId>hello-world</artifactId>
 <version>1.0-SNAPSHOT</version>
 <name>Maven Hello World Project</name> 
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.10</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>1.5</version>
         <executions>
           <execution>
             <phase>package</phase>
             <goals>
               <goal>shade</goal>
             </goals>
             <configuration>
               <transformers>
                 <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                   <mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>
                 </transformer>
               </transformers>
             </configuration>
           </execution>
         </executions>
       </plugin>
     </plugins>
 </build>
</project>

14) cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>mvn clean install
...
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ hello-world ---
[INFO] Installing F:\hello-world\target\hello-world-1.0-SNAPSHOT.jar to C:\Users\NHN\.m2\repository\com\juvenxu\mvnbook\
hello-world\1.0-SNAPSHOT\hello-world-1.0-SNAPSHOT.jar
[INFO] Installing F:\hello-world\pom.xml to C:\Users\NHN\.m2\repository\com\juvenxu\mvnbook\hello-world\1.0-SNAPSHOT\hel
lo-world-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.888s
[INFO] Finished at: Fri Feb 24 10:02:25 CST 2012
[INFO] Final Memory: 9M/24M
[INFO] ------------------------------------------------------------------------

15)cmd ---> cd /d  (To  hello-world folder ) -->

F:\hello-world>java -jar target\hello-world-1.0-SNAPSHOT.jar
Hello Maven


16) put hello-world folder in svn server-->Tortoise SVN-->Repo-browser-->
URL: http://localhost/svn/myweb/trunk/-->OK-->Username: admin-->Password: admin-->
Save authentication-->OK-->Create folder...-->New name: MyMaven-->OK-->OK-->Tow the hello-world folder to the MyMaven folder-->
Question: NO
Commit person: CN15209
Commit reason: Commit the hello-world project.

-->OK-->OK-->delete the local hello-world folder-->
SVN Checkout...-->URL of repository:http://localhost/svn/myweb/trunk/MyMaven/hello-world-->
OK-->
Now we create a repository on svn.

17) start hudson(I use Java Method to start hudson)

18) firefox-->http://localhost:8080 --> Manage Hudson-->Configure System-->JDK-->
Add JDK-->Name: JDK1.6.0_31-->JAVA_HOME: C:\Program Files\Java\jdk1.6.0_31-->Maven-->Add Maven-->

Name: M2-->cancel Install automatically-->MAVEN_HOME: C:\CI\apache-maven-3.0.4-->
E-mail Notification--> Advanced-->
SMTP server : 127.0.0.1
Default User E-mail Suffix: @mymail.cn
System Admin E-mail Address: Jenny@mymail.cn
Hudson URL: http://localhost:8080/

Use SMTP Autherntication (Choose)
User Name: Jenny@mymail.cn
Password: Jenny
User SSL (Disable)
SMTP Port: 25
Charset UTF-8
-->Test configuration by sending e-mail to System Admin Address-->Save-->Your Foxmail will receive a email from hudson.It's said that it is ok.

-->Save

19) Hudson-->New Job-->Job name: myfirstmavenjob-->choose Build a Maven 2/3 project(Legacy)-->OK-->
Source Code Management choose Subversion-->Repository URL: http://localhost/svn/myweb/trunk/MyMaven/hello-world-->
enter credential-->User name/password authentication-->User name: admin-->Password: admin-->ok-->close-->
Build-->Goals and options:  clean install
-->Save-->Hudson-->choose myfirstmavenjob Schedule a build-->
See Latest Console output

20) Create trigger -->Hudson-->myfirstmavenjob-->Configure-->Choose Poll SCM-->Schedule: * * * * *  (Every minute to check codes)-->Save

#########################
Here you maybe use internet,but I haven't it.So I setup a mail server and foxmail client.
Please See my hMailServer_Step by Step.txt file for the detail.
I configure 127.0.0.1 smtp server ip,User : Jenny@mymail.cn Password : Jenny
#########################

21) Hudson-->Manage Hudson-->Configure System-->E-mail Notification-->Recipients:Jenny@mymail.cn-->
Choose Send e-mail for every unstable build
Don't Choose Send separate e-mails to individuals who broke the build (because the svn user isn't a email user,so if you choose this ,the email
can't send above the correct email user.)
(Remember the Recipients users must use the blank ,if you use ',' ,the email cann't send always)

22) Build Now-->You will receive a email(If you build success.you will not receive a email.Please let you code error,you will receive a email).