﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-qileilove-文章分类-maven</title><link>http://www.blogjava.net/qileilove/category/54206.html</link><description>不想做屌丝的码农，不是好项目经理！屌丝生涯从此开始！</description><language>zh-cn</language><lastBuildDate>Fri, 11 Apr 2014 21:58:32 GMT</lastBuildDate><pubDate>Fri, 11 Apr 2014 21:58:32 GMT</pubDate><ttl>60</ttl><item><title>android maven配置</title><link>http://www.blogjava.net/qileilove/articles/412327.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 11 Apr 2014 10:56:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/412327.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/412327.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/412327.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/412327.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/412327.html</trackback:ping><description><![CDATA[<ol style="font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li>http://code.google.com/p/maven-android-plugin/<br /></li><ol><li>安装jdk 略过 &nbsp;我的是这个版本Java(TM) SE Runtime Environment (build 1.6.0_38-b05)&nbsp;<ul><li>如需ubuntu 安装配置jdk的教程，请点击 &nbsp;<a href="http://hi.baidu.com/xingfukaixin/item/fa85176ad76dba34ad3e8364" style="color: #ca0000; text-decoration: none;">http://hi.baidu.com/xingfukaixin/item/fa85176ad76dba34ad3e8364</a></li></ul></li><li>安装Android-sdk &nbsp;<ul><li><a href="http://developer.android.com/sdk/index.html" style="color: #ca0000; text-decoration: none;">http://developer.android.com/sdk/index.html</a><br /></li></ul></li><li>到Maven的官方下载最新版本的Maven</li></ol><ul><li>下载地址&nbsp;<a href="http://maven.apache.org/download.html" rel="nofollow" style="color: #ca0000; text-decoration: none;">http://maven.apache.org/download.html</a></li><li>我下载的是 Maven 3.0.4<br /></li><li>找个文件夹解压，并配置到系统的环境变量<br /><ul><li>/home/wuyexiong/Android/tool/maven/apache-maven-3.0.4/bin 配置到/etc/environment</li><li>ANDROID_HOME="/home/wuyexiong/Android/android-linux/adt-bundle-linux-x86_64/sdk"<br />这个sdk &nbsp;可以利用anroidmanager来下载 sdk<br /><br /></li></ul></li></ul><li>打开该网页，点击&nbsp;<a href="http://code.google.com/p/maven-android-plugin/wiki/GettingStarted" style="color: #ca0000; text-decoration: none;">GettingStarted</a>&nbsp;跳转到http://code.google.com/p/maven-android-plugin/wiki/GettingStarted 该页面<br /><br /><span style="font-size: 14.44444465637207px;">想编译Android项目还差最后一部 ，用git把&nbsp;</span><a external"="" href="http://github.com/mosabua/maven-android-sdk-deployer" target="_top" style="color: #ca0000; text-decoration: none; font-size: 14.44444465637207px;">Maven AndroidSDK Deployer</a><span style="font-size: 14.44444465637207px;">&nbsp; 项目载到本地</span><br /><div style="font-size: 14.44444465637207px;"><ul><li><ul><li>在此之前的环境都搭建完毕的前提下，进入该项目的跟目录</li><li>执行 mvn clean install 。 就会自动构建Android-maven的编译环境<br /><br />mvn install -P 4.0 会把 相关的sdk 上传到 maven仓库中 &nbsp;折腾了 老子一天 &nbsp;由于家里网不行 &nbsp;maven依赖的jar都下载不下来 &nbsp;到公司都OK</li><li>中途会下载一些东西，检查你的sdk等等，稍作等候即可</li><li><div bg_html"="" style="width: 857.1354370117188px;"><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 598px; top: 1240px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Reactor&nbsp;Summary:&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Maven&nbsp;Android&nbsp;SDK&nbsp;Deployer&nbsp;........................&nbsp;SUCCESS&nbsp;[0.232s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platforms&nbsp;.................................&nbsp;SUCCESS&nbsp;[0.007s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;1.5&nbsp;API&nbsp;3&nbsp;........................&nbsp;SUCCESS&nbsp;[0.065s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;1.6&nbsp;API&nbsp;4&nbsp;........................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;2.1&nbsp;API&nbsp;7&nbsp;........................&nbsp;SUCCESS&nbsp;[0.012s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;2.2&nbsp;API&nbsp;8&nbsp;........................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;2.3.3&nbsp;API&nbsp;10&nbsp;.....................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;3.0&nbsp;API&nbsp;11&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.028s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;3.1&nbsp;API&nbsp;12&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;3.2&nbsp;API&nbsp;13&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;4.0&nbsp;API&nbsp;14&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.012s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;4.0.3&nbsp;API&nbsp;15&nbsp;.....................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;4.1&nbsp;API&nbsp;16&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Platform&nbsp;4.2&nbsp;API&nbsp;17&nbsp;.......................&nbsp;SUCCESS&nbsp;[0.012s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-Ons&nbsp;...................................&nbsp;SUCCESS&nbsp;[0.006s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;1.5&nbsp;API&nbsp;3&nbsp;(Maps)&nbsp;...&nbsp;SUCCESS&nbsp;[0.018s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;1.6&nbsp;API&nbsp;4&nbsp;(Maps)&nbsp;...&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;2.1&nbsp;API&nbsp;7&nbsp;(Maps)&nbsp;...&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;2.2&nbsp;API&nbsp;8&nbsp;(Maps)&nbsp;...&nbsp;SUCCESS&nbsp;[0.014s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;2.3.3&nbsp;API&nbsp;10&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.017s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;3.0&nbsp;API&nbsp;11&nbsp;(Maps)&nbsp;..&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;3.1&nbsp;API&nbsp;12&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.017s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;3.2&nbsp;API&nbsp;13&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.016s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;4.0&nbsp;API&nbsp;14&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.017s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;4.0.3&nbsp;API&nbsp;15&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.018s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;4.1&nbsp;API&nbsp;16&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.019s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Add-On&nbsp;Google&nbsp;Platform&nbsp;4.2&nbsp;API&nbsp;17&nbsp;(Maps&nbsp;and&nbsp;USB)&nbsp;&nbsp;SUCCESS&nbsp;[0.018s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Extras&nbsp;....................................&nbsp;SUCCESS&nbsp;[0.009s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Compatibility&nbsp;Extra&nbsp;V4&nbsp;....................&nbsp;SUCCESS&nbsp;[0.013s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Compatibility&nbsp;Extra&nbsp;V7&nbsp;Gridlayout&nbsp;Library&nbsp;.&nbsp;SUCCESS&nbsp;[1.999s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Compatibility&nbsp;Extra&nbsp;V13&nbsp;...................&nbsp;SUCCESS&nbsp;[0.009s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Analytics&nbsp;Extra&nbsp;....................&nbsp;SUCCESS&nbsp;[0.009s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;AdMob&nbsp;Ads&nbsp;Extra&nbsp;....................&nbsp;SUCCESS&nbsp;[0.009s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Cloud&nbsp;Messaging&nbsp;Library&nbsp;Extra&nbsp;Parent&nbsp;&nbsp;SUCCESS&nbsp;[0.006s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Cloud&nbsp;Messaging&nbsp;Client&nbsp;Library&nbsp;Extra&nbsp;&nbsp;SUCCESS&nbsp;[0.010s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Cloud&nbsp;Messaging&nbsp;Server&nbsp;Library&nbsp;Extra&nbsp;&nbsp;SUCCESS&nbsp;[0.010s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Play&nbsp;Services&nbsp;Extra&nbsp;................&nbsp;SUCCESS&nbsp;[0.460s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Play&nbsp;Licensing&nbsp;Extra&nbsp;...............&nbsp;SUCCESS&nbsp;[0.297s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Extras&nbsp;-&nbsp;Apk&nbsp;Expansion&nbsp;....................&nbsp;SUCCESS&nbsp;[0.006s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Play&nbsp;APK&nbsp;Expansion&nbsp;Extra&nbsp;-&nbsp;ZIP&nbsp;.....&nbsp;SUCCESS&nbsp;[0.240s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Google&nbsp;Play&nbsp;APK&nbsp;Expansion&nbsp;Extra&nbsp;-&nbsp;Downloader&nbsp;&nbsp;SUCCESS&nbsp;[0.314s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Tools&nbsp;.....................................&nbsp;SUCCESS&nbsp;[0.004s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Android&nbsp;Annotations&nbsp;...............................&nbsp;SUCCESS&nbsp;[0.007s]&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;BUILD&nbsp;SUCCESS&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Total&nbsp;time:&nbsp;5.277s&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Finished&nbsp;at:&nbsp;Mon&nbsp;Dec&nbsp;31&nbsp;16:42:23&nbsp;CST&nbsp;2012&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Final&nbsp;Memory:&nbsp;24M/298M&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li></ol></div><br /><br /></li><li>出现以上，就代表 android-maven的初步环境构建完毕<br /></li><li>cd ~/.m2/ 到该目录下打开repository的文件夹即可查看到已经配置好相关的Android环境了<br /></li></ul></li></ul><div></div></div><div style="font-size: 14.44444465637207px;"><ul><li>测试android-maven<ul><li>下载可供给打包测试的例子代码&nbsp;<a href="https://github.com/jayway/maven-android-plugin-samples/zipball/stable" rel="nofollow" style="color: #ca0000; text-decoration: none;">Download samples from the stable branch</a></li><li>解压该项目，进入&nbsp;jayway-maven-android-plugin-samples-b17572a 文件夹</li><li><div bg_html"="" style="width: 857.1354370117188px;"><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 598px; top: 2609px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;4&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;31&nbsp;15:49&nbsp;apidemos-android-10/&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;&nbsp;136&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;.gitignore&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;4&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;helloflashlight/&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;6&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;libraryprojects/&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;10173&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;LICENSE.txt&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;5&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;morseflash/&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;13&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;native/&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;7548&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;pom.xml&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;&nbsp;942&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;README.txt&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;4&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;scala/&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;5&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;31&nbsp;15:34&nbsp;support4demos/&nbsp;&nbsp;</li></ol></div></li><li>可以看到都是一些例子的代码。</li><li>这时候可以进入具体的一个项目，比如进入support4demos</li><li><div bg_html"="" style="width: 857.1354370117188px;"><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 598px; top: 2957px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;10630&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;AndroidManifest.xml&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;1909&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;pom.xml&nbsp;&nbsp;</li><li style="line-height: 20px;">-rw-rw-r--&nbsp;&nbsp;1&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;&nbsp;377&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;README.txt&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;10&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;res/&nbsp;&nbsp;</li><li style="line-height: 20px;">drwxrwxr-x&nbsp;&nbsp;3&nbsp;wuyexiong&nbsp;wuyexiong&nbsp;&nbsp;4096&nbsp;12月&nbsp;19&nbsp;10:25&nbsp;src/&nbsp;&nbsp;</li></ol></div></li><li>这是完整项目的文件了</li><li>打开模拟器，或者链接上手机，执行&nbsp;<span style="color: #3366ff;">mvn clean install</span>&nbsp;即可编该程序了</li><li>也可以只是执行<span style="color: #3366ff;">&nbsp;mvn package&nbsp;</span>来进行打包， 即可在项目下生成一个target的目录，目录底下都是一些目标文件</li><li>这两种默认都是以debug签名的，更多待研究了。。。</li><li>最后执行&nbsp;<span style="color: #3366ff;">mvn android:deploy</span>&nbsp;即可安装到模拟器或者手机</li><li>编译并安装是执行&nbsp;<span style="color: #3366ff;">mvn clean install android:deploy</span></li><li><span style="color: #3366ff;"><br /></span></li><li><div bg_html"="" style="width: 857.1354370117188px;"><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/forever_crying/article/details/8455626#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 598px; top: 3312px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 20px;">[INFO]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Building&nbsp;Android&nbsp;Support&nbsp;V4&nbsp;Demos&nbsp;1.0.0-SNAPSHOT&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;---&nbsp;android-maven-plugin:3.5.0:deploy&nbsp;(default-cli)&nbsp;@&nbsp;support4demos&nbsp;---&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Waiting&nbsp;for&nbsp;initial&nbsp;device&nbsp;list&nbsp;from&nbsp;the&nbsp;Android&nbsp;Debug&nbsp;Bridge&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Found&nbsp;1&nbsp;devices&nbsp;connected&nbsp;with&nbsp;the&nbsp;Android&nbsp;Debug&nbsp;Bridge&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;android.device&nbsp;parameter&nbsp;not&nbsp;set,&nbsp;using&nbsp;all&nbsp;attached&nbsp;devices&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Successfully&nbsp;installed&nbsp;/home/wuyexiong/Android/tool/maven/jayway-maven-android-plugin-samples-b17572a/support4demos/target/support4demos.apk&nbsp;to&nbsp;MX3ACA1ALGVA8Q1125_Meizu_M031&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;BUILD&nbsp;SUCCESS&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Total&nbsp;time:&nbsp;8.965s&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Finished&nbsp;at:&nbsp;Mon&nbsp;Dec&nbsp;31&nbsp;16:55:09&nbsp;CST&nbsp;2012&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;Final&nbsp;Memory:&nbsp;17M/146M&nbsp;&nbsp;</li><li style="line-height: 20px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li></ol></div><br /><br /></li></ul></li></ul></div><div style="font-size: 14.44444465637207px;"></div><div style="font-size: 14.44444465637207px;">&nbsp; &nbsp; &nbsp; &nbsp; 本章到此了,我也是刚研究这个，因为发现github上面很多开源项目都是带有pom.xml这个文件的，所以下了解一下，最好能深入一下。</div><div style="font-size: 14.44444465637207px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="font-size: 14.44444465637207px;">&nbsp; &nbsp; &nbsp; &nbsp; 循序渐进吧。等待研究更深入的东西，把笔记都记到这上面</div></li></ol><img src ="http://www.blogjava.net/qileilove/aggbug/412327.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-11 18:56 <a href="http://www.blogjava.net/qileilove/articles/412327.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven 插件管理</title><link>http://www.blogjava.net/qileilove/articles/411892.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 03 Apr 2014 03:37:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411892.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411892.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411892.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411892.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411892.html</trackback:ping><description><![CDATA[<strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">插件管理</strong><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp; pluginManagement：插件管理以同样的方式包括插件元素，用于在特定的项目中配置。所有继承于此项目的子项目都能使用。主要定义插件的共同元素</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">扩展元素集合</strong><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">主要包括以下的元素：</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">Directories</strong><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">用于设置各种目录结构，如下：</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" />&nbsp;<div style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;">xml 代码</div><div style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 30px;"><div>&nbsp;</div><ol style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;build&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;sourceDirectory&gt;${basedir}/src/main/java&lt;!----&gt;sourceDirectory&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;scriptSourceDirectory&gt;${basedir}/src/main/scripts&lt;!----&gt;scriptSourceDirectory&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;testSourceDirectory&gt;${basedir}/src/test/java&lt;!----&gt;testSourceDirectory&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;outputDirectory&gt;${basedir}/target/classes&lt;!----&gt;outputDirectory&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;testOutputDirectory&gt;${basedir}/target/test-classes&lt;!----&gt;testOutputDirectory&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;!----&gt;build&gt;&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 30px; background-color: #ffffff;" /><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;">在父项目的 pluginManagement 中明确 使用 maven-site-plugin。而在每一个项目中都明确使用 maven-site-plugin</p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;">代码如下：父项目pom.xml：</p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;">&nbsp;&lt;build&gt;&nbsp;<br />&lt;pluginManagement&gt;&nbsp;<br />&lt;plugin&gt;&nbsp;<br />&lt;groupId&gt; org.apache.maven.plugins&lt;/groupId&gt;&nbsp;<br />&lt;artifactId&gt; maven-site-plugin&lt;/artifactId&gt;&nbsp;<br />&lt;version&gt; 2.0&lt;/version&gt;&nbsp;<br />&lt;/plugin&gt;&nbsp;<br />&lt;/plugins&gt;&nbsp;<br />&lt;/pluginManagement&gt;&nbsp;<br />&lt;plugins&gt;&nbsp;<br />&lt;plugin&gt;&nbsp;<br />&lt;groupId&gt; org.apache.maven.plugins&lt;/groupId&gt;&nbsp;<br />&lt;artifactId&gt; maven-site-plugin&lt;/artifactId&gt;&nbsp;<br />&lt;/plugin&gt;&nbsp;<br />&lt;/plugins&gt;&nbsp;<br />&lt;/build&gt;</p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ffffff;"><br />子项目pom.xml：&nbsp;<br />&lt;build&gt;&nbsp;<br />&lt;plugins&gt;&nbsp;<br />&lt;plugin&gt;&nbsp;<br />&lt;groupId&gt; org.apache.maven.plugins&lt;/groupId&gt;&nbsp;<br />&lt;artifactId&gt; maven-site-plugin&lt;/artifactId&gt;&nbsp;<br />&lt;/plugin&gt;&nbsp;<br />&lt;/plugins&gt;&nbsp;<br />&lt;/build&gt;</p><div></div><img src ="http://www.blogjava.net/qileilove/aggbug/411892.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-03 11:37 <a href="http://www.blogjava.net/qileilove/articles/411892.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven3实战笔记07继承</title><link>http://www.blogjava.net/qileilove/articles/411833.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 02 Apr 2014 03:49:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411833.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411833.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411833.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411833.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411833.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">创建两个项目</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cdai_codebase_parent：其他项目的Maven配置都继承这个项目中pom.xml的定义。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cdai_codebase_ssh：一个SSH示例项目，继承parent项目中的配置。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><img src="http://img.my.csdn.net/uploads/201212/17/1355744083_1575.png" alt="" style="border: none; max-width: 100%;" />&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">首先看cdai_codebase_parent中pom.xml的内容：</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;<img src="http://img.my.csdn.net/uploads/201212/17/1355744329_3806.png" alt="" style="border: none; max-width: 100%;" /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">通过将packaging属性定义为pom来说明当前pom.xml是用来被继承的。之后在parent的pom.xml中，我们可以定义一些统一的版本号（Spring等第三方包的），依赖项（所有项目都会用的JUnit），以及通用的打包配置等。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">现在，我们就可以在cdai_codebase_ssh中，通过项目的相对路径引用这个parent的pom.xml文件了。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><img src="http://img.my.csdn.net/uploads/201212/17/1355744425_2209.png" alt="" style="border: none; max-width: 100%;" />&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">附：在父pom.xml中dependencyManagement中定义需要被继承的依赖，然后在子pom.xml中可以直接指定groupId和artifactId来引入，就不需要版本号了。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><img src="http://img.my.csdn.net/uploads/201212/17/1355744469_1219.png" alt="" style="border: none; max-width: 100%;" /></p><img src ="http://www.blogjava.net/qileilove/aggbug/411833.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-02 11:49 <a href="http://www.blogjava.net/qileilove/articles/411833.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven - 继承和聚合</title><link>http://www.blogjava.net/qileilove/articles/411802.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 01 Apr 2014 07:20:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411802.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411802.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411802.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411802.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411802.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: *聚合(多模块)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在一个项目中 往往有多个模块组成&nbsp; 例如有项目demo&nbsp; 下面有a, b两个模块&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/articles/411802.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/411802.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-04-01 15:20 <a href="http://www.blogjava.net/qileilove/articles/411802.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven常用插件配置和使用</title><link>http://www.blogjava.net/qileilove/articles/411743.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 31 Mar 2014 09:29:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411743.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411743.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411743.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411743.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411743.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">本文主要是<strong>介绍maven的几个常见第三方插件(cobertura、findbugs、source、assembly、插件开发)配置和使用</strong>，接<a href="http://trinea.iteye.com/blog/1290898" style="color: black;">http://trinea.iteye.com/blog/1290898</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>maven本质上是一个插件框架，它的所有工作都交给插件来做，每个插件可以有多个goal</strong>。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">除了自带的插件之外还有很多比较成熟的第三方插件，我们也很容易上手进行简单的插件开发，下面一一介绍</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>1 自带插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">maven自带的核心插件为Build plugins和Reporting plugins。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">mvn compile编译源码实际上就利用到了maven-compiler-plugin，其他phase也类似用到了相应的插件</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">关于maven自带的核心插件见：<a href="http://maven.apache.org/plugins/index.html" style="color: black;">http://maven.apache.org/plugins/index.html</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2 第三方插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.1 maven有很多成熟的第三方插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">如jetty 对于web开发使用jetty作为容器</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">native<span style="white-space: pre;">	</span>编译c和c++代码</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">sql<span style="white-space: pre;">	</span>执行sql脚本</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">其他更多见：<a href="http://maven.apache.org/plugins/index.html#Outside_The_Maven_Land" style="color: black;">http://maven.apache.org/plugins/index.html#Outside_The_Maven_Land</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">下面具体介绍下单元测试覆盖率插件<strong>cobertura、findbugs</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.2&nbsp;maven2的cobertura插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.2.1&nbsp;<a href="http://cobertura.sourceforge.net/" target="_blank" style="color: black;">cobertura</a>是一款用来计算java代码测试覆盖率的工具</strong>，基于jcoverage。能计算每个类、包、整个工程的行覆盖率和分支覆盖率以及<a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity" target="_blank" style="color: black;">代码复杂度(Cyclomatic complexity)</a>并生成html或xml形式的报告，让用户很方便的查看代码的单元测试覆盖率情况。cobertura的原理是通过对class文件进行插桩然后计算。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.2.2&nbsp;maven2的cobertura插件介绍</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">插件地址为<a href="http://mojo.codehaus.org/cobertura-maven-plugin/index.html" style="color: black;">http://mojo.codehaus.org/cobertura-maven-plugin/index.html</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">a、首先在pom中添加配置如下</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="text-decoration: underline;"><img src="http://trinea.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">reporting</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">outputDirectory</span><span style="color: #006699; font-weight: bold;">&gt;</span>target/site<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">outputDirectory</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>org.codehaus.mojo<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>cobertura-maven-plugin<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">reporting</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">b、运行goal</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">到项目根目录下运行mvn cobertura:cobertura 将会插桩class文件、测试、生成覆盖率报告</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">cobertura支持的goal如下</p><ul style="margin: 0px 0px 1.5em; padding: 0px; line-height: 25.200000762939453px; background-color: #ffffff; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13px;"><li style="margin: 0px 0px 0.25em 30px; padding: 0px;"><a href="http://mojo.codehaus.org/cobertura-maven-plugin/check-mojo.html" style="color: #3366aa; text-decoration: none;">cobertura:check</a>&nbsp;Check the Last Instrumentation Results.</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;"><a href="http://mojo.codehaus.org/cobertura-maven-plugin/clean-mojo.html" style="color: #3366aa; text-decoration: none;">cobertura:clean</a>&nbsp;Clean up rogue files that cobertura maven plugin is tracking.</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;"><a href="http://mojo.codehaus.org/cobertura-maven-plugin/dump-datafile-mojo.html" style="color: #3366aa; text-decoration: none;">cobertura:dump-datafile</a>&nbsp;Cobertura Datafile Dump Mojo.</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;"><a href="http://mojo.codehaus.org/cobertura-maven-plugin/instrument-mojo.html" style="color: #3366aa; text-decoration: none;">cobertura:instrument</a>&nbsp;Instrument the compiled classes.</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;"><a href="http://mojo.codehaus.org/cobertura-maven-plugin/cobertura-mojo.html" style="color: #3366aa; text-decoration: none;">cobertura:cobertura</a>&nbsp;Instruments, Tests, and Generates a Cobertura Report.</li></ul><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">c、在target\site\cobertura目录下生成报告文件，打开index.html可以查看具体报告</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">mvn cobertura:cobertura执行前会执行test phase，即执行单侧代码</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.3 maven2的</strong><strong>findbugs</strong><strong>插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.3.1&nbsp;<a href="http://findbugs.sourceforge.net/factSheet.html" target="_blank" style="color: black;">findbugs</a>是静态检查java代码的工具</strong>，根据一些bugs的表达式检查代码中的bugs，可以自定义检查规则</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.3.2&nbsp;maven2的</strong><strong>findbugs</strong><strong>插件介绍</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">插件地址为<a href="http://mojo.codehaus.org/findbugs-maven-plugin/index.html" style="color: black;">http://mojo.codehaus.org/findbugs-maven-plugin/index.html</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">a、首先在pom中添加配置如下</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">不同goal的配置略有不同，可自己调整，以下介绍的是mvn findbugs:findbugs的配置</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="text-decoration: underline;"><img src="http://trinea.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">reporting</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>org.codehaus.mojo<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>findbugs-maven-plugin<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>2.3.1<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">reporting</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">b、运行goal</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">到项目根目录下运行mvn findbugs:findbugs将会开始检查，并生成bugs报告</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">findbugs支持的goal如下</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="text-decoration: underline;"><img src="http://trinea.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">findbugs:check&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Fail&nbsp;the&nbsp;build&nbsp;if&nbsp;there&nbsp;were&nbsp;any&nbsp;FindBugs&nbsp;violations&nbsp;in&nbsp;the&nbsp;source&nbsp;code.&nbsp;An&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;XML&nbsp;report&nbsp;is&nbsp;put&nbsp;out&nbsp;by&nbsp;default&nbsp;in&nbsp;the&nbsp;target&nbsp;directory&nbsp;with&nbsp;the&nbsp;errors.&nbsp;To&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;see&nbsp;more&nbsp;documentation&nbsp;about&nbsp;FindBugs'&nbsp;options,&nbsp;please&nbsp;see&nbsp;the&nbsp;FindBugs&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Manual..&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">findbugs:findbugs&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Generates&nbsp;a&nbsp;FindBugs&nbsp;Report&nbsp;when&nbsp;the&nbsp;site&nbsp;plugin&nbsp;is&nbsp;run.&nbsp;The&nbsp;HTML&nbsp;report&nbsp;is&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;generated&nbsp;for&nbsp;site&nbsp;commands&nbsp;only.&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">findbugs:gui&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Launch&nbsp;the&nbsp;Findbugs&nbsp;GUI.&nbsp;It&nbsp;will&nbsp;use&nbsp;all&nbsp;the&nbsp;parameters&nbsp;in&nbsp;the&nbsp;POM&nbsp;fle.&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">findbugs:help&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Display&nbsp;help&nbsp;information&nbsp;on&nbsp;findbugs-maven-plugin.&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;Call&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;mvn&nbsp;findbugs:help&nbsp;<span style="color: red;">-Ddetail</span>=<span style="color: blue;">true</span>&nbsp;<span style="color: red;">-Dgoal</span>=<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">goal-name</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;to&nbsp;display&nbsp;parameter&nbsp;details.&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">c、在target\site\findbugs目录下生成报告文件，打开index.html可以查看具体报告</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">mvn findbugs:findbugs绑定到了compile phase，即在编译时自动检查</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><a href="http://qa.taobao.com/?p=4206" style="color: black;">http://qa.taobao.com/?p=4206</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.4 maven的source插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.4.1 source插件用来将工程打包成带源代码的jar包</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.4.2&nbsp;maven2的source</strong><strong>插件介绍</strong></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="text-decoration: underline;"><img src="http://trinea.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">build</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>org.apache.maven.plugins<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>maven-source-plugin<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>2.1.2<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">executions</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">execution</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>attach-sources<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">phase</span><span style="color: #006699; font-weight: bold;">&gt;</span>verify<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">phase</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">goals</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">goal</span><span style="color: #006699; font-weight: bold;">&gt;</span>jar-no-fork<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">goal</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">goals</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">execution</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">executions</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">build</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">直接运行mvn clean install会在target下打出两个包，带***-sources.jar的为源码包</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.5 maven的assembly插件</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.5.1&nbsp;assembly插件可用来将工程依赖的jar包和工程都打成一个jar打包</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.5.2&nbsp;maven2的</strong><strong>assembly</strong><strong>插件pom配置如下</strong></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="text-decoration: underline;"><img src="http://trinea.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">build</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>maven-assembly-plugin<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">configuration</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">descriptorRefs</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">descriptorRef</span><span style="color: #006699; font-weight: bold;">&gt;</span>jar-with-dependencies<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">descriptorRef</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">descriptorRefs</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">configuration</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugins</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">build</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">直接运行mvn assembly:assembly会在target下出现***-with-dependencies.jar的jar包</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>2.6 插件开发</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">maven的插件开发相当简单，可以参考<a href="http://trinea.iteye.com/blog/1171957" style="color: black;">http://trinea.iteye.com/blog/1171957</a></p><img src ="http://www.blogjava.net/qileilove/aggbug/411743.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-31 17:29 <a href="http://www.blogjava.net/qileilove/articles/411743.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven生命周期详解</title><link>http://www.blogjava.net/qileilove/articles/411608.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 28 Mar 2014 06:19:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411608.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411608.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411608.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411608.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411608.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven强大的一个重要的原因是它有一个十分完善的生命周期模型(lifecycle)，这个生命周期可以从两方面来理解，第一，顾名思义，运行Maven的每个步骤都由它来定义的，这种预定义的默认行为使得我们使用Maven变得简单，相比而言，Ant的每个步骤都要你手工去定义。第二，这个模型是一种标准，在不同的项目中，使用Maven的接口是一样的，这样就不用去仔细理解每个项目的构建了，一般情况下，<strong>mvn clean install</strong>&nbsp;这样的命令是通用的。我想，一定是吸收了许多项目的经验，Maven才能定义出如此完善的模型。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven有三套相互独立的生命周期，请注意这里说的是&#8220;三套&#8221;，而且&#8220;相互独立&#8221;，初学者容易将Maven的生命周期看成一个整体，其实不然。这三套生命周期分别是：</p><ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">Clean Lifecycle 在进行真正的构建之前进行一些清理工作。<br /></li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">Default Lifecycle 构建的核心部分，编译，测试，打包，部署等等。<br /></li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">Site Lifecycle 生成项目报告，站点，发布站点。</li></ul><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">我再次强调一下它们是相互独立的，你可以仅仅调用clean来清理工作目录，仅仅调用site来生成站点。当然你也可以直接运行&nbsp;<strong>mvn clean install site</strong>&nbsp;运行所有这三套生命周期。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">知道了每套生命周期的大概用途和相互关系以后，来逐个详细看一下每套生命周期，Clean和Site相对比较简单，先解释一下。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">每套生命周期都由一组阶段(Phase)组成，我们平时在命令行输入的命令总会对应于一个特定的阶段。比如，运行<strong>mvn clean</strong>&nbsp;，这个的clean是Clean生命周期的一个阶段。有点绕？要知道有Clean生命周期，也有clean阶段。Clean生命周期一共包含了三个阶段：</p><ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">pre-clean&nbsp; 执行一些需要在clean之前完成的工作</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">clean&nbsp; 移除所有上一次构建生成的文件</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">post-clean&nbsp; 执行一些需要在clean之后立刻完成的工作</li></ul><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><strong>mvn clean</strong>&nbsp;中的clean就是上面的clean，在一个生命周期中，运行某个阶段的时候，它之前的所有阶段都会被运行，也就是说，<strong>mvn clean</strong>&nbsp;等同于&nbsp;<strong>mvn pre-clean clean</strong>&nbsp;，如果我们运行&nbsp;<strong>mvn post-clean</strong>&nbsp;，那么 pre-clean，clean 都会被运行。这是Maven很重要的一个规则，可以大大简化命令行的输入。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">下面看一下Site生命周期的各个阶段：</p><ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">pre-site &nbsp;&nbsp;&nbsp; 执行一些需要在生成站点文档之前完成的工作</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">site &nbsp;&nbsp; 生成项目的站点文档</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">post-site &nbsp;&nbsp;&nbsp; 执行一些需要在生成站点文档之后完成的工作，并且为部署做准备</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">site-deploy &nbsp;&nbsp;&nbsp; 将生成的站点文档部署到特定的服务器上</li></ul><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">这里经常用到的是site阶段和site-deploy阶段，用以生成和发布Maven站点，这可是Maven相当强大的功能，Manager比较喜欢，文档及统计数据自动生成，很好看。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">最后，来看一下Maven的最重要的Default生命周期，绝大部分工作都发生在这个生命周期中，这里，我只解释一些比较重要和常用的阶段：</p><ul style="margin: 0px 0px 1.5em; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">validate</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">generate-sources</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-sources</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">generate-resources</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-resources &nbsp;&nbsp;&nbsp; 复制并处理资源文件，至目标目录，准备打包。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">compile &nbsp;&nbsp;&nbsp; 编译项目的源代码。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-classes</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">generate-test-sources&nbsp;</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-test-sources&nbsp;<br /></li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">generate-test-resources</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-test-resources &nbsp;&nbsp;&nbsp; 复制并处理资源文件，至目标测试目录。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">test-compile &nbsp;&nbsp;&nbsp; 编译测试源代码。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">process-test-classes</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">test &nbsp;&nbsp;&nbsp; 使用合适的单元测试框架运行测试。这些测试代码不会被打包或部署。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">prepare-package</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">package &nbsp;&nbsp;&nbsp; 接受编译好的代码，打包成可发布的格式，如 JAR 。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">pre-integration-test</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">integration-test</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">post-integration-test</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">verify</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">install &nbsp;&nbsp;&nbsp; 将包安装至本地仓库，以让其它项目依赖。</li><li style="margin: 0px 0px 0.25em 30px; padding: 0px;">deploy &nbsp;&nbsp;&nbsp; 将最终的包复制到远程的仓库，以让其它开发人员与项目共享。</li></ul><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">基本上，根据名称我们就能猜出每个阶段的用途，关于其它阶段的解释，请参考<a href="http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html" style="color: #108ac6;">http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html</a></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">记住，运行任何一个阶段的时候，它前面的所有阶段都会被运行，这也就是为什么我们运行<strong>mvn install</strong>&nbsp;的时候，代码会被编译，测试，打包。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">此外，Maven的插件机制是完全依赖Maven的生命周期的，因此理解生命周期至关重要，在之后的文章里，我将会进一步解释Maven的插件机制。</p><img src ="http://www.blogjava.net/qileilove/aggbug/411608.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-28 14:19 <a href="http://www.blogjava.net/qileilove/articles/411608.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Nexus搭建私服</title><link>http://www.blogjava.net/qileilove/articles/411493.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 26 Mar 2014 05:19:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411493.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411493.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411493.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411493.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411493.html</trackback:ping><description><![CDATA[<p style="margin-bottom:0pt; margin-top:0pt; text-align:center; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; ">Nexus搭建私服</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-align:center; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">首先介绍一下背景，公司访问外网有限制，项目组大部分人员不能访问maven的central&nbsp;repository，因此在局域网里找一台有外网权限的机器，搭建nexus私服，然后开发人员连到这台私服上&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">环境是：nexus-2.1.1、maven-3.0.4、jdk-1.6.0_32&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">一、用admin用户登陆nexus&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">nexus的下载和安装都很简单，网上也有很多介绍，本文就不重复了。主要介绍一下安装之后的配置&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">nexus的配置需要用admin角色完成，默认的密码是admin123，进入nexus首页之后，点击右上角，进行登录&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片1.png" width="221" height="60" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">然后就可以在左边的菜单中进行配置了&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片2.png" width="192" height="513" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">二、为nexus配置代理服务器&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">由于这台机器需要通过代理才能访问外网，所以首先要配置代理服务器，在Administration--&gt;Server中进行配置&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片3.png" width="859" height="454" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">配置之后，nexus才能连上central&nbsp;repository，如果私服所在机器可以直接上外网，则可以省略这一步&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">三、配置repository&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">在Views/Repositories--&gt;Repositories里进行配置&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片4.png" width="1106" height="257" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">nexus里可以配置3种类型的仓库，分别是proxy、hosted、group&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">proxy是远程仓库的代理。比如说在nexus中配置了一个central&nbsp;repository的proxy，当用户向这个proxy请求一个artifact，这个proxy就会先在本地查找，如果找不到的话，就会从远程仓库&nbsp;下载，然后返回给用户，相当于起到一个中转的作用&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">hosted是宿主仓库，用户可以把自己的一些构件，deploy到hosted中，也可以手工上传构件到hosted里。比如说oracle的驱动程序，ojdbc6.jar，在central&nbsp;repository是获取不到的，就需要手工上传到hosted里&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">group是仓库组，在maven里没有这个概念，是nexus特有的。目的是将上述多个仓库聚合，对用户暴露统一的地址，这样用户就不需要在pom中配置多个地址，只要统一配置group的地址就可以了&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">nexus装好之后，已经初始化定义了一些repository，我们熟悉之后，就可以自行删除、新增、编辑&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">右边那个Repository&nbsp;Path可以点击进去，看到仓库中artifact列表。不过要注意浏览器缓存。我今天就发现，明明构件已经更新了，在浏览器里却看不到，还以为是BUG，其实是被浏览器缓存了&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">四、配置Central&nbsp;Repository的proxy&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">最关键的一个配置，可能就是Central&nbsp;Repository的proxy配置，因为大部分的构件，都是要通过这个proxy得到的&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="font-size: 10.5pt; font-family: 'Times New Roman';"><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片5.png" width="1135" height="543" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">在安装完nexus之后，这个proxy是预置的，需要做的就是把Download&nbsp;Remote&nbsp;Indexes改为true，这样nexus才会从central&nbsp;repository下载索引，才能在nexus中使用artifact&nbsp;search的功能&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">网络上有一些其他公开的maven仓库，可以用同样的办法，在nexus中设置proxy，但是并不是所有maven仓库，都提供了nexus&nbsp;index，这种情况下，就无法建立索引了&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">五、配置hosted&nbsp;repository&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">一般会配置3个hosted&nbsp;repository，分别是3rd&nbsp;party、Snapshots、Releases，分别用来保存第三方jar（典型的比如ojdbc6.jar），项目组内部的快照、项目组内部的发布版&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片6.png" width="951" height="538" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">这里并没有什么特别的配置，只是Deployment&nbsp;Policy这个选项，一般Snapshots会配置成允许，而Releases和3rd&nbsp;party会设置为禁止&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">六、配置group&nbsp;repository&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">前面说过，group其实是一个虚拟的仓库，通过对实体仓库（proxy、hosted）进行聚合，对外暴露一个统一的地址&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片7.png" width="859" height="541" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">这里要注意的是，放到左边的仓库，才是会被聚合的仓库。我昨天一直搞错了，把仓库都放到右边，结果group什么都没有聚合到，是一个空的仓库。。。&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">七、配置用户密码&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">在Security--&gt;Users中配置，在deployment用户上点击右键，选择Set&nbsp;Password，然后设置一个密码，做这个操作是为了后面提交做准备&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片8.png" width="1069" height="335" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">八、在用户机器上配置settings.xml&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">经过前面的7个步骤，nexus就配置好了，接下来需要在每个开发人员的开发机器上进行配置了&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">配置文件在%USER_HOME%/.m2/settings.xml&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">Xml代码&nbsp;&nbsp;</span><a><img width="15" height="14" src="file:///C:\DOCUME~1\pccw\LOCALS~1\Temp\ksohtml\wps_clip_image-20587.png"  alt="" /></a></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">1&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">2&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">3&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;settings&nbsp;xmlns="http://maven.apache.org/SETTINGS/1.0.0"&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">4&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">5&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0&nbsp;http://maven.apache.org/xsd/settings-1.0.0.xsd"&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">6&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">7&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;servers&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">8&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">9&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;server&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">10&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;nexus-snapshots&lt;/id&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">11&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;username&gt;deployment&lt;/username&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">12&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;password&gt;deployment&lt;/password&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">13&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/server&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">14&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">15&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;/servers&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">16&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">17&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;mirrors&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">18&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">19&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;mirror&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">20&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;nexus&lt;/id&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">21&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;internal&nbsp;nexus&nbsp;repository&lt;/name&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">22&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url&gt;http://10.78.68.122:9090/nexus-2.1.1/content/groups/public/&lt;/url&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">23&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mirrorOf&gt;central&lt;/mirrorOf&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">24&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mirror&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">25&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">26&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;/mirrors&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">27&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">28&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;/settings&gt;&nbsp;&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">这里只配置了2个元素&lt;mirrors&gt;和&lt;servers&gt;&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">首先这里配置了一个id为nexus的镜像仓库，地址是前面配置的public&nbsp;group的URL，然后镜像目标是central&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">maven里的超级pom，里面配置了这样一段：&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">Xml代码&nbsp;&nbsp;</span><a><img width="15" height="14" src="file:///C:\DOCUME~1\pccw\LOCALS~1\Temp\ksohtml\wps_clip_image-25038.png"  alt="" /></a></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">29&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;repositories&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">30&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;repository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">31&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;central&lt;/id&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">32&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;Central&nbsp;Repository&lt;/name&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">33&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url&gt;http://repo.maven.apache.org/maven2&lt;/url&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">34&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;layout&gt;default&lt;/layout&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">35&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;snapshots&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">36&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;enabled&gt;false&lt;/enabled&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">37&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/snapshots&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">38&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/repository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">39&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;/repositories&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">40&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">41&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;pluginRepositories&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">42&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;pluginRepository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">43&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;central&lt;/id&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">44&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;Central&nbsp;Repository&lt;/name&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">45&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url&gt;http://repo.maven.apache.org/maven2&lt;/url&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">46&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;layout&gt;default&lt;/layout&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">47&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;snapshots&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">48&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;enabled&gt;false&lt;/enabled&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">49&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/snapshots&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">50&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;releases&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">51&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">52&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/releases&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">53&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/pluginRepository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">54&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&lt;/pluginRepositories&gt;&nbsp;&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">因此，当本地的maven项目，找不到需要的构件（包括jar包和插件）的时候，默认会到central里获取&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">所以我们刚刚配置的镜像仓库，id也是central，这样本地maven项目对central&nbsp;repository的请求，就会转到镜像仓库上，也就是我们设置的nexus私服上&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">由于我们在项目的pom里，不会再配置其他的&lt;repositories&gt;和&lt;pluginRepositories&gt;&nbsp;元素，所以只要配置一个central的mirror，就足以阻止所有的外网访问。如果pom中还配置了其他的外网仓库，比如jboss&nbsp;repository等，可以把&lt;mirrorOf&gt;改为*&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">至于&lt;servers&gt;元素，是因为我们把项目内部的构件上传到nexus的仓库中时，nexus会进行权限控制，所以这里需要设置&nbsp;权限相关的信息。注意这里的&lt;id&gt;nexus-snapshots&lt;/id&gt;，和后面maven工程里的pom设置是一致的&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">由于我们这里已经屏蔽了对外网仓库的请求，所以就不需要配置代理服务器了，如果需要配置代理服务器，可以用&lt;proxies&gt;元素&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">九、配置maven项目的pom文件&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">下面是简化后的pom文件：&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">Xml代码&nbsp;&nbsp;</span><a><img width="15" height="14" src="file:///C:\DOCUME~1\pccw\LOCALS~1\Temp\ksohtml\wps_clip_image-26428.png"  alt="" /></a></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">55&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;project&nbsp;xmlns="http://maven.apache.org/POM/4.0.0"&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">56&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="http://maven.apache.org/POM/4.0.0&nbsp;http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">57&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">58&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">59&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;com.huawei.inoc.wfm.task&lt;/groupId&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">60&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;task-sla&lt;/artifactId&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">61&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">62&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;task-sla&lt;/name&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">63&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">64&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;配置部署的远程仓库&nbsp;--&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">65&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;distributionManagement&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">66&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;snapshotRepository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">67&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;nexus-snapshots&lt;/id&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">68&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;nexus&nbsp;distribution&nbsp;snapshot&nbsp;repository&lt;/name&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">69&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url&gt;http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/&lt;/url&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">70&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/snapshotRepository&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">71&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/distributionManagement&gt;&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">72&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&nbsp;&nbsp;</span></p><p style="margin-left:18.0000pt; margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; "><span style="font-size:10.5000pt; font-family:'Symbol'; ">73&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">&lt;/project&gt;&nbsp;&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">这里配置了&lt;distributionManagement&gt;元素，其中的&lt;id&gt;nexus-snapshots&lt;/id&gt;，与前面说的settings.xml中的&lt;servers&gt;元素中的配置必须一致&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">配置这个的目的，是当执行maven&nbsp;deploy时，才知道要将生成的构件部署到哪个远程仓库上，注意这里的URL填的就不是public&nbsp;group的地址：&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">http://10.78.68.122:9090/nexus-2.1.1/content/groups/public/&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">而是snapshots的地址：&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">http://10.78.68.122:9090/nexus-2.1.1/content/repositories/snapshots/&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">但是在nexus中，snapshots也是聚合到public&nbsp;group里的，所以开发人员A提交到snapshots的构件，开发人员B也可以从public&nbsp;group里获取到&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">十、eclipse中的设置&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">经过前面的配置，已经可以通过命令行进行maven操作了。不过实际开发中，一般都是使用eclipse的m2e插件，所以还需要对eclipse进行一些额外的配置&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">在Preferences--&gt;Maven--&gt;User&nbsp;Settings中，点击Update&nbsp;Settings，加载刚才我们对settings.xml的更改&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片9.png" width="634" height="745" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">然后在Maven&nbsp;Repositories视图里，可以看到仓库的情况&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片10.png" width="797" height="226" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">可以看到，从超级pom继承来的central被置灰了，不可用，后面的mirrored&nbsp;by&nbsp;nexus表示对该仓库的所有请求，都会转到镜像nexus中&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">十一、nexus的目录结构&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">nexus会安装在%USER_HOME%/sonatype-work/nexus下，有以下目录&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><img src="http://www.blogjava.net/images/blogjava_net/qileilove/图片11.png" width="623" height="228" alt="" /><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; "><br /></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Times New Roman'; ">其中的storage目录，就是构件实际存放的地址了&nbsp;</span></p><img src ="http://www.blogjava.net/qileilove/aggbug/411493.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-26 13:19 <a href="http://www.blogjava.net/qileilove/articles/411493.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven3实战之仓库(快照版本)</title><link>http://www.blogjava.net/qileilove/articles/411491.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 26 Mar 2014 05:01:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411491.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411491.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411491.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411491.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411491.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">maven3实战之仓库(快照版本)</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">----------</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">在Maven的世界中，任何一个项目或者构件都必须有自己的版本。版本的值可能是1.0.0,1.3-alpha-4,2.0,2.1-SNAPSHOT或者2.1-20091214.221414-13。其中，1.0、1.3-alpha-4和2.0是稳定的发布版本，而2.1-SNAPSHOT和2.1-20091214.221414-13是不稳定的快照版本。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven为什么要区分发布版本和快照版本呢？简单的1.0.0、1.2、2.1等不就够了吗？为什么还要2.1-SNAPSHOT，甚至是长长的2.1-20091214.221414-13？试想一下这样的情况，小张在开发模块A的2.1版本，该版本还未正式发布，与模块A一同开发的还有模块B，它由小张的同事季MM开发，B的功能依赖于A。在开发的过程中，小张需要经常将自己最新的构建输出，交给季MM，供她开发和集成调试，问题是，这个工作如何进行呢？</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">如果不停更新版本2.1.1、2.1.2、2.1.3....呢？首先，小张和季MM两人都需要频繁地更改POM，如果有更多的模块依赖于模块A，就会涉及更多的POM更改；其次，大量的版本其实仅仅包含了微小的差异，这样也会造成为版本号的滥用。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven的快照版本机制就是为了解决上述问题。在该例中，<span style="color: #0000ff;">小张只需要将模块A的版本设定为2.1-SNAPSHOT，然后发布到私服中，在发布的过程中，Maven会自动为构件打上时间戳</span>。比如:2.1-20091214.221414-13就表示2009年12月14日&nbsp;22点14分14秒的第13次快照。有了该时间戳，Maven就能随时找到仓库中该构件2.1-SNAPSHOT版本最新的文件。这时，季MM配置对于模块A的2.1-SNAPSHOT版本的依赖，当她构件模块B的时候，<span style="color: #0000ff;">Maven会自动从仓库中检查模块A的2.1-SNAPSHOT的最新构件，当发现有更新时便进行下载</span>。默认情况下，Maven每天检查一次更新(由仓库配置的updatePolicy控制)，<span style="color: #ff0000;">用户也可以使用命令行-U参数强制让Maven检查更新，如：mvn clean install-U</span>。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">基于快照版本机制，小张在构建成功之后才能将构件部署至仓库，而季MM可以完全不用考虑模块A的构建，并且她能确保随时得到模块A的最新可用的快照构件，而这一切都不需要额外的手工操作。</p><img src ="http://www.blogjava.net/qileilove/aggbug/411491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-26 13:01 <a href="http://www.blogjava.net/qileilove/articles/411491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven3实战之仓库(远程仓库的配置)</title><link>http://www.blogjava.net/qileilove/articles/411460.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 25 Mar 2014 09:00:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411460.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411460.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411460.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411460.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411460.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">maven3实战之仓库(远程仓库的配置)</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">----------</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">在很多情况下，默认的中央仓库无法满足项目的需求，可能项目需要的构件存在于另外一个远程仓库中，如:JBoss，Maven仓库。这时，可以在POM中配置该仓库，见代码请单：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #620091; text-decoration: underline;"><img src="http://fhd001.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">project</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">repositories</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">repository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>jboss<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>JBoss&nbsp;Repository<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>http://repository.jboss.com/maven2/<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">releases</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>true<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">releases</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">repository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">snapshots</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>false<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">snapshots</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">layout</span><span style="color: #006699; font-weight: bold;">&gt;</span>default<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">layout</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">repositories</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">project</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">在repositories元素下，可以<span style="color: #0000ff;">使用repository子元素声明一个或者多个远程仓库</span>。该例中声明了一个id为jboss，名称为JBoss Repository的仓库。任何一个仓库声明的<span style="color: #0000ff;">id必须是唯一的，尤其需要注意的是，maven自带的中央仓库使用的id为central，如果其他的仓库声明也使用该id，就会覆盖中央仓库的配置</span>。该配置中的url值指向了仓库的地址，一般来说，该地址都基于http协议，maven用户都可以在浏览器中打开仓库地址浏览构件。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">该例配置中的<span style="color: #0000ff;">releases和snapshots元素</span>比较重要，它们用来控制Maven对于发布版构件和快照版构件的下载。该例中<span style="color: #0000ff;">releases的enabled值为true，表示开启JBoss仓库的发布版本下载支持，而snapshots的enabled值为false，表示</span><span style="color: #0000ff;">关闭JBoss仓库的快照版本的下载支持</span>。<span style="color: #0000ff;">该例中的layout元素值default表示仓库的布局是Maven2及Maven3的默认布局，而不是Maven1的布局</span>。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">对于releases和snapshots来说，除了enabled，它们还包含<span style="color: #0000ff;">另外两个子元素updatePolicy和checksumPolicy</span>:</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #620091; text-decoration: underline;"><img src="http://fhd001.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">snapshots</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>true<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">enabled</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">updatePolicy</span><span style="color: #006699; font-weight: bold;">&gt;</span>daily<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">updatePolicy</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">checksumPolicy</span><span style="color: #006699; font-weight: bold;">&gt;</span>ignore<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">checksumPolicy</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">snapshots</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="color: #0000ff;">元素updatePolicy用来配置Maven从远程仓库检查更新的频率，默认的值是daily，表示Maven每天检查一次。其他可用的值包括：never---从不检查更新；always---每次构建都检查更新；interval:X---每隔X分钟检查一次更新(X为任意整数)。</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="color: #0000ff;">元素checksumPolicy用来配置Maven检查检验和文件的策略。当构件被部署到Maven仓库中时，会同时部署对应的校验</span><span style="color: #0000ff;">和文件。在下载构件的时候，Maven会验证校验和文件，如果校验和验证失败，怎么办？当checksumPolicy的值为默认的warn时，Maven会在执行构建时输出警告信息，其他可用的值包括：fail---Maven遇到校验和错误就让构建失败；ignore---使用Maven完全忽略校验和错误</span>。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">1.<span style="color: #ff0000;">远程仓库的认证</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">大部分远程仓库无须认证就可以访问，但有时候出于安全方面的考虑，我们需要提认证信息才能访问一些远程仓库。例如，组织内部有一个Maven仓库服务器，该服务器为每个项目都提供独立的Maven仓库，为了防止非法的仓库访问，管理员为每个仓库提供了一组用户名级密码。这时，为了能让Maven访问仓库内容，就需要配置认证信息。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="color: #0000ff;">配置认证信息和配置仓库信息不同，仓库信息可以直接配置在POM文件中，但是认证信息必须配置在settings.xml</span><span style="color: #0000ff;">文件中</span>。这是因为POM往往是被提交到代码仓库中供所有成员访问的，而settings.xml一般只放在本机。因此，<span style="color: #0000ff;">settings.xml中配置认证信息更为安全</span>。假设需要为一个id为my-proj的仓库配置认证信息，编辑settings.xml文件见代码清单：&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #620091; text-decoration: underline;"><img src="http://fhd001.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">settings</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">servers</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">server</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>my-proj<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">username</span><span style="color: #006699; font-weight: bold;">&gt;</span>repo-user<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">username</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">password</span><span style="color: #006699; font-weight: bold;">&gt;</span>repo-pwd<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">password</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">server</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">servers</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">settings</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven使用settings.xml文件中并不显而易见的servers元素及其server子元素配置仓库认证信息。上例中，仓库的认证用户名为repo-user，认证密码为repo-pwd。这里的关键是id元素，<span style="color: #0000ff;">settings.xml中server元素的id必须与POM中需要认证的repository元素的id完全一致</span>。换句话说，正是这个Id将认证信息与仓库配置联系在了一起。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">2.<span style="color: #ff0000;">部署至远程仓库</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">私服的一大作用是部署第三方构件，包括组织内部生成的构件以及一些无法从外部仓库直接获取的构件。无论是日常开发中生成的构件，还是正式版本发布的构件，都需要部署到仓库中，供其他团队成员使用。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">Maven除了能对项目进行编译、测试、打包之外，<span style="color: #0000ff;">还能将项目生成的构建部署到仓库中</span>。首先，需要编辑项目的pom.xml文件。<span style="color: #0000ff;">配置distributionManagement元素</span>，见代码：</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #620091; text-decoration: underline;"><img src="http://fhd001.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">project</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">destributionManagement</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">repository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>proj-releases<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>Proj&nbsp;Release&nbsp;Repository<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>http://192.168.1.100/content/repositories/proj-releases<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">repository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">snapshotRepository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>proj-snapshots<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">id</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>Proj&nbsp;Snapshot&nbsp;Repository<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">name</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>http://192.168.1.100/content/repositories/proj-snapshots<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">url</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">snapshotRepository</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">destributionManagement</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">project</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="color: #0000ff;">distributionManagement包含repository和snapshotRepository子元素，前者表示发布版本构件的仓库，后者表示</span><span style="color: #0000ff;">快照版本的仓库</span>。这两个元素下都需要配置id、name和url，id为该远程仓库的唯一标识，name是为了方便人阅读，关键的url表示该仓库的地址。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">往远程仓库部署构件的时候，往往需要认证。就是需要在settings.xml中创建一个server元素，其id与仓库的id匹配，并配置正确的认证信息。不论远程仓库下载构件，还是部署构件至远程仓库，当需要认证的时候，配置的方式是一样的。配置正确后，<span style="color: #ff0000;">在命令行运行mvn clean deploy</span>，Maven就会将项目构建输出的构件部署到配置对应的远程仓库，如果项目当前的版本是快照版本，则部署到快照版本仓库地址，否则就部署到发布版本仓库地址。</p><img src ="http://www.blogjava.net/qileilove/aggbug/411460.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-25 17:00 <a href="http://www.blogjava.net/qileilove/articles/411460.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven仓库</title><link>http://www.blogjava.net/qileilove/articles/411427.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 24 Mar 2014 09:21:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411427.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411427.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411427.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411427.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411427.html</trackback:ping><description><![CDATA[<h4>什么是Maven仓库</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">在不用Maven的时候，比如说以前我们用Ant构建项目，在项目目录下，往往会看到一个名为/lib的子目录，那里存放着各类第三方依赖jar文件，如log4j.jar，junit.jar等等。每建立一个项目，你都需要建立这样的一个/lib目录，然后复制一对jar文件，这是很明显的重复。重复永远是噩梦的起点，多个项目不共用相同的jar文件，不仅会造成磁盘资源的浪费，也使得版本的一致性管理变得困难。此外，如果你使用版本管理工具，如SVN（你没有使用版本管理工具？马上试试SVN吧，它能帮你解决很多头疼的问题），你需要将大量的jar文件提交到代码库里，可是版本管理工具在处理二进制文件方面并不出色。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Maven仓库就是放置所有JAR文件（WAR，ZIP，POM等等）的地方，所有Maven项目可以从同一个Maven仓库中获取自己所需要的依赖JAR，这节省了磁盘资源。此外，由于Maven仓库中所有的JAR都有其自己的坐标，该坐标告诉Maven它的组ID，构件ID，版本，打包方式等等，因此Maven项目可以方便的进行依赖版本管理。你也不在需要提交JAR文件到SCM仓库中，你可以建立一个组织层次的Maven仓库，供所有成员使用。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">简言之，Maven仓库能帮助我们管理构件（主要是JAR）。</p><h4><a name="t1" style="color: rgb(51, 102, 153);"></a>本地仓库 vs. 远程仓库</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">运行Maven的时候，Maven所需要的任何构件都是直接从本地仓库获取的。如果本地仓库没有，它会首先尝试从远程仓库下载构件至本地仓库，然后再使用本地仓库的构件。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">比如说，你的项目配置了junit-3.8的依赖，在你运行<strong>mvn test</strong>&nbsp;的时候，Maven需要使用junit-3.8的jar文件，它首先根据坐标查找本地仓库，如果找到，就直接使用。如果没有，Maven会检查可用的远程仓库配置，然后逐个尝试这些远程仓库去下载junit-3.8的jar文件，如果远程仓库存在该文件，Maven会将其下载到本地仓库中，继而使用。如果尝试过所有远程仓库之后，Maven还是没能够下载到该文件，它就会报错。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Maven缺省的本地仓库地址为<em>${user.home}/.m2/repository</em>&nbsp;。也就是说，一个用户会对应的拥有一个本地仓库。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">你也可以自定义本地仓库的位置，修改<em>${user.home}/.m2/settings.xml</em>&nbsp;：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;settings&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;</li><li><strong>&lt;localRepository&gt;</strong>D:/java/repository<strong>&lt;/localRepository&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;</li><li><strong>&lt;/settings&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">你还可以在运行时指定本地仓库位置：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><strong>mvn clean install -Dmaven.repo.local=/home/juven/myrepo/</strong></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">还有一点需要理解的是，当我们运行install的时候，Maven实际上是将项目生成的构件安装到了本地仓库，也就是说，只有install了之后，其它项目才能使用此项目生成的构件。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">了解了本地仓库，接着了解一下Maven缺省的远程仓库，即Maven中央仓库。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">安装好Maven之后，我们可以建立一个简单的项目，配置一些简单的依赖，然后运行mvn clean install，项目就构建好了。我们没有手工的去下载任何jar文件，这一切都是因为Maven中央仓库的存在，当Maven在本地仓库找不到需要的jar文件时，它会查找远程仓库，而一个原始的Maven安装就自带了一个远程仓库&#8212;&#8212;Maven中央仓库。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">这个Maven中央仓库是在哪里定义的呢？在我的机器上，我安装了maven-2.0.10，我可以找到这个文件：<em>${M2_HOME}/lib/maven-2.0.10-uber.jar</em>&nbsp;，打开该文件，能找到超级POM：<em>/org/apache/maven/project/pom-4.0.0.xml</em>&nbsp;，它是所有Maven POM的父POM，所有Maven项目继承该配置，你可以在这个POM中发现如下配置：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;repositories&gt;</strong></li><li><strong>&lt;repository&gt;</strong></li><li><strong>&lt;id&gt;</strong>central<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Maven Repository Switchboard<strong>&lt;/name&gt;</strong></li><li><strong>&lt;layout&gt;</strong>default<strong>&lt;/layout&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://repo1.maven.org/maven2<strong>&lt;/url&gt;</strong></li><li><strong>&lt;snapshots&gt;</strong></li><li><strong>&lt;enabled&gt;</strong>false<strong>&lt;/enabled&gt;</strong></li><li><strong>&lt;/snapshots&gt;</strong></li><li><strong>&lt;/repository&gt;</strong></li><li><strong>&lt;/repositories&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">关于远程仓库的配置，下面的小节我会详细解释，这里我们只要知道，中央仓库的id为central，远程url地址为http://repo1.maven.org/maven2，它关闭了snapshot版本构件下载的支持。</p><h4><a name="t2" style="color: rgb(51, 102, 153);"></a>在POM中配置远程仓库</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">前面我们看到超级POM配置了ID为central的远程仓库，我们可以在POM中配置其它的远程仓库。这样做的原因有很多，比如你有一个局域网的远程仓库，使用该仓库能大大提高下载速度，继而提高构建速度，也有可能你依赖的一个jar在central中找不到，它只存在于某个特定的公共仓库，这样你也不得不添加那个远程仓库的配置。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">这里我配置一个远程仓库指向中央仓库的中国镜像：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;project&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;repositories&gt;</strong></li><li><strong>&lt;repository&gt;</strong></li><li><strong>&lt;id&gt;</strong>maven-net-cn<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Maven China Mirror<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://maven.net.cn/content/groups/public/<strong>&lt;/url&gt;</strong></li><li><strong>&lt;releases&gt;</strong></li><li><strong>&lt;enabled&gt;</strong>true<strong>&lt;/enabled&gt;</strong></li><li><strong>&lt;/releases&gt;</strong></li><li><strong>&lt;snapshots&gt;</strong></li><li><strong>&lt;enabled&gt;</strong>false<strong>&lt;/enabled&gt;</strong></li><li><strong>&lt;/snapshots&gt;</strong></li><li><strong>&lt;/repository&gt;</strong></li><li><strong>&lt;/repositories&gt;</strong></li><li><strong>&lt;pluginRepositories&gt;</strong></li><li><strong>&lt;pluginRepository&gt;</strong></li><li><strong>&lt;id&gt;</strong>maven-net-cn<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Maven China Mirror<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://maven.net.cn/content/groups/public/<strong>&lt;/url&gt;</strong></li><li><strong>&lt;releases&gt;</strong></li><li><strong>&lt;enabled&gt;</strong>true<strong>&lt;/enabled&gt;</strong></li><li><strong>&lt;/releases&gt;</strong></li><li><strong>&lt;snapshots&gt;</strong></li><li><strong>&lt;enabled&gt;</strong>false<strong>&lt;/enabled&gt;</strong></li><li><strong>&lt;/snapshots&gt;</strong></li><li><strong>&lt;/pluginRepository&gt;</strong></li><li><strong>&lt;/pluginRepositories&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;/project&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">我们先看一下&lt;repositories&gt;的配置，你可以在它下面添加多个&lt;repository&gt; ，每个&lt;repository&gt;都有它唯一的ID，一个描述性的name，以及最重要的，远程仓库的url。此外，&lt;releases&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/releases&gt;告诉Maven可以从这个仓库下载releases版本的构件，而&lt;snapshots&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;/snapshots&gt;告诉Maven不要从这个仓库下载snapshot版本的构件。禁止从公共仓库下载snapshot构件是推荐的做法，因为这些构件不稳定，且不受你控制，你应该避免使用。当然，如果你想使用局域网内组织内部的仓库，你可以激活snapshot的支持。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">关于&lt;repositories&gt;的更详细的配置及相关解释，请参考：http://www.sonatype.com/books/maven-book/reference_zh/apas02s08.html。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">至于&lt;pluginRepositories&gt;，这是配置Maven从什么地方下载插件构件（Maven的所有实际行为都由其插件完成）。该元素的内部配置和&lt;repository&gt;完全一样，不再解释。</p><h4><a name="t3" style="color: rgb(51, 102, 153);"></a>在settings.xml中配置远程仓库</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">我们知道了如何在POM中配置远程仓库，但考虑这样的情况：在一个公司内部，同时进行这3个项目，而且以后随着这几个项目的结束，越来越多的项目会开始；同时，公司内部建立一个Maven仓库。我们统一为所有这些项目配置该仓库，于是不得不为每个项目提供同样的配置。问题出现了，这是<em>重复</em>&nbsp;！</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">其实我们可以做到只配置一次，在哪里配置呢？就是settings.xml。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">不过事情没有那么简单，不是简单的将POM中的&lt;repositories&gt;及&lt;pluginRepositories&gt;元素复制到settings.xml中就可以，setting.xml<em>不直接支持</em>&nbsp;这两个元素。但我们还是有一个并不复杂的解决方案，就是利用profile，如下：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;settings&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;</li><li><strong>&lt;profiles&gt;</strong></li><li><strong>&lt;profile&gt;</strong></li><li><strong>&lt;id&gt;</strong>dev<strong>&lt;/id&gt;</strong></li><li>&lt;!-- repositories and pluginRepositories here--&gt;</li><li><strong>&lt;/profile&gt;</strong></li><li><strong>&lt;/profiles&gt;</strong></li><li><strong>&lt;activeProfiles&gt;</strong></li><li><strong>&lt;activeProfile&gt;</strong>dev<strong>&lt;/activeProfile&gt;</strong></li><li><strong>&lt;/activeProfiles&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;</li><li><strong>&lt;/settings&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">这里我们定义一个id为dev的profile，将所有repositories以及pluginRepositories元素放到这个profile中，然后，使用&lt;activeProfiles&gt;元素自动激活该profile。这样，你就不用再为每个POM重复配置仓库。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">使用profile为settings.xml添加仓库提供了一种用户全局范围的仓库配置。</p><h4><a name="t4" style="color: rgb(51, 102, 153);"></a>镜像</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">如果你的地理位置附近有一个速度更快的central镜像，或者你想覆盖central仓库配置，或者你想为所有POM使用唯一的一个远程仓库（这个远程仓库代理的所有必要的其它仓库），你可以使用settings.xml中的mirror配置。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">以下的mirror配置用maven.net.cn覆盖了Maven自带的central：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;settings&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;mirrors&gt;</strong></li><li><strong>&lt;mirror&gt;</strong></li><li><strong>&lt;id&gt;</strong>maven-net-cn<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Maven China Mirror<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://maven.net.cn/content/groups/public/<strong>&lt;/url&gt;</strong></li><li><strong>&lt;mirrorOf&gt;</strong>central<strong>&lt;/mirrorOf&gt;</strong></li><li><strong>&lt;/mirror&gt;</strong></li><li><strong>&lt;/mirrors&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;/settings&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">这里唯一需要解释的是&lt;mirrorOf&gt;，这里我们配置central的镜像，我们也可以配置一个所有仓库的镜像，以保证该镜像是Maven唯一使用的仓库：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;settings&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;mirrors&gt;</strong></li><li><strong>&lt;mirror&gt;</strong></li><li><strong>&lt;id&gt;</strong>my-org-repo<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Repository in My Orgnization<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://192.168.1.100/maven2<strong>&lt;/url&gt;</strong></li><li><strong>&lt;mirrorOf&gt;</strong>*<strong>&lt;/mirrorOf&gt;</strong></li><li><strong>&lt;/mirror&gt;</strong></li><li><strong>&lt;/mirrors&gt;</strong></li><li>...&nbsp;&nbsp;</li><li><strong>&lt;/settings&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">关于更加高级的镜像配置，可以参考：http://maven.apache.org/guides/mini/guide-mirror-settings.html。</p><h4><a name="t5" style="color: rgb(51, 102, 153);"></a>分发构件至远程仓库</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><strong>mvn install</strong>&nbsp;会将项目生成的构件安装到本地Maven仓库，<strong>mvn deploy</strong>&nbsp;用来将项目生成的构件分发到远程Maven仓库。本地Maven仓库的构件只能供当前用户使用，在分发到远程Maven仓库之后，所有能访问该仓库的用户都能使用你的构件。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">我们需要配置POM的distributionManagement来指定Maven分发构件的位置，如下：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;project&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;&nbsp;&nbsp;</li><li><strong>&lt;distributionManagement&gt;</strong></li><li><strong>&lt;repository&gt;</strong></li><li><strong>&lt;id&gt;</strong>nexus-releases<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Nexus Release Repository<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://127.0.0.1:8080/nexus/content/repositories/releases/<strong>&lt;/url&gt;</strong></li><li><strong>&lt;/repository&gt;</strong></li><li><strong>&lt;snapshotRepository&gt;</strong></li><li><strong>&lt;id&gt;</strong>nexus-snapshots<strong>&lt;/id&gt;</strong></li><li><strong>&lt;name&gt;</strong>Nexus Snapshot Repository<strong>&lt;/name&gt;</strong></li><li><strong>&lt;url&gt;</strong>http://127.0.0.1:8080/nexus/content/repositories/snapshots/<strong>&lt;/url&gt;</strong></li><li><strong>&lt;/snapshotRepository&gt;</strong></li><li><strong>&lt;/distributionManagement&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;&nbsp;&nbsp;</li><li><strong>&lt;/project&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Maven区别对待release版本的构件和snapshot版本的构件，snapshot为开发过程中的版本，实时，但不稳定，release版本则比较稳定。Maven会根据你项目的版本来判断将构件分发到哪个仓库。</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">一般来说，分发构件到远程仓库需要认证，如果你没有配置任何认证信息，你往往会得到401错误。这个时候，如下在settings.xml中配置认证信息：</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Xml代码</p><ol style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><li><strong>&lt;settings&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;&nbsp;&nbsp;</li><li><strong>&lt;servers&gt;</strong></li><li><strong>&lt;server&gt;</strong></li><li><strong>&lt;id&gt;</strong>nexus-releases<strong>&lt;/id&gt;</strong></li><li><strong>&lt;username&gt;</strong>admin<strong>&lt;/username&gt;</strong></li><li><strong>&lt;password&gt;</strong>admin123<strong>&lt;/password&gt;</strong></li><li><strong>&lt;/server&gt;</strong></li><li><strong>&lt;server&gt;</strong></li><li><strong>&lt;id&gt;</strong>nexus-snapshots<strong>&lt;/id&gt;</strong></li><li><strong>&lt;username&gt;</strong>admin<strong>&lt;/username&gt;</strong></li><li><strong>&lt;password&gt;</strong>admin123<strong>&lt;/password&gt;</strong></li><li><strong>&lt;/server&gt;</strong></li><li><strong>&lt;/servers&gt;</strong></li><li>&nbsp; ...&nbsp;&nbsp;&nbsp;&nbsp;</li><li><strong>&lt;/settings&gt;</strong></li></ol><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">需要注意的是，settings.xml中server元素下id的值必须与POM中repository或snapshotRepository下id的值完全一致。将认证信息放到settings下而非POM中，是因为POM往往是它人可见的，而settings.xml是本地的。</p><h4><a name="t6" style="color: rgb(51, 102, 153);"></a>小结</h4><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">本文介绍了Maven仓库，它是什么？本地仓库，远程仓库，中央仓库具体是指什么？并介绍了如何在POM中配置项目层次的仓库，在settings中配置用户层次的仓库，以及mirror。本文还介绍了如何安装构件到本地仓库，如何分发构件至仓库。</p><img src ="http://www.blogjava.net/qileilove/aggbug/411427.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-24 17:21 <a href="http://www.blogjava.net/qileilove/articles/411427.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven实战（六）依赖</title><link>http://www.blogjava.net/qileilove/articles/411279.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 20 Mar 2014 06:15:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411279.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411279.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411279.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411279.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411279.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 我们项目中用到的jar包可以通过依赖的方式引入，构建项目的时候从Maven仓库下载即可。&nbsp;1. 依赖配置&nbsp;&nbsp;&nbsp; 依赖可以声明如下：&nbsp;&nbsp;&nbsp;Xml代码&nbsp;&nbsp;&lt;project&gt;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependenci...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/articles/411279.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/411279.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-20 14:15 <a href="http://www.blogjava.net/qileilove/articles/411279.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven坐标</title><link>http://www.blogjava.net/qileilove/articles/411164.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 18 Mar 2014 02:52:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411164.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411164.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411164.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411164.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">Maven 坐标有groupId,artifactId,packaging,version,classifier</p><div bg_html"="" style="width: 936.3368530273438px; line-height: 26px;"><div><div style="border-left-color: #999999;"><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/java2000_wl/article/details/7748439#" title="view plain">view plain</a><a href="http://blog.csdn.net/java2000_wl/article/details/7748439#" title="copy">copy</a><a href="http://blog.csdn.net/java2000_wl/article/details/7748439#" title="print">print</a><a href="http://blog.csdn.net/java2000_wl/article/details/7748439#" title="?">?</a><div style="position: absolute; left: 570px; top: 494px; width: 32px; height: 16px; z-index: 99;"></div></div></div><ol start="1"><li style="border-left-color: #999999; line-height: 20px;"><span style="color: blue; font-weight: bold;">&lt;</span><span style="color: blue; font-weight: bold;">groupId</span><span style="color: blue; font-weight: bold;">&gt;</span>com.x<span style="color: blue; font-weight: bold;">&lt;/</span><span style="color: blue; font-weight: bold;">groupId</span><span style="color: blue; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="border-left-color: #999999; color: #555555; line-height: 20px;"><span style="color: blue; font-weight: bold;">&lt;</span><span style="color: blue; font-weight: bold;">artifactId</span><span style="color: blue; font-weight: bold;">&gt;</span>helloworld-1<span style="color: blue; font-weight: bold;">&lt;/</span><span style="color: blue; font-weight: bold;">artifactId</span><span style="color: blue; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="border-left-color: #999999; line-height: 20px;"><span style="color: blue; font-weight: bold;">&lt;</span><span style="color: blue; font-weight: bold;">packaging</span><span style="color: blue; font-weight: bold;">&gt;</span>jar<span style="color: blue; font-weight: bold;">&lt;/</span><span style="color: blue; font-weight: bold;">packaging</span><span style="color: blue; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="border-left-color: #999999; color: #555555; line-height: 20px;"><span style="color: blue; font-weight: bold;">&lt;</span><span style="color: blue; font-weight: bold;">version</span><span style="color: blue; font-weight: bold;">&gt;</span>0.0.1-SNAPSHOT<span style="color: blue; font-weight: bold;">&lt;/</span><span style="color: blue; font-weight: bold;">version</span><span style="color: blue; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; (1).groupId,定义当前maven项目隶属的实际项目。首先，maven项目和实际项目不一定是一对一的关系。比如SpringFramework这一实际项目，其对应的maven项目会有很&nbsp;&nbsp;多，如: spring-core，spring-context等。这是由于maven中模块的概念，因此，一个实际项目往往会被划分成很多模块。其次，groupId不应该对应项目隶属的组织或公司。原因很简单，一个组织下会有很多个实际项目，如果groupId只定义到组织级别，而后面我们会看到，artifactId只能定义maven项目(模块),那么实际项目这个层将难以定义。最后，groupId的表示方式与java包名的表示方式类似，通常与域名反向一一对应。&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; (2).artifactId,该元素定义实际项目中的一个maven项目(模块),推荐的做法是使用实际项目名称作为artifactId前缀，这样做的好处是方便寻找实际构件。在默认情况下，maven生成的构件，其文件名会以artifactId作为开头，如:helloworld-1-0.0.1-SNAPSHOT.jar，使用实际项目名称作为前缀之后，就能方便从一个lib文件夹中找到某个项目的一组构件。。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; (3).version,该元素定义maven项目当前所处的版本，如：helloworld-1-0.0.1-SNAPSHOT.jar的版本是0.0.1。需要注意的是，maven定义了一套完整的版本规范，以及快照(SNAPSHOT)的概念。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; (4).packaging, 定义了maven项目的打包方式。默认值为jar，可取值：<tt>ejb</tt>&nbsp;/&nbsp;<tt>ejb3</tt>&nbsp;/<tt>jar</tt>&nbsp;/&nbsp;<tt>par</tt>&nbsp;/&nbsp;<tt>rar</tt>&nbsp;/&nbsp;<tt>war</tt>。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;&nbsp; (5).classifier,该元素用来帮助定义构建输出的一些附属构件。附属构件与主构件对应，如上例中的主构件是: nexus-indexer-2.0.0.jar，该项目可能还会通过使用一些插件生成如：helloworld-1-0.0.1-SNAPSHOT-javadoc.jar、helloworld-1-0.0.1-SNAPSHOT-sources.jar这样一些附属构件，其包含了java文档和源代码。这时候，javadoc和sources就是这两个附属构件的classifier。这样，附属构件也就拥有了自己唯一的坐标。</p><p style="margin: 0px; padding: 0px; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&nbsp;项目构件的文件名是与坐标相对应, 规则为:&nbsp;<strong><span style="color: #ff6666;">artifactId-version[-classifier].packaging</span></strong>，[-classifier]为可选。</p><img src ="http://www.blogjava.net/qileilove/aggbug/411164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-18 10:52 <a href="http://www.blogjava.net/qileilove/articles/411164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven学习之 搭建多模块企业级项目</title><link>http://www.blogjava.net/qileilove/articles/411136.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 17 Mar 2014 03:50:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411136.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411136.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411136.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411136.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411136.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 首先，前面几次学习已经学会了安装maven，如何创建maven项目等，最近的学习，终于有点进展了，搭建一下企业级多模块项目。好了，废话不多说，具体如下：首先新建一个maven项目，pom.xml的文件如下：搭建多模块项目，必须要有一个packaging为pom的根目录。创建好这个maven项目后，我们对着项目右键--&gt;new输入你的项目名称这里就不重复说创建项目了，创建好的目录结构在ecli...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/articles/411136.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/411136.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-17 11:50 <a href="http://www.blogjava.net/qileilove/articles/411136.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NetBeans Maven插件简单使用 </title><link>http://www.blogjava.net/qileilove/articles/411037.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 14 Mar 2014 06:03:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/411037.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/411037.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/411037.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/411037.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/411037.html</trackback:ping><description><![CDATA[<h2>3.7 NetBeans Maven插件简单使用&nbsp;</h2><div style="margin: 0px; color: #333333; font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 22.5px; background-color: #ffffff;"><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><span style="padding: 0px; margin: 0px;">NetBeans</span>的<span style="padding: 0px; margin: 0px;">Maven</span>插件也十分简单易用，我们可以轻松地在<span style="padding: 0px; margin: 0px;">NetBeans</span>中导入现有的<span style="padding: 0px; margin: 0px;">Maven</span>项目，或者使用<span style="padding: 0px; margin: 0px;">Archetype</span>创建<span style="padding: 0px; margin: 0px;">Maven</span>项目，我们也能够在<span style="padding: 0px; margin: 0px;">NetBeans</span>中直接运行<span style="padding: 0px; margin: 0px;">mvn</span>命令。</p><h2><span style="padding: 0px; margin: 0px;">3.7.1&nbsp;</span>打开<span style="padding: 0px; margin: 0px;">Maven</span>项目</h2><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">与其说<span style="padding: 0px; margin: 0px; font-weight: 600;">打开</span><span style="padding: 0px; margin: 0px;">Maven</span>项目，不如称之为<span style="padding: 0px; margin: 0px; font-weight: 600;">导入</span>更为合适，因为这个项目不需要是<span style="padding: 0px; margin: 0px;">NetBeans</span>创建的<span style="padding: 0px; margin: 0px;">Maven</span>项目，不过这里我们还是遵照<span style="padding: 0px; margin: 0px;">NetBeans</span>菜单中使用的名称。</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">选择菜单栏中的<span style="padding: 0px; margin: 0px; font-weight: 600;">文件</span>，然后选择<span style="padding: 0px; margin: 0px; font-weight: 600;">打开项目</span>，直接定位到<span style="padding: 0px; margin: 0px;">Hello World</span>项目的根目录，<span style="padding: 0px; margin: 0px;">NetBeans</span>会十分智能地识别出<span style="padding: 0px; margin: 0px;">Maven</span>项目，如图<span style="padding: 0px; margin: 0px;">3-6</span>所示：</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><br style="padding: 0px; margin: 0px;" /><a href="http://static.oschina.net/uploads/img/201305/10104518_2QHm.jpg" target="_blank" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;"><img src="http://static.oschina.net/uploads/img/201305/10104518_2QHm.jpg" style="padding: 5px; margin: 10px 0px; border: 1px solid #dddddd; max-width: 640px; background-color: #f4f7f9; cursor: pointer; background-position: initial initial; background-repeat: initial initial;"  alt="" /></a></p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">图<span style="padding: 0px; margin: 0px;">3-6&nbsp;</span>在<span style="padding: 0px; margin: 0px;">NetBeans</span>中导入<span style="padding: 0px; margin: 0px;">Maven</span>项目</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><span style="padding: 0px; margin: 0px;">Maven</span>项目的图标有别于一般的文件夹，点击<span style="padding: 0px; margin: 0px; font-weight: 600;">打开项目</span>后，<span style="padding: 0px; margin: 0px;">Hello World</span>项目就会被导入到<span style="padding: 0px; margin: 0px;">NetBeans</span>中，在<span style="padding: 0px; margin: 0px; font-weight: 600;">项目</span>视图中可以看到如图<span style="padding: 0px; margin: 0px;">3-7</span>所示的项目结构：</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><br style="padding: 0px; margin: 0px;" /><a href="http://static.oschina.net/uploads/img/201305/10104518_YhjV.jpg" target="_blank" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;"><img src="http://static.oschina.net/uploads/img/201305/10104518_YhjV.jpg" style="padding: 5px; margin: 10px 0px; border: 1px solid #dddddd; max-width: 640px; background-color: #f4f7f9; cursor: pointer; background-position: initial initial; background-repeat: initial initial;"  alt="" /></a></p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">&nbsp;图<span style="padding: 0px; margin: 0px;">3-7 NetBeans</span>中导入的<span style="padding: 0px; margin: 0px;">Maven</span>项目结构</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><span style="padding: 0px; margin: 0px;">NetBeans</span>中项目主代码目录的名称为<span style="padding: 0px; margin: 0px; font-weight: 600;">源包</span>，测试代码目录成了<span style="padding: 0px; margin: 0px; font-weight: 600;">测试包</span>，编译范围依赖为<span style="padding: 0px; margin: 0px; font-weight: 600;">库</span>，测试范围依赖为<span style="padding: 0px; margin: 0px; font-weight: 600;">测试库</span>，这里我们也能看到<span style="padding: 0px; margin: 0px;">pom.xml</span>，<span style="padding: 0px; margin: 0px;">NetBeans</span>甚至还帮我们引用了<span style="padding: 0px; margin: 0px;">settings.xml</span>。</p><h2><span style="padding: 0px; margin: 0px;">3.7.2&nbsp;</span>创建<span style="padding: 0px; margin: 0px;">Maven</span>项目</h2><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">在<span style="padding: 0px; margin: 0px;">NetBeans</span>中创建<span style="padding: 0px; margin: 0px;">Maven</span>项目同样十分轻松，在菜单栏中选择<span style="padding: 0px; margin: 0px; font-weight: 600;">文件</span>，然后<span style="padding: 0px; margin: 0px; font-weight: 600;">新建项目</span>，在弹出的对话框中，选择项目类别为<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven</span>，项目为<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven</span><span style="padding: 0px; margin: 0px; font-weight: 600;">项目</span>，点击&#8220;下一步&#8221;之后，对话框会提示我们选择<span style="padding: 0px; margin: 0px;">Maven</span>原型（即<span style="padding: 0px; margin: 0px;">Maven Archtype</span>），我们选择<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven</span><span style="padding: 0px; margin: 0px; font-weight: 600;">快速启动原型（<span style="padding: 0px; margin: 0px;">1.0</span></span><span style="padding: 0px; margin: 0px; font-weight: 600;">）</span>，（即前文提到的<span style="padding: 0px; margin: 0px;">maven-archetype-quickstart</span>），点击&#8220;下一步&#8221;之后，输入项目的基本信息，这些信息在之前讨论<span style="padding: 0px; margin: 0px;">archetype</span>及在<span style="padding: 0px; margin: 0px;">m2eclipse</span>中创建<span style="padding: 0px; margin: 0px;">Maven</span>项目的时候都仔细解释过，不再详述，如图<span style="padding: 0px; margin: 0px;">3-8</span>所示：</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><br style="padding: 0px; margin: 0px;" /><a href="http://static.oschina.net/uploads/img/201305/10104518_XOCR.jpg" target="_blank" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;"><img title="点击查看原始大小图片" src="http://static.oschina.net/uploads/img/201305/10104518_XOCR.jpg" height="354" width="650" style="padding: 5px; margin: 10px 0px; border: 1px solid #dddddd; max-width: 640px; background-color: #f4f7f9; cursor: pointer; background-position: initial initial; background-repeat: initial initial;"  alt="" /></a></p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">&nbsp;图<span style="padding: 0px; margin: 0px;">3-8&nbsp;</span>在<span style="padding: 0px; margin: 0px;">NetBeans</span>中使用<span style="padding: 0px; margin: 0px;">Archetype</span>创建<span style="padding: 0px; margin: 0px;">Maven</span>项目</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">点击完成之后，一个新的<span style="padding: 0px; margin: 0px;">Maven</span>项目就创建好了。</p><h2><span style="padding: 0px; margin: 0px;">3.7.3&nbsp;</span>运行<span style="padding: 0px; margin: 0px;">mvn</span>命令</h2><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><span style="padding: 0px; margin: 0px;">NetBeans</span>在默认情况下提供两种<span style="padding: 0px; margin: 0px;">Maven</span>运行方式，点击菜单栏中的<span style="padding: 0px; margin: 0px; font-weight: 600;">运行</span>，我们可以看到<span style="padding: 0px; margin: 0px; font-weight: 600;">生成项目</span>和<span style="padding: 0px; margin: 0px; font-weight: 600;">清理并生成项目</span>两个选项，我们可以尝试&#8220;点击运行<span style="padding: 0px; margin: 0px;">Maven</span>构建&#8221;，根据<span style="padding: 0px; margin: 0px;">NetBeans</span>控制台的输出，我们就能发现它们实际上对应了<span style="padding: 0px; margin: 0px; font-weight: 600;">mvn install</span>和<span style="padding: 0px; margin: 0px; font-weight: 600;">mvn clean install</span>两个命令。</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">在实际开发过程中，我们往往不会满足于这两种简单的方式，比如，有时候我们只想执行项目的测试，而不需要打包，这时我们就希望能够执行<span style="padding: 0px; margin: 0px; font-weight: 600;">mvn clean test</span>命令，所幸的是<span style="padding: 0px; margin: 0px;">NetBeans Maven</span>插件完全支持自定义的<span style="padding: 0px; margin: 0px;">mvn</span>命令配置。</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">在菜单栏中选择<span style="padding: 0px; margin: 0px; font-weight: 600;">工具</span>，接着选择<span style="padding: 0px; margin: 0px; font-weight: 600;">选项</span>，在对话框中，最上面一栏选择<span style="padding: 0px; margin: 0px; font-weight: 600;">其他</span>，下面选择<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven</span>标签栏，在这里我们可以对<span style="padding: 0px; margin: 0px;">NetBeans Maven</span>插件进行全局的配置（还记得第<span style="padding: 0px; margin: 0px;">2</span>章中我们如何配置<span style="padding: 0px; margin: 0px;">NetBeans</span>使用外部<span style="padding: 0px; margin: 0px;">Maven</span>么？）。现在，选择倒数第三行的<span style="padding: 0px; margin: 0px; font-weight: 600;">编辑全局定制目标定义</span><span style="padding: 0px; margin: 0px; font-weight: 600;">&#8230;</span>，我们添加一个名为<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven Test</span>的操作，执行目标为<span style="padding: 0px; margin: 0px;">clean test</span>，暂时不考虑其他配置选项，如图<span style="padding: 0px; margin: 0px;">3-9</span>所示：</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">&nbsp;</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;"><a href="http://static.oschina.net/uploads/img/201305/10104518_sjU0.jpg" target="_blank" style="padding: 0px; margin: 0px; color: #ff8373; outline: 0px; font-size: 12px;"><img title="点击查看原始大小图片" src="http://static.oschina.net/uploads/img/201305/10104518_sjU0.jpg" height="467" width="650" style="padding: 5px; margin: 10px 0px; border: 1px solid #dddddd; max-width: 640px; background-color: #f4f7f9; cursor: pointer; background-position: initial initial; background-repeat: initial initial;"  alt="" /></a></p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">图<span style="padding: 0px; margin: 0px;">3-9&nbsp;</span>在<span style="padding: 0px; margin: 0px;">NetBeans</span>中自定义<span style="padding: 0px; margin: 0px;">mvn</span>命令</p><p style="padding: 0px; margin: 8px 0px; letter-spacing: 0.5px; font-size: 12.5px;">点击&#8220;缺省保存该配置&#8221;，在<span style="padding: 0px; margin: 0px;">Maven</span>项目上右击，选择<span style="padding: 0px; margin: 0px; font-weight: 600;">定制</span>，就能看到刚才配置好的<span style="padding: 0px; margin: 0px;">Maven</span>运行操作，选择<span style="padding: 0px; margin: 0px; font-weight: 600;">Maven Test</span>之后，终端将执行<span style="padding: 0px; margin: 0px;">mvn clean test</span>。值得一提的是，我们也可以在项目上右击，选择<span style="padding: 0px; margin: 0px; font-weight: 600;">定制</span>，再选择<span style="padding: 0px; margin: 0px; font-weight: 600;">目标</span><span style="padding: 0px; margin: 0px; font-weight: 600;">&#8230;</span>再输入想要执行的<span style="padding: 0px; margin: 0px;">Maven</span>目标（如<span style="padding: 0px; margin: 0px;">clean package)</span>，点击确定之后<span style="padding: 0px; margin: 0px;">NetBeans</span>就会执行相应的<span style="padding: 0px; margin: 0px;">Maven</span>命令。这种方式十分便捷，但这是临时的，该配置不会被保存，也不会有历史记录。</p></div><h2>3.8 小结&nbsp;</h2><div style="margin: 0px; color: #333333; font-family: Verdana, sans-serif, 宋体; font-size: 13px; line-height: 22.5px; background-color: #ffffff;"><span style="padding: 0px; margin: 0px; font-size: medium;">本章以尽可能简单且详细的方式叙述了一个Hello World项目，重点解释了POM的基本内容、Maven项目的基本结构、以及构建项目基本的Maven命令。在此基础上，还介绍了如何使用 Archetype快速创建项目骨架。最后讲述的是如何在Eclipse和NetBeans中导入、创建及构建Maven项目。</span></div><img src ="http://www.blogjava.net/qileilove/aggbug/411037.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-14 14:03 <a href="http://www.blogjava.net/qileilove/articles/411037.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>m2eclipse简单使用,创建Maven项目 ,运行mvn命令  </title><link>http://www.blogjava.net/qileilove/articles/410980.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 13 Mar 2014 06:25:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410980.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410980.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410980.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410980.html</trackback:ping><description><![CDATA[<u style="line-height: 28px; color: #333333; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ccced0;">. m2eclipse简单使用,创建Maven项目 ,运行mvn命令 (摘)</u><div style="line-height: 28px; color: #333333; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ccced0;"><span style="line-height: 84px; font-size: 48px;">m2eclipse简单使用</span></div><div id="article_content" style="line-height: 28px; color: #333333; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; background-color: #ccced0;"><p align="left" style="margin: 0px 0px 10px; padding: 0px;">前面介绍了如何安装m2eclipse，现在，我们使用m2ecilpse导入Hello World项目。选择菜单项<strong>File</strong>，然后选择<strong>Import</strong>，我们会看到一个Import对话框，在该对话框中选择General目录下的<strong>Maven Projects</strong>，然后点击<strong>Next</strong>，就会出现<strong>Import Projects</strong>对话框，在该对话框中点击<strong>Browse&#8230;</strong>选择Hello World的根目录（即包含pom.xml文件的那个目录），这时对话框中的<strong>Projects:</strong>部分就会显示该目录包含的Maven项目.</p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><img alt="" src="http://hi.csdn.net/attachment/201111/1/0_1320119976KKeX.gif" style="border: 0px; max-width: 100%;" /><br /></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;">点击Finish之后，m2ecilpse就会将该项目导入到当前的workspace中，导入完成之后，我们就可以在Package Explorer视图中看到项目.</p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><img alt="" src="http://hi.csdn.net/attachment/201111/1/0_13201200232W25.gif" style="border: 0px; max-width: 100%;" /><br /></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;">我们看到主代码目录<em>src/main/java</em>和测试代码目录<em>src/test/java</em>成了Eclipse中的资源目录，包和类的结构也十分清晰，当然pom.xml永远在项目的根目录下，而从这个视图中我们甚至还能看到项目的依赖junit-4.7.jar，其实际的位置指向了Maven本地仓库（这里我自定义了Maven本地仓库地址为<em>D:\java\repository</em>，后续章节会介绍如何自定义本地仓库位置）。</p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><br /></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><span style="line-height: 84px; font-size: 48px;">创建Maven项目&nbsp;</span></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><span style="line-height: 21px; font-size: 10px;">创建一个Maven项目也十分简单，选择菜单项<strong>File -&gt; New -&gt; Other</strong>，在弹出的对话框中选择Maven下的<strong>Maven Project</strong>，然后点击<strong>Next &gt;</strong>，在弹出的<strong>New Maven Project</strong>对话框中，我们使用默认的选项（不要选择Createa simple project选项，那样我们就能使用Maven Archetype），点击<strong>Next &gt;</strong>，此时m2eclipse会提示我们选择一个Archetype，我们选择<strong>maven-archetype-quickstart</strong>，再点击<strong>Next &gt;</strong>。由于m2eclipse实际上是在使用maven-archetype-plugin插件创建项目，因此这个步骤与上一节我们使用archetype创建项目骨架类似，输入groupId,、artifactId、version、package（暂时我们不考虑Properties），</span><br /></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><span style="line-height: 21px; font-size: 10px;"><img alt="" src="http://hi.csdn.net/attachment/201111/1/0_1320123763XIIc.gif" style="border: 0px; max-width: 100%;" /><br /></span></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;">注意，为了不和前面已导入的Hello World项目产生冲突和混淆，我们使用不同的artifactId和package。OK，点击Finish，Maven项目就创建完成了，其结构与前一个已导入的Hello World项目基本一致。</p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><span style="line-height: 84px; font-size: 48px;">3 运行mvn命令</span></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;">我们需要在命令行输入如mvn clean install之类的命令来执行maven构建，m2eclipse中也有对应的功能，在Maven项目或者pom.xml上右击，再选择Run As，就能看到如下的常见Maven命令，如图所示：</p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;"><img alt="" src="http://hi.csdn.net/attachment/201111/1/0_1320123892HEo1.gif" style="border: 0px; max-width: 100%;" /></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;">选择想要执行的Maven命令就能执行相应的构建，同时我们也能在Eclipse的console中看到构建输出。这里常见的一个问题是，默认选项中没有我们想要执行的Maven命令怎么办？比如，默认带有mvn test，但我们想执行mvn clean test，很简单，选择<strong>Maven buid&#8230;&nbsp;</strong>以自定义Maven运行命令，在弹出对话框中的<strong>Goals</strong>一项中输入我们想要执行的命令，如clean test，设置一下Name，点击<strong>Run</strong>即可。并且，下一次我们选择<strong>Maven build</strong>，或者使用快捷键Alt + Shift + X, M快速执行Maven构建的时候，上次的配置直接就能在历史记录中找到。图3-5就是自定义Maven运行命令的界面：<br /></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;"><br /></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;"><img alt="" src="http://hi.csdn.net/attachment/201111/1/0_1320123967M8q9.gif" style="border: 0px; max-width: 100%;" />在Eclipse中自定义mvn命令</p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;"><br /></p><p align="left" style="line-height: 21px; margin: 0px 0px 10px; padding: 0px; font-size: 10px;"></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;"><strong>&nbsp;小结</strong><a rel="nofollow" href="http://www.javaeye.com/wiki/hzbook/2872-Maven-in-action#top" style="color: #58992a; text-decoration: none;"></a></p><p align="left" style="margin: 0px 0px 10px; padding: 0px;">本章以尽可能简单且详细的方式叙述了一个Hello World项目，重点解释了POM的基本内容、Maven项目的基本结构、以及构建项目基本的Maven命令。在此基础上，还介绍了如何使用Archetype快速创建项目骨架。最后讲述的是如何在Eclipse和NetBeans中导入、创建及构建Maven项目。</p></div><img src ="http://www.blogjava.net/qileilove/aggbug/410980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-13 14:25 <a href="http://www.blogjava.net/qileilove/articles/410980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Archetype生成项目骨架</title><link>http://www.blogjava.net/qileilove/articles/410930.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 12 Mar 2014 03:35:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410930.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410930.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410930.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410930.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410930.html</trackback:ping><description><![CDATA[<p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;"><strong>3.5 使用Archetype生成项目骨架</strong></p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">Hello World项目中有一些Maven的约定：在项目的根目录中放置pom.xml，在src/main/java目录中放置项目的主代码，在src/test/java中放置项目的测试代码。之所以一步一步地展示这些步骤，是为了能让可能是Maven初学者的你得到最实际的感受。我们称这些基本的目录结构和pom.xml文件内容称为项目的骨架，当第一次创建项目骨架的时候，你还会饶有兴趣地去体会这些默认约定背后的思想，第二次，第三次，你也许还会满意自己的熟练程度，但第四、第五次做同样的事情，你可能就会恼火了。为此Maven提供了Archetype以帮助我们快速勾勒出项目骨架。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">还是以Hello World为例，我们使用maven archetype来创建该项目的骨架，离开当前的Maven项目目录。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">如果是Maven 3，简单地运行：</p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6; line-height: 28px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">mvn&nbsp;archetype:generate&nbsp;</span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">如果是Maven 2，最好运行如下命令：</p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6; line-height: 28px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">mvn&nbsp;org.apache.maven.plugins:mavenarchetype<br style="clear: both; width: 0px; height: 0px;" />plugin:2.0alpha5:generate &nbsp;</span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">很多资料会让你直接使用更为简单的 mvn archetype:generate 命令，但在Maven 2中这是不安全的，因为该命令没有指定Archetype插件的版本，于是Maven会自动去下载最新的版本，进而可能得到不稳定的SNAPSHOT版本，导致运行失败。然而在Maven 3中，即使用户没有指定版本，Maven也只会解析最新的稳定版本，因此这是安全的。具体内容见7.7节。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">我们实际上是在运行插件mavenarchetypeplugin，注意冒号的分隔，其格式为 groupId:artifactId:version:goal，org.apache.maven.plugins 是maven官方插件的groupId，mavenarchetypeplugin 是Archetype插件的artifactId，2.0alpha5 是目前该插件最新的稳定版，generate是要使用的插件目标。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">紧接着会看到一段长长的输出，有很多可用的Archetype供选择，包括著名的Appfuse项目的Archetype、JPA项目的Archetype等。每一个Archetype前面都会对应有一个编号，同时命令行会提示一个默认的编号，其对应的Archetype为mavenarchetypequickstart，直接回车以选择该Archetype，紧接着Maven会提示输入要创建项目的groupId、artifactId、version以及包名package。如下输入并确认：</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;"></p><span style="color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; background-color: #f8f8f8;"><span style="width: 635px; line-height: 18px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><span style="width: 635px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><span style="width: 635px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><span style="width: 635px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><span style="width: 635px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><span style="width: 635px; margin-bottom: 10px; padding-top: 7px; padding-bottom: 4px;"><pre style="margin-top: 0px; padding: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">Define&nbsp;value&nbsp;for&nbsp;groupId:&nbsp;:&nbsp;com.juvenxu.mvnbook &nbsp;</span></span></li><li style="padding: 0px 10px; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Define&nbsp;value&nbsp;for&nbsp;artifactId:&nbsp;:&nbsp;helloworld &nbsp;</span></li><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Define&nbsp;value&nbsp;for&nbsp;version:&nbsp;&nbsp;1.0SNAPSHOT:&nbsp;: &nbsp;</span></li><li style="padding: 0px 10px; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Define&nbsp;value&nbsp;for&nbsp;package:&nbsp;&nbsp;com.juvenxu.mvnbook:&nbsp;:&nbsp;<br style="clear: both; width: 0px; height: 0px;" />com.juvenxu.mvnbook.helloworld &nbsp;</span></li><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Confirm&nbsp;properties&nbsp;configuration: &nbsp;</span></li><li style="padding: 0px 10px; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">groupId:&nbsp;com.juvenxu.mvnbook &nbsp;</span></li><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">artifactId:&nbsp;helloworld &nbsp;</span></li><li style="padding: 0px 10px; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">version:&nbsp;1.0SNAPSHOT &nbsp;</span></li><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">package:&nbsp;com.juvenxu.mvnbook.helloworld&nbsp;</span></li><li style="padding: 0px 10px; color: inherit; list-style: decimal inside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: #f8f8f8; height: 20px; float: left; margin: 0px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Y: : YArchetype</span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">插件将根据我们提供的信息创建项目骨架。在当前目录下，Archetype插件会创建一个名为helloworld（我们定义的artifactId）的子目录，从中可以看到项目的基本结构：基本的pom.xml已经被创建，里面包含了必要的信息以及一个junit依赖；主代码目录src/main/java已经被创建，在该目录下还有一个Java类com.juvenxu.mvnbook.helloworld.App，注意这里使用到了刚才定义的包名，而这个类也仅仅只有一个简单的输出Hello World!的main方法；测试代码目录src/test/java也被创建好了，并且包含了一个测试用例com.juvenxu.mvnbook.helloworld.AppTest。</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">Archetype可以帮助我们迅速地构建起项目的骨架，在前面的例子中，我们完全可以在Archetype生成的骨架的基础上开发Hello World项目以节省大量时间。</p><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;">此外，这里仅仅是看到了一个最简单的Archetype，如果有很多项目拥有类似的自定义项目结构以及配置文件，则完全可以一劳永逸地开发自己的Archetype，然后在这些项目中使用自定义的Archetype来快速生成项目骨架。本书后面的章节会详细阐述如何开发Maven Archetype。<br /><br /></p><h3 style="font-size: 1.2em; line-height: 1.5em; margin: 0px 0px 0.5em; padding: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;">Maven2创建Java项目<p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">1、打开命令行窗口，显示在保存项目的位置；</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">2、创建JAVA项目</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp; 命令：<span style="color: #ff0000;">mvn&nbsp;archetype:generate</span></p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">* 输入需要创建的项目,这里创建普通java项目,按照选择输入15,默认就可以了;&nbsp;<br />*&nbsp;<strong>Define value for groupId</strong>&nbsp;:输入组织ID;&nbsp;<br />*&nbsp;<strong>Define value for groupId</strong>&nbsp;:输入项目名称;&nbsp;<br />*&nbsp;<strong>Define value for version</strong>&nbsp;:输入版本号,可以直接回车,默认是1.0-SNAPSHOT;&nbsp;<br />*&nbsp;<strong>Define value for package</strong>&nbsp;:java的包名,如com.shichao;&nbsp;<br />完成以上输入后,命令行显示以上信息,输入<strong>y</strong>&nbsp;即完成创建.</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">3、将maven项目转化为eclipse项目</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;">mvn&nbsp;eclipse:eclipse</span></p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maven将生成eclipse需要的配置文件,形成eclipse项目(如.project文件);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开eclipse,菜单选择:file&gt;import&gt;general&gt;existing projects into workspace,在对话框中选中目录,导入即可;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">4、清除eclipse项目相关配置</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;">mvn&nbsp;eclipse:clean</span></p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp; maven将清除项目中eclipse配置文件</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;</p></h3><h3>Maven2创建WEB项目</h3><h3 style="font-size: 1.2em; line-height: 1.5em; margin: 0px 0px 0.5em; padding: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;"><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在maven的工作空间（这里的工作空间即将要存放所创建的Web项目文件夹的文件夹。如E:\maven)中执行如下的命令：</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;">mvn archetype:create -DgroupId=com.javaeye.webfoo -DartifactId=webfoo -DarchetypeArtifactId=maven-archetype-webapp</span></p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.200000762939453px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 再将项目导入eclipse即可！</p><div></div></h3><p style="margin: 10px 0px; padding: 0px; background-color: transparent; text-indent: 28px;"></p></span></span></span></span></span></span></span><img src ="http://www.blogjava.net/qileilove/aggbug/410930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-12 11:35 <a href="http://www.blogjava.net/qileilove/articles/410930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>1. MAVEN + SVN + HUDSON + SONAR集成测试环境搭建、</title><link>http://www.blogjava.net/qileilove/articles/410916.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 12 Mar 2014 02:48:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410916.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410916.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410916.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410916.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410916.html</trackback:ping><description><![CDATA[<div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">1. MAVEN + SVN + HUDSON + SONAR集成测试环境搭建、</strong></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">1.1 软件准备</strong></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　Hudson、Jenkins、Sonar</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">1.2 软件安装</strong></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　说明：本例均使用将应用程序部署至<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>容器下，Hudson和Sonar有其他部署启动方式，如有需要请自行使用，本文不做赘述。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1.2.1 安装hudson</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1)将下载到的hudson.war文件部署至web容器中，启动web容器。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　2)访问地址http://localhost:8080/hudson，显示如下：</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　(8080是容器默认端口，hudson是项目名称)</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1.2.2 安装sonar</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　说明：以下内容是快速安装的示例。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1)解压sonar.zip，进入war文件夹下，运行build-war文件，会生成sonar.war文件</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　2)将sonar.war文件部署至web容器下，启动容器</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　3)访问地址http://localhost:8080/sonar/，显示如下：</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　4)(8080是容器默认端口，sonar是项目名称)</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　1.3 软件配置</strong></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1.3.1 配置sonar</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1)创建<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　a)Sonar需要数据库的支持，其本身自带Derby同时支持MySQL5.x，<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Oracle</strong></u></a>&nbsp;10g XE,Postgresql和MS SqlServer 2005，推荐使用<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">MySQL</strong></u></a>。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　b)创建数据库：MySQL中创建用户sonar，同时创建数据库sonar，未用户sonar赋予权限。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　说明：表和索引活在sonar激活后自动创建。</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　2)配置数据库，编辑conf/sonar.properties</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">sonar.jdbc.username: sonar</div><div style="word-break: break-all; margin: 10px 0px;">sonar.jdbc.password: sonar</div><div style="word-break: break-all; margin: 10px 0px;">sonar.jdbc.url: &nbsp; &nbsp; jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true</div><div style="word-break: break-all; margin: 10px 0px;">sonar.jdbc.driverClassName:com.mysql.jdbc.Driver</div></td></tr></tbody></table></div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　说明：更改数据库配置，请注意extensions/jdbc-driver/mysql/目录下是否有对应的驱动</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1.3.2 配置hudson</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　请保证Hudson已经安装以下插件：</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　进入Manage Hudson -&gt;Config System进行配置，显示如下：</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　1)系统信息配置：</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　Home directory：hudson目录</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　System Message：hudson系统说明信息</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　# of executors：同时可执行最大数</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　Quiet period：构建工程之前的等候时间，单位是s，此项较重要可以保证构建工程时项目的完整性</div><div style="font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; background-color: #ffffff;">　　SCM checkout retry count：检出失败重试次数<span style="font-size: 11.818181991577148px; line-height: 21.60000228881836px; font-family: verdana, 'courier new';">2)安全信息配置：</span></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　3)JDK配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　如果系统配置已为JDK配置了环境变量，则此处可以不做设置</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　4)Maven配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　Name：为你的maven指定名称</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　MAVEN_HOME：指定maven安装路径</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　5)SVN配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　Exclusion revprop name：指定项目SVN路径</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">1.4 环境集成</strong></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1.4.1 Maven与Sonar集成</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　编辑$MAVEN_HOME/conf或者~/.m2下的setting.xml文件，添加如下内容：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;!--sonar --&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;profile&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;id&gt;sonar&lt;/id&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;activation&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;activeByDefault&gt;true&lt;/activeByDefault&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/activation&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;properties&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;!-- mysql--&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;sonar.jdbc.url&gt; jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/sonar.jdbc.url&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;sonar.jdbc.driver&gt; com.mysql.jdbc.Driver&lt;/sonar.jdbc.driver&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;sonar.jdbc.username&gt;sonar&lt;/sonar.jdbc.username&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;sonar.jdbc.password&gt;sonar&lt;/sonar.jdbc.password&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;!--remote host--&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;sonar.host.url&gt;http://localhost:8080/sonar&lt;/sonar.host.url&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/properties&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/profile&gt;</div></td></tr></tbody></table></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　说明： 因为sonar是通过Maven2插件来分析源代码并把结果注入到数据库的，所以必须在Maven的配置里设置数据库的属性。</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1.4.2 hudson与sonar集成</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1)安装sonar插件</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2)配置Sonar参数（服务地址和数据库地址）</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">1.5 创建和配置job</strong></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1.5.1 创建JOB，点击New Job，显示如下：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1.5.2 点击OK，显示如下：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1)工程概要配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2)工程高级配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　3)源码管理：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　高级配置：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　4)构建</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2.Eclipse中IDE环境下集成测试</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　说明：在IDE环境下集成测试非常方便，可以使用的组件有dashboard、cobertura、findbugs</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2.1 &nbsp; Findbugs：根据既定规则检查代码bug</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1)修改工程的pom.xml文件，添加findbugs-maven-plugin插件</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;plugin&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;artifactId&gt;findbugs-maven-plugin&lt;/artifactId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;version&gt;2.5.1&lt;/version&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;configuration&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;threshold&gt;High&lt;/threshold&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;effort&gt;Default&lt;/effort&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;findbugsXmlOutput&gt;true&lt;/findbugsXmlOutput&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;!-- findbugs xml输出路径--&gt; &nbsp; &nbsp; &nbsp; &nbsp;&lt;findbugsXmlOutputDirectory&gt;target/site&lt;/findbugsXmlOutputDirectory&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/configuration&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/plugin&gt;</div></td></tr></tbody></table></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2)输入命令：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　mvn findbugs:findbugs</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　3)结果会生成在target/目录下findbugsXml.xml文件中</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2.2 Cobertura：测试覆盖率插件</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1)修改工程的pom.xml文件，添加cobertura-maven-plugin插件</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;plugin&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;artifactId&gt;cobertura-maven-plugin&lt;/artifactId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;version&gt;2.5.1&lt;/version&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/plugin&gt;</div></td></tr></tbody></table></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2)输入命令：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　mvn cobertura:cobertura</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　3)结果生成在target/site/cobertura目录下</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2.3 &nbsp; Dashboard：图表显示测试结果</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　1)修改工程的pom.xml文件，添加dashboard-maven-plugin插件</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;plugin&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;artifactId&gt;dashboard-maven-plugin&lt;/artifactId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;version&gt;1.0.0-beta-1&lt;/version&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/plugin&gt;</div></td></tr></tbody></table></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　2)输入命令：</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.7272338867188px; background-color: #dddddd; font-size: 12px;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="font-size: 12px; word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">mvn site</div><div style="word-break: break-all; margin: 10px 0px;">mvn dashboard:dashboard</div></td></tr></tbody></table></div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　3)在项目targe/site目录下打开dashboard页面查看结果</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;">　　如果安装了dashboard插件，可以在dashaboard文件中查看所有测试结果信息。</div><div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 11.818181991577148px; word-break: break-all; line-height: 21.60000228881836px; margin: 10px 0px;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/410916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-12 10:48 <a href="http://www.blogjava.net/qileilove/articles/410916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven3实战之maven使用入门(打包和运行)</title><link>http://www.blogjava.net/qileilove/articles/410887.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 11 Mar 2014 09:30:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410887.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410887.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410887.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410887.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410887.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">maven3实战之maven使用入门(打包和运行)</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">----------</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">将项目进行编译，测试之后，下一个重要步骤就是打包。pom.xml中如果没有指定打包类型，默认打包类型为：jar。我们可以简单地执行命令打包：<span style="color: #ff0000;">&nbsp;mvn clean pachage</span>。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">类似地，maven会在打包之前执行编译，测试等操作。如以打jar包为例，jar:jar任务负责打包，实际上就是jar插件的jar目标将项目主代码打包成一个名为xxxxxx-1.0-SNAPSHOT.jar的文件。该文件也位于target/输出目录中，它是根据<span style="color: #ff0000;">artifact-version.jar</span>的规则进行命名的，如有需要，还可以使用<span style="color: #ff0000;">finalName</span>来自定义该文件的名称，这里暂且不展开，后面会详细解释。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">在打包之后，又执行了安装任务install:install。从输出可以看到任务将项目输出的jar安装到了maven本地仓库中，可以打开相应的文件夹看到项目的pom和jar。之前我们说只有构件被下载到本地仓库后，才能由所有Maven项目使用，这里同样的道理，只有将自己编写的项目安装到本地仓库之后，其他maven项目才能使用它。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">我们已经体验了maven最主要的命令：<span style="color: #ff0000;">mvn clean compile，mvn clean test，mvn clean package，mvn clean install</span>。执行test之前是会先执行compile的，执行package之前是会先执行test的，而类似地，install之前会执行package。可以在任何一个maven项目中执行这些命令。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">默认打包是生成jar的，如果我的项目还有main方法的，我想打包成可执行的jar包，为了生成可执行的jar文件，需要借助<span style="color: #ff0000;">maven-shade-plugin,</span>配置该插件如下：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Xml代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #620091; text-decoration: underline;"><img src="http://fhd001.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>org.apache.maven.plugins<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">groupId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>maven-shade-plugin<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">artifactId</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>1.2.1<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">version</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">executions</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">execution</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">phase</span><span style="color: #006699; font-weight: bold;">&gt;</span>package<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">phase</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">goals</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">goal</span><span style="color: #006699; font-weight: bold;">&gt;</span>shade<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">goal</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">goals</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">configuration</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">transformers</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">transformer</span>&nbsp;<span style="color: red;">implementation</span>=<span style="color: blue;">"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;</span><span style="color: #006699; font-weight: bold;">mainClass</span><span style="color: #006699; font-weight: bold;">&gt;</span>com.juvenxu.mvnbook.helloworld.HelloWorld<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">mainClass</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">transformer</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">transformers</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">configuration</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">execution</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">executions</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #006699; font-weight: bold;">&lt;/</span><span style="color: #006699; font-weight: bold;">plugin</span><span style="color: #006699; font-weight: bold;">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">默认打包生成jar是不能够直接运行的，因为带有main方法的类信息不会添加到manifest中(打开jar文件中的META-INF/MANIFEST.MF文件，将无法看到Main-Class一行)。</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">plugin元素在POM中的相对位置应该在&lt;project&gt;&lt;build&gt;&lt;plugins&gt;下面。我们配置了mainClass为com.juvenxu.mvnbook.helloworld.HelloWorld，项目在打包时会将该信息放到MANIFEST中。现在执行<span style="color: #ff0000;">mvn clean install</span>，待构建完成之后打开target/目录，可以看到hello-world-1.0-SNAPSHOT.jar和original-hello-world-1.0-SNAPSHOT.jar，前者是带有Main-Class信息的可执行jar，后者是原始的jar，打开hello-world-1.0-SNAPSHOT.jar的META-INF/MANIFEST.MF，可以看到它包含这样一行信息：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"><span style="color: #ff0000;">Main-Class:com.juvenxu.mvnbook.helloworld.HelloWorld</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">现在，在项目根目录中执行该jar文件：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;">D:\code\hello-world &gt;&nbsp;<span style="color: #ff0000;">java-jar target\hello-world-1.0-SNAPSHOT.jar</span>，可以得到正确的输出了。<br /></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">1：创建名为：helloword的maven项目</span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">2:/helloword/src/main/java下建立package包hello，在包下建类SayHello</span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">package hello;<br /><br />public class SayHello {<br /><br />&nbsp;&nbsp; &nbsp;public String sayhello() {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("hello............is anybody here...");<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return "dddddddddddddddddddddddddd";<br />&nbsp;&nbsp; &nbsp;}<br /><br />&nbsp;&nbsp; &nbsp;public static void main(String[] arg) {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println(new SayHello().sayhello());<br />&nbsp;&nbsp; &nbsp;}<br />}<span style="color: #3333ff;"><br />3：/helloword/src/test/java下建立test包，在test包下建HelloWordTest类</span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">package test;<br /><br />import hello.SayHello;<br />import junit.framework.Assert;<br />import junit.framework.TestCase;<br /><br />public class HelloWordTest extends TestCase {<br /><br />&nbsp;&nbsp; &nbsp;public HelloWordTest(String name) {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;super(name);<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;&nbsp; protected void setUp() {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //进行初始化的任务<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br />&nbsp;&nbsp; &nbsp;/**<br />&nbsp;&nbsp; &nbsp; * @param args<br />&nbsp;&nbsp; &nbsp; */<br />&nbsp;&nbsp; &nbsp;public void testSayHello()<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SayHello s = new SayHello();<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String r = s.sayhello();<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Assert.assertEquals("dddddddddddddddddddddddddd", r);<br />&nbsp;&nbsp; &nbsp;}<br />}<br /><br />4：pom.xml配置</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&lt;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"&gt;<br />&nbsp; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br />&nbsp; &lt;groupId&gt;com.houwen.test&lt;/groupId&gt;<br />&nbsp; &lt;artifactId&gt;helloword&lt;/artifactId&gt;<br />&nbsp; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br />&nbsp; &lt;name&gt;Maven Helloword&lt;/name&gt;</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&lt;!--junit依赖是为tset准备，配置后，记得install,把依赖包嵌入resourse内，--&gt;<br />&nbsp;&nbsp; &lt;dependencies&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;junit&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;junit&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.8.1&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;scope&gt;test&lt;/scope&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependencies&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;build&gt;</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">&lt;!--maven-shade-plugin</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #ff0000;">而要得到一个可以直接在命令行通过java命令运行的JAR文件，还要满足两个条件：<br />　　JAR包中的/META-INF/MANIFEST.MF元数据文件必须包含Main-Class信息。</span><br /></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">Maven有好几个插件能帮助用户完成上述任务，不过用起来最方便的还是maven-shade-plugin，它可以让用户配置Main-Class的值，然后在打包的时候将值填入/META-INF/MANIFEST.MF文件。关于项目的依赖，它很聪明地将依赖JAR文件全部解压后，再将得到的.class文件连同当前项目的.class文件一起合并到最终的CLI包中，这样，在执行CLI JAR文件的时候，所有需要的类就都在Classpath中了。下面是一个配置样例：</span><br /></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;">--&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;plugins&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;plugin&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;version&gt;1.2.1&lt;/version&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;executions&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;execution&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;phase&gt;package&lt;/phase&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;goals&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;goal&gt;shade&lt;/goal&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/goals&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;configuration&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;transformers&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mainClass&gt;hello.SayHello&lt;/mainClass&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/transformer&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/transformers&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/execution&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/executions&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;/plugin&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;/plugins&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/build&gt;<br />&lt;/project&gt;</p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br /></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">4.1上述例子中的，运行maven package后<br /></span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">我的Main-Class是hello.SayHello，构建完成后，对应于一个常规的helloword-0.0.1-SNAPSHOT.jar文件，我还得到了一个original-helloword-0.0.1-SNAPSHOT.jar文件。最后，我可以通过helloword-0.0.1-SNAPSHOT.jar命令运行程序。</span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">4.2之后再运行maven install,把生成的jar打入到本地的maven仓库，可以在C:\Documents and Settings\hcen\.m2\repository\com\houwen\test\helloword\0.0.1-SNAPSHOT</span></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="color: #3333ff;">找到helloword-0.0.1-SNAPSHOT.jar</span><br /></p><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="font-size: 14.44444465637207px;">5.最后，我可以通过java -jar&nbsp;&nbsp;</span><span style="font-size: 14.44444465637207px; color: #3333ff;">(jar包路径)/helloword-0.0.1-SNAPSHOT.jar</span><span style="font-size: 14.44444465637207px;">命令运行程序。<br /><br /></span></p><h1 style="margin: 0px; padding: 0px; font-size: 16px; text-align: center; font-family: Tahoma;">用Maven生成一个包孕所有依赖jar包的可执行的jar包</h1><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="font-size: 14.44444465637207px;"><br /></span><span style="color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px; background-color: #fafafa;">create an executable jar with dependencies using Maven:</span><br style="margin: 0px; padding: 0px; color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px;" /><br style="margin: 0px; padding: 0px; color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px;" /><span style="color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px; background-color: #fafafa;">using plugin - onejar-maven-plugin. Example below (mvn package build jar):</span><br style="margin: 0px; padding: 0px; color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px;" /></p><pre name="code" class="xml" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-size: 14px;">&lt;plugin&gt;
     &lt;groupId&gt;org.dstovall&lt;/groupId&gt;
     &lt;artifactId&gt;onejar-maven-plugin&lt;/artifactId&gt;
     &lt;version&gt;1.3.0&lt;/version&gt;
     &lt;executions&gt;
           &lt;execution&gt;
              &lt;configuration&gt;
                  &lt;mainClass&gt;com.company.MainClass&lt;/mainClass&gt;
              &lt;/configuration&gt;
              &lt;goals&gt;
                  &lt;goal&gt;one-jar&lt;/goal&gt;
              &lt;/goals&gt;
           &lt;/execution&gt;
     &lt;/executions&gt;
&lt;/plugin&gt;
</pre><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><br style="margin: 0px; padding: 0px; color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px;" /><span style="color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px; background-color: #fafafa;">You need to add repository for that plugin:</span><br style="margin: 0px; padding: 0px; color: #000000; font-family: Tahoma; font-size: 14px; line-height: 24px;" /></p><pre name="code" class="xml" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; font-size: 14px;">&lt;pluginRepositories&gt;
     &lt;pluginRepository&gt;
           &lt;id&gt;onejar-maven-plugin.googlecode.com&lt;/id&gt;
           &lt;url&gt;http://onejar-maven-plugin.googlecode.com/svn/mavenrepo&lt;/url&gt;
     &lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;</pre><p style="color: #333333; font-family: Arial; font-size: 14.44444465637207px; line-height: 26px; background-color: #ffffff;"><span style="font-size: 14.44444465637207px;"><br /></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px; background-color: #ffffff;"></p><img src ="http://www.blogjava.net/qileilove/aggbug/410887.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-11 17:30 <a href="http://www.blogjava.net/qileilove/articles/410887.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven编写主代码与测试代码</title><link>http://www.blogjava.net/qileilove/articles/410677.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Mar 2014 03:39:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410677.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410677.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410677.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410677.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410677.html</trackback:ping><description><![CDATA[<h2>3.2 编写主代码&nbsp;</h2><div style="padding-top: 5px; padding-left: 5px; font-size: 14px; line-height: 1.8em; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;"><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">项目主代码和测试代码不同，项目的主代码会被打包到最终的构件中（比如<span style="font-size: small;">jar</span>），而测试代码只在运行测试时用到，不会被打包。默认情况下，<span style="font-size: small;">Maven</span>假设项目主代码位于<span style="font-size: small;"><em>src/main/java</em></span>目录，我们遵循<span style="font-size: small;">Maven</span>的约定，创建该目录，然后在该目录下创建文件<span style="font-size: small;">com/juvenxu/mvnbook/helloworld/<em>HelloWorld.java</em></span>，其内容如代码清单<span style="font-size: small;">3-2</span>：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单<span style="font-size: small;">3-2</span>：<span style="font-size: small;">Hello World</span>的主代码</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;span&nbsp;style="font-size:&nbsp;small;"&gt;<span style="color: #7f0055;">package</span>&nbsp;com.juvenxu.mvnbook.helloworld;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;HelloWorld&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;String&nbsp;sayHello()&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;"Hello&nbsp;Maven";&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorld().sayHello()&nbsp;);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/span&gt;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;"><span style="font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>这是一个简单的<span style="font-size: small;">Java</span>类，它有一个<span style="font-size: small;">sayHello()</span>方法，返回一个<span style="font-size: small;">String</span>。同时这个类还带有一个<span style="font-size: small;">main</span>方法，创建一个<span style="font-size: small;">HelloWorld</span>实例，调用<span style="font-size: small;">sayHello()</span>方法，并将结果输出到控制台。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">关于该<span style="font-size: small;">Java</span>代码有两点需要注意。首先，在<span style="font-size: small;">95%</span>以上的情况下，我们应该把项目主代码放到<span style="font-size: small;"><em>src/main/java/</em></span>目录下（遵循<span style="font-size: small;">Maven</span>的约定），而无须额外的配置，<span style="font-size: small;">Maven</span>会自动搜寻该目录找到项目主代码。其次，该<span style="font-size: small;">Java</span>类的包名是<span style="font-size: small;">com.juvenxu.mvnbook.helloworld</span>，这与我们之前在<span style="font-size: small;">POM</span>中定义的<span style="font-size: small;">groupId</span>和<span style="font-size: small;">artifactId</span>相吻合。一般来说，项目中<span style="font-size: small;">Java</span>类的包都应该基于项目的<span style="font-size: small;">groupId</span>和<span style="font-size: small;">artifactId</span>，这样更加清晰，更加符合逻辑，也方便搜索构件或者<span style="font-size: small;">Java</span>类。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码编写完毕后，我们使用<span style="font-size: small;">Maven</span>进行编译，在项目根目录下运行命令<span style="font-size: small;">&nbsp;<strong>mvn clean compile&nbsp;</strong></span>，我们会得到如下输出：</p><p style="margin: 0px; padding: 0px;"><span style="font-size: small;"><br /></span></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;span&nbsp;style="font-size:&nbsp;small;"&gt;[INFO]&nbsp;Scanning&nbsp;<span style="color: #7f0055;">for</span>&nbsp;projects...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Building&nbsp;Maven&nbsp;Hello&nbsp;World&nbsp;Project&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;&nbsp;&nbsp;&nbsp;task-segment:&nbsp;[clean,&nbsp;compile]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[clean:clean&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-clean}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Deleting&nbsp;directory&nbsp;D:\code\hello-world\target&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:resources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-resources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;skip&nbsp;non&nbsp;existing&nbsp;resourceDirectory&nbsp;D:&nbsp;\code\hello-world\src\main\resources&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:compile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-compile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;BUILD&nbsp;SUCCESSFUL&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Total&nbsp;time:&nbsp;<span style="color: #c00000;">1</span>&nbsp;second&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Finished&nbsp;at:&nbsp;Fri&nbsp;Oct&nbsp;<span style="color: #c00000;">09</span>&nbsp;<span style="color: #c00000;">02</span>:<span style="color: #c00000;">08</span>:<span style="color: #c00000;">09</span>&nbsp;CST&nbsp;<span style="color: #c00000;">2009</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Final&nbsp;Memory:&nbsp;9M/16M&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/span&gt;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;"><span style="font-size: small;">clean</span>告诉<span style="font-size: small;">Maven</span>清理输出目录<span style="font-size: small;"><em>target/</em></span>，<span style="font-size: small;">compile</span>告诉<span style="font-size: small;">Maven</span>编译项目主代码，从输出中我们看到<span style="font-size: small;">Maven</span>首先执行了<span style="font-size: small;">clean:clean</span>任务，删除<span style="font-size: small;"><em>target/</em></span>目录，默认情况下<span style="font-size: small;">Maven</span>构建的所有输出都在<span style="font-size: small;"><em>target/</em></span>目录中；接着执行<span style="font-size: small;">resources:resources</span>任务（未定义项目资源，暂且略过）；最后执行<span style="font-size: small;">compiler:compile</span>任务，将项目主代码编译至<span style="font-size: small;"><em>target/classes</em></span>目录<span style="font-size: small;">(</span>编译好的类为<span style="font-size: small;"><em>com/juvenxu/mvnbook/helloworld/HelloWorld.Class</em></span>）。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">上文提到的<span style="font-size: small;">clean:clean</span>、<span style="font-size: small;">resources:resources</span>，以及<span style="font-size: small;">compiler:compile</span>对应了一些<span style="font-size: small;">Maven</span>插件及插件目标，比如<span style="font-size: small;">clean:clean</span>是<span style="font-size: small;">clean</span>插件的<span style="font-size: small;">clean</span>目标，<span style="font-size: small;">compiler:compile</span>是<span style="font-size: small;">compiler</span>插件的<span style="font-size: small;">compile</span>目标，后文会详细讲述<span style="font-size: small;">Maven</span>插件及其编写方法。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">至此，<span style="font-size: small;">Maven</span>在没有任何额外的配置的情况下就执行了项目的清理和编译任务，接下来，我们编写一些单元测试代码并让<span style="font-size: small;">Maven</span>执行自动化测试。<br /><br /></p><h2 style="line-height: 1.5em; margin: 0px 0px 0.5em; padding: 15px 0px 3px 5px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #cccccc; font-size: 16px !important;">3.3 编写测试代码&nbsp;<a name="3349" href="http://hzbook.group.iteye.com/group/wiki/2872-Maven-in-action#top" style="color: #006699; text-decoration: none;"><img alt="Top" src="http://www.iteye.com/images/wiki/top.gif?1324994303" style="border: 0px;" /></a></h2><p style="margin: 0px; padding: 0px; text-indent: 21pt;"><br /></p><div style="padding-top: 5px; padding-left: 5px; font-size: 14px; line-height: 1.8em;"><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">为了使项目结构保持清晰，主代码与测试代码应该分别位于独立的目录中。3.2节讲过Maven项目中默认的主代码目录是<em>src/main/java</em>，对应地，Maven项目中默认的测试代码目录是<em>src/test/java</em>。因此，在编写测试用例之前，我们先创建该目录。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">在Java世界中，由Kent Beck和Erich Gamma建立的JUnit是事实上的单元测试标准。要使用JUnit，我们首先需要为Hello World项目添加一个JUnit依赖，修改项目的POM如代码清单3-3：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-3：为Hello World的POM添加依赖</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;project&nbsp;xmlns="http://maven.apache.org/POM/4.0.0"&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="http:<span style="width: auto; border-width: 0px;">//maven.apache.org/POM/4.0.0</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">http:<span style="width: auto; border-width: 0px;">//maven.apache.org/maven-v4_0_0.xsd"&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;modelVersion&gt;<span style="color: #c00000;">4.0</span>.<span style="color: #c00000;">0</span>&lt;/modelVersion&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;groupId&gt;com.juvenxu.mvnbook&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;artifactId&gt;hello-world&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;version&gt;<span style="color: #c00000;">1.0</span>-SNAPSHOT&lt;/version&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;name&gt;Maven&nbsp;Hello&nbsp;World&nbsp;Project&lt;/name&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;dependencies&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependency&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;junit&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;junit&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;<span style="color: #c00000;">4.7</span>&lt;/version&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;scope&gt;test&lt;/scope&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependency&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;/dependencies&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/project&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp; 代码中添加了dependencies元素，该元素下可以包含多个dependency元素以声明项目的依赖，这里我们添加了一个依赖&#8212;&#8212;groupId是junit，artifactId是junit，version是4.7。前面我们提到groupId、artifactId和version是任何一个Maven项目最基本的坐标，JUnit也不例外，有了这段声明，Maven就能够自动下载junit-4.7.jar。也许你会问，Maven从哪里下载这个jar呢？在Maven之前，我们可以去JUnit的官网下载分发包。而现在有了Maven，它会自动访问中央仓库（<a href="http://repo1.maven.org/maven2/" style="color: #006699; text-decoration: none;">http://repo1.maven.org/maven2/</a>），下载需要的文件。读者也可以自己访问该仓库，打开路径junit/junit/4.7/，就能看到junit-4.7.pom和junit-4.7.jar。本书第6章会详细介绍Maven仓库及中央仓库。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">上述POM代码中还有一个值为test的元素scope，scope为依赖范围，若依赖范围为test则表示该依赖只对测试有效，换句话说，测试代码中的import JUnit代码是没有问题的，但是如果我们在主代码中用import JUnit代码，就会造成编译错误。如果不声明依赖范围，那么默认值就是compile，表示该依赖对主代码和测试代码都有效。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">配置了测试依赖，接着就可以编写测试类，回顾一下前面的HelloWorld类，现在我们要测试该类的sayHello()方法，检查其返回值是否为&#8220;Hello Maven&#8221;。在src/test/java目录下创建文件，其内容如代码清单3-4：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-4：Hello World的测试代码</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;com.juvenxu.mvnbook.helloworld;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;org.junit.Assert.assertEquals;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;org.junit.Test;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;HelloWorldTest&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464;">@Test</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;testSayHello()&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorld();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;result&nbsp;=&nbsp;helloWorld.sayHello();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(&nbsp;"Hello&nbsp;Maven",&nbsp;result&nbsp;);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">一个典型的单元测试包含三个步骤：一，准备测试类及数据；二，执行要测试的行为；三，检查结果。上述样例中，我们首先初始化了一个要测试的HelloWorld实例，接着执行该实例的sayHello()方法并保存结果到result变量中，最后使用JUnit框架的Assert类检查结果是否为我们期望的&#8221;Hello Maven&#8221;。在JUnit 3中，约定所有需要执行测试的方法都以test开头，这里我们使用了JUnit 4，但我们仍然遵循这一约定，在JUnit 4中，需要执行的测试方法都应该以@Test进行标注。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">测试用例编写完毕之后就可以调用Maven执行测试，运行&nbsp;<strong>mvn clean test</strong>&nbsp;：</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Scanning&nbsp;<span style="color: #7f0055;">for</span>&nbsp;projects...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Building&nbsp;Maven&nbsp;Hello&nbsp;World&nbsp;Project&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;&nbsp;&nbsp;&nbsp;task-segment:&nbsp;[clean,&nbsp;test]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[clean:clean&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-clean}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Deleting&nbsp;directory&nbsp;D:\git-juven\mvnbook\code\hello-world\target&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:resources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-resources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Downloading:&nbsp;http:<span style="width: auto; border-width: 0px;">//repo1.maven.org/maven2/junit/junit/4.7/junit-4.7.pom</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">1K&nbsp;downloaded&nbsp;&nbsp;(junit-<span style="color: #c00000;">4.7</span>.pom)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:compile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-compile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:testResources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testResources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Downloading:&nbsp;http:<span style="width: auto; border-width: 0px;">//repo1.maven.org/maven2/junit/junit/4.7/junit-4.7.jar</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">226K&nbsp;downloaded&nbsp;&nbsp;(junit-<span style="color: #c00000;">4.7</span>.jar)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:testCompile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testCompile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:\&nbsp;code\hello-world\target\test-classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[ERROR]&nbsp;BUILD&nbsp;FAILURE&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compilation&nbsp;failure&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">D:\code\hello-world\src\test\java\com\juvenxu\mvnbook\helloworld\HelloWorldTest.java:[<span style="color: #c00000;">8</span>,<span style="color: #c00000;">5</span>]&nbsp;-source&nbsp;<span style="color: #c00000;">1.3</span>&nbsp;中不支持注释&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">（请使用&nbsp;-source&nbsp;<span style="color: #c00000;">5</span>&nbsp;或更高版本以启用注释）&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464;">@Test</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;For&nbsp;more&nbsp;information,&nbsp;run&nbsp;Maven&nbsp;with&nbsp;the&nbsp;-e&nbsp;<span style="color: #7f0055;">switch</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&#8230;&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; text-indent: 21pt;">不幸的是构建失败了，不过我们先耐心分析一下这段输出（为了本书的简洁，一些不重要的信息我用省略号略去了）。命令行输入的是mvn clean test，而Maven实际执行的可不止这两个任务，还有clean:clean、resources:resources、compiler:compile、resources:testResources以及compiler:testCompile。暂时我们需要了解的是，在Maven执行测试（test）之前，它会先自动执行项目主资源处理，主代码编译，测试资源处理，测试代码编译等工作，这是Maven生命周期的一个特性，本书后续章节会详细解释Maven的生命周期。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">从输出中我们还看到：Maven从中央仓库下载了junit-4.7.pom和junit-4.7.jar这两个文件到本地仓库（<em>~/.m2/repository</em>）中，供所有Maven项目使用。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">构建在执行compiler:testCompile任务的时候失败了，Maven输出提示我们需要使用-source 5或更高版本以启动注释，也就是前面提到的JUnit 4的@Test注解。这是Maven初学者常常会遇到的一个问题。由于历史原因，Maven的核心插件之一compiler插件默认只支持编译Java 1.3，因此我们需要配置该插件使其支持Java 5，见代码清单3-5：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-5：配置maven-compiler-plugin支持Java 5</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;project&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;build&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugins&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;configuration&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;source&gt;<span style="color: #c00000;">1.5</span>&lt;/source&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;target&gt;<span style="color: #c00000;">1.5</span>&lt;/target&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/configuration&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugins&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;/build&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/project&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">该POM省略了除插件配置以外的其他部分，我们暂且不去关心插件配置的细节，只需要知道compiler插件支持Java 5的编译。现在再执行<strong>mvn clean test</strong><strong>，</strong>输出如下：</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:testCompile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testCompile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\test-classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[surefire:test&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-test}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Surefire&nbsp;report&nbsp;directory:&nbsp;D:\code\hello-world\target\surefire-reports&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">-------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;T&nbsp;E&nbsp;S&nbsp;T&nbsp;S&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">-------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Running&nbsp;com.juvenxu.mvnbook.helloworld.HelloWorldTest&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Tests&nbsp;run:&nbsp;<span style="color: #c00000;">1</span>,&nbsp;Failures:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Errors:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Skipped:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Time&nbsp;elapsed:&nbsp;<span style="color: #c00000;">0.055</span>&nbsp;sec&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Results&nbsp;:&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Tests&nbsp;run:&nbsp;<span style="color: #c00000;">1</span>,&nbsp;Failures:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Errors:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Skipped:&nbsp;<span style="color: #c00000;">0</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;BUILD&nbsp;SUCCESSFUL&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">我们看到compiler:testCompile任务执行成功了，测试代码通过编译之后在<em>target/test-classes</em>下生成了二进制文件，紧接着surefire:test任务运行测试，surefire是Maven世界中负责执行测试的插件，这里它运行测试用例HelloWorldTest，并且输出测试报告，显示一共运行了多少测试，失败了多少，出错了多少，跳过了多少。显然，我们的测试通过了&#8212;&#8212;BUILD SUCCESSFUL。</p></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/410677.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-06 11:39 <a href="http://www.blogjava.net/qileilove/articles/410677.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven编写主代码与测试代码</title><link>http://www.blogjava.net/qileilove/articles/410678.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Mar 2014 03:39:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410678.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410678.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410678.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410678.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410678.html</trackback:ping><description><![CDATA[<h2>3.2 编写主代码&nbsp;</h2><div style="padding-top: 5px; padding-left: 5px; font-size: 14px; line-height: 1.8em; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #ffffff;"><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">项目主代码和测试代码不同，项目的主代码会被打包到最终的构件中（比如<span style="font-size: small;">jar</span>），而测试代码只在运行测试时用到，不会被打包。默认情况下，<span style="font-size: small;">Maven</span>假设项目主代码位于<span style="font-size: small;"><em>src/main/java</em></span>目录，我们遵循<span style="font-size: small;">Maven</span>的约定，创建该目录，然后在该目录下创建文件<span style="font-size: small;">com/juvenxu/mvnbook/helloworld/<em>HelloWorld.java</em></span>，其内容如代码清单<span style="font-size: small;">3-2</span>：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单<span style="font-size: small;">3-2</span>：<span style="font-size: small;">Hello World</span>的主代码</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;span&nbsp;style="font-size:&nbsp;small;"&gt;<span style="color: #7f0055;">package</span>&nbsp;com.juvenxu.mvnbook.helloworld;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;HelloWorld&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;String&nbsp;sayHello()&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;"Hello&nbsp;Maven";&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorld().sayHello()&nbsp;);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/span&gt;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;"><span style="font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>这是一个简单的<span style="font-size: small;">Java</span>类，它有一个<span style="font-size: small;">sayHello()</span>方法，返回一个<span style="font-size: small;">String</span>。同时这个类还带有一个<span style="font-size: small;">main</span>方法，创建一个<span style="font-size: small;">HelloWorld</span>实例，调用<span style="font-size: small;">sayHello()</span>方法，并将结果输出到控制台。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">关于该<span style="font-size: small;">Java</span>代码有两点需要注意。首先，在<span style="font-size: small;">95%</span>以上的情况下，我们应该把项目主代码放到<span style="font-size: small;"><em>src/main/java/</em></span>目录下（遵循<span style="font-size: small;">Maven</span>的约定），而无须额外的配置，<span style="font-size: small;">Maven</span>会自动搜寻该目录找到项目主代码。其次，该<span style="font-size: small;">Java</span>类的包名是<span style="font-size: small;">com.juvenxu.mvnbook.helloworld</span>，这与我们之前在<span style="font-size: small;">POM</span>中定义的<span style="font-size: small;">groupId</span>和<span style="font-size: small;">artifactId</span>相吻合。一般来说，项目中<span style="font-size: small;">Java</span>类的包都应该基于项目的<span style="font-size: small;">groupId</span>和<span style="font-size: small;">artifactId</span>，这样更加清晰，更加符合逻辑，也方便搜索构件或者<span style="font-size: small;">Java</span>类。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码编写完毕后，我们使用<span style="font-size: small;">Maven</span>进行编译，在项目根目录下运行命令<span style="font-size: small;">&nbsp;<strong>mvn clean compile&nbsp;</strong></span>，我们会得到如下输出：</p><p style="margin: 0px; padding: 0px;"><span style="font-size: small;"><br /></span></p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;span&nbsp;style="font-size:&nbsp;small;"&gt;[INFO]&nbsp;Scanning&nbsp;<span style="color: #7f0055;">for</span>&nbsp;projects...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Building&nbsp;Maven&nbsp;Hello&nbsp;World&nbsp;Project&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;&nbsp;&nbsp;&nbsp;task-segment:&nbsp;[clean,&nbsp;compile]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[clean:clean&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-clean}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Deleting&nbsp;directory&nbsp;D:\code\hello-world\target&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:resources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-resources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;skip&nbsp;non&nbsp;existing&nbsp;resourceDirectory&nbsp;D:&nbsp;\code\hello-world\src\main\resources&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:compile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-compile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;BUILD&nbsp;SUCCESSFUL&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Total&nbsp;time:&nbsp;<span style="color: #c00000;">1</span>&nbsp;second&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Finished&nbsp;at:&nbsp;Fri&nbsp;Oct&nbsp;<span style="color: #c00000;">09</span>&nbsp;<span style="color: #c00000;">02</span>:<span style="color: #c00000;">08</span>:<span style="color: #c00000;">09</span>&nbsp;CST&nbsp;<span style="color: #c00000;">2009</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Final&nbsp;Memory:&nbsp;9M/16M&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/span&gt;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;"><span style="font-size: small;">clean</span>告诉<span style="font-size: small;">Maven</span>清理输出目录<span style="font-size: small;"><em>target/</em></span>，<span style="font-size: small;">compile</span>告诉<span style="font-size: small;">Maven</span>编译项目主代码，从输出中我们看到<span style="font-size: small;">Maven</span>首先执行了<span style="font-size: small;">clean:clean</span>任务，删除<span style="font-size: small;"><em>target/</em></span>目录，默认情况下<span style="font-size: small;">Maven</span>构建的所有输出都在<span style="font-size: small;"><em>target/</em></span>目录中；接着执行<span style="font-size: small;">resources:resources</span>任务（未定义项目资源，暂且略过）；最后执行<span style="font-size: small;">compiler:compile</span>任务，将项目主代码编译至<span style="font-size: small;"><em>target/classes</em></span>目录<span style="font-size: small;">(</span>编译好的类为<span style="font-size: small;"><em>com/juvenxu/mvnbook/helloworld/HelloWorld.Class</em></span>）。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">上文提到的<span style="font-size: small;">clean:clean</span>、<span style="font-size: small;">resources:resources</span>，以及<span style="font-size: small;">compiler:compile</span>对应了一些<span style="font-size: small;">Maven</span>插件及插件目标，比如<span style="font-size: small;">clean:clean</span>是<span style="font-size: small;">clean</span>插件的<span style="font-size: small;">clean</span>目标，<span style="font-size: small;">compiler:compile</span>是<span style="font-size: small;">compiler</span>插件的<span style="font-size: small;">compile</span>目标，后文会详细讲述<span style="font-size: small;">Maven</span>插件及其编写方法。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">至此，<span style="font-size: small;">Maven</span>在没有任何额外的配置的情况下就执行了项目的清理和编译任务，接下来，我们编写一些单元测试代码并让<span style="font-size: small;">Maven</span>执行自动化测试。<br /><br /></p><h2 style="line-height: 1.5em; margin: 0px 0px 0.5em; padding: 15px 0px 3px 5px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #cccccc; font-size: 16px !important;">3.3 编写测试代码&nbsp;<a name="3349" href="http://hzbook.group.iteye.com/group/wiki/2872-Maven-in-action#top" style="color: #006699; text-decoration: none;"><img alt="Top" src="http://www.iteye.com/images/wiki/top.gif?1324994303" style="border: 0px;" /></a></h2><p style="margin: 0px; padding: 0px; text-indent: 21pt;"><br /></p><div style="padding-top: 5px; padding-left: 5px; font-size: 14px; line-height: 1.8em;"><p style="margin: 0px; padding: 0px;">&nbsp;</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">为了使项目结构保持清晰，主代码与测试代码应该分别位于独立的目录中。3.2节讲过Maven项目中默认的主代码目录是<em>src/main/java</em>，对应地，Maven项目中默认的测试代码目录是<em>src/test/java</em>。因此，在编写测试用例之前，我们先创建该目录。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">在Java世界中，由Kent Beck和Erich Gamma建立的JUnit是事实上的单元测试标准。要使用JUnit，我们首先需要为Hello World项目添加一个JUnit依赖，修改项目的POM如代码清单3-3：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-3：为Hello World的POM添加依赖</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;project&nbsp;xmlns="http://maven.apache.org/POM/4.0.0"&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xsi:schemaLocation="http:<span style="width: auto; border-width: 0px;">//maven.apache.org/POM/4.0.0</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">http:<span style="width: auto; border-width: 0px;">//maven.apache.org/maven-v4_0_0.xsd"&gt;</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;modelVersion&gt;<span style="color: #c00000;">4.0</span>.<span style="color: #c00000;">0</span>&lt;/modelVersion&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;groupId&gt;com.juvenxu.mvnbook&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;artifactId&gt;hello-world&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;version&gt;<span style="color: #c00000;">1.0</span>-SNAPSHOT&lt;/version&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;name&gt;Maven&nbsp;Hello&nbsp;World&nbsp;Project&lt;/name&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;dependencies&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependency&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;junit&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;junit&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;<span style="color: #c00000;">4.7</span>&lt;/version&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;scope&gt;test&lt;/scope&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependency&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;/dependencies&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/project&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp; 代码中添加了dependencies元素，该元素下可以包含多个dependency元素以声明项目的依赖，这里我们添加了一个依赖&#8212;&#8212;groupId是junit，artifactId是junit，version是4.7。前面我们提到groupId、artifactId和version是任何一个Maven项目最基本的坐标，JUnit也不例外，有了这段声明，Maven就能够自动下载junit-4.7.jar。也许你会问，Maven从哪里下载这个jar呢？在Maven之前，我们可以去JUnit的官网下载分发包。而现在有了Maven，它会自动访问中央仓库（<a href="http://repo1.maven.org/maven2/" style="color: #006699; text-decoration: none;">http://repo1.maven.org/maven2/</a>），下载需要的文件。读者也可以自己访问该仓库，打开路径junit/junit/4.7/，就能看到junit-4.7.pom和junit-4.7.jar。本书第6章会详细介绍Maven仓库及中央仓库。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">上述POM代码中还有一个值为test的元素scope，scope为依赖范围，若依赖范围为test则表示该依赖只对测试有效，换句话说，测试代码中的import JUnit代码是没有问题的，但是如果我们在主代码中用import JUnit代码，就会造成编译错误。如果不声明依赖范围，那么默认值就是compile，表示该依赖对主代码和测试代码都有效。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">配置了测试依赖，接着就可以编写测试类，回顾一下前面的HelloWorld类，现在我们要测试该类的sayHello()方法，检查其返回值是否为&#8220;Hello Maven&#8221;。在src/test/java目录下创建文件，其内容如代码清单3-4：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-4：Hello World的测试代码</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">package</span>&nbsp;com.juvenxu.mvnbook.helloworld;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;org.junit.Assert.assertEquals;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;org.junit.Test;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;HelloWorldTest&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464;">@Test</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;testSayHello()&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;helloWorld&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HelloWorld();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;result&nbsp;=&nbsp;helloWorld.sayHello();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(&nbsp;"Hello&nbsp;Maven",&nbsp;result&nbsp;);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">一个典型的单元测试包含三个步骤：一，准备测试类及数据；二，执行要测试的行为；三，检查结果。上述样例中，我们首先初始化了一个要测试的HelloWorld实例，接着执行该实例的sayHello()方法并保存结果到result变量中，最后使用JUnit框架的Assert类检查结果是否为我们期望的&#8221;Hello Maven&#8221;。在JUnit 3中，约定所有需要执行测试的方法都以test开头，这里我们使用了JUnit 4，但我们仍然遵循这一约定，在JUnit 4中，需要执行的测试方法都应该以@Test进行标注。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">测试用例编写完毕之后就可以调用Maven执行测试，运行&nbsp;<strong>mvn clean test</strong>&nbsp;：</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Scanning&nbsp;<span style="color: #7f0055;">for</span>&nbsp;projects...&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Building&nbsp;Maven&nbsp;Hello&nbsp;World&nbsp;Project&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;&nbsp;&nbsp;&nbsp;task-segment:&nbsp;[clean,&nbsp;test]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[clean:clean&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-clean}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Deleting&nbsp;directory&nbsp;D:\git-juven\mvnbook\code\hello-world\target&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:resources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-resources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Downloading:&nbsp;http:<span style="width: auto; border-width: 0px;">//repo1.maven.org/maven2/junit/junit/4.7/junit-4.7.pom</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">1K&nbsp;downloaded&nbsp;&nbsp;(junit-<span style="color: #c00000;">4.7</span>.pom)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:compile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-compile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[resources:testResources&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testResources}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Downloading:&nbsp;http:<span style="width: auto; border-width: 0px;">//repo1.maven.org/maven2/junit/junit/4.7/junit-4.7.jar</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">226K&nbsp;downloaded&nbsp;&nbsp;(junit-<span style="color: #c00000;">4.7</span>.jar)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:testCompile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testCompile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:\&nbsp;code\hello-world\target\test-classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[ERROR]&nbsp;BUILD&nbsp;FAILURE&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compilation&nbsp;failure&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">D:\code\hello-world\src\test\java\com\juvenxu\mvnbook\helloworld\HelloWorldTest.java:[<span style="color: #c00000;">8</span>,<span style="color: #c00000;">5</span>]&nbsp;-source&nbsp;<span style="color: #c00000;">1.3</span>&nbsp;中不支持注释&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">（请使用&nbsp;-source&nbsp;<span style="color: #c00000;">5</span>&nbsp;或更高版本以启用注释）&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #646464;">@Test</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;For&nbsp;more&nbsp;information,&nbsp;run&nbsp;Maven&nbsp;with&nbsp;the&nbsp;-e&nbsp;<span style="color: #7f0055;">switch</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&#8230;&nbsp;&nbsp;</li></ol></div>&nbsp;<p style="margin: 0px; padding: 0px; text-indent: 21pt;">不幸的是构建失败了，不过我们先耐心分析一下这段输出（为了本书的简洁，一些不重要的信息我用省略号略去了）。命令行输入的是mvn clean test，而Maven实际执行的可不止这两个任务，还有clean:clean、resources:resources、compiler:compile、resources:testResources以及compiler:testCompile。暂时我们需要了解的是，在Maven执行测试（test）之前，它会先自动执行项目主资源处理，主代码编译，测试资源处理，测试代码编译等工作，这是Maven生命周期的一个特性，本书后续章节会详细解释Maven的生命周期。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">从输出中我们还看到：Maven从中央仓库下载了junit-4.7.pom和junit-4.7.jar这两个文件到本地仓库（<em>~/.m2/repository</em>）中，供所有Maven项目使用。</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">构建在执行compiler:testCompile任务的时候失败了，Maven输出提示我们需要使用-source 5或更高版本以启动注释，也就是前面提到的JUnit 4的@Test注解。这是Maven初学者常常会遇到的一个问题。由于历史原因，Maven的核心插件之一compiler插件默认只支持编译Java 1.3，因此我们需要配置该插件使其支持Java 5，见代码清单3-5：</p><p style="margin: 0px; padding: 0px; text-indent: 21pt;">代码清单3-5：配置maven-compiler-plugin支持Java 5</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;project&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;build&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugins&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;configuration&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;source&gt;<span style="color: #c00000;">1.5</span>&lt;/source&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;target&gt;<span style="color: #c00000;">1.5</span>&lt;/target&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/configuration&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugins&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&lt;/build&gt;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&lt;/project&gt;&nbsp;&nbsp;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">该POM省略了除插件配置以外的其他部分，我们暂且不去关心插件配置的细节，只需要知道compiler插件支持Java 5的编译。现在再执行<strong>mvn clean test</strong><strong>，</strong>输出如下：</p><p style="margin: 0px; padding: 0px;">&nbsp;</p><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: transparent; width: 675.109375px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码&nbsp;&nbsp;<a title="收藏这段代码" style="color: #006699;"><img src="http://hzbook.group.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[compiler:testCompile&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-testCompile}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Compiling&nbsp;<span style="color: #c00000;">1</span>&nbsp;source&nbsp;file&nbsp;to&nbsp;D:&nbsp;\code\hello-world\target\test-classes&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;[surefire:test&nbsp;{execution:&nbsp;<span style="color: #7f0055;">default</span>-test}]&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;Surefire&nbsp;report&nbsp;directory:&nbsp;D:\code\hello-world\target\surefire-reports&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">-------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;T&nbsp;E&nbsp;S&nbsp;T&nbsp;S&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">-------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Running&nbsp;com.juvenxu.mvnbook.helloworld.HelloWorldTest&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Tests&nbsp;run:&nbsp;<span style="color: #c00000;">1</span>,&nbsp;Failures:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Errors:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Skipped:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Time&nbsp;elapsed:&nbsp;<span style="color: #c00000;">0.055</span>&nbsp;sec&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Results&nbsp;:&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Tests&nbsp;run:&nbsp;<span style="color: #c00000;">1</span>,&nbsp;Failures:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Errors:&nbsp;<span style="color: #c00000;">0</span>,&nbsp;Skipped:&nbsp;<span style="color: #c00000;">0</span>&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;BUILD&nbsp;SUCCESSFUL&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">[INFO]&nbsp;------------------------------------------------------------------------&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&#8230;&nbsp;&nbsp;</li></ol></div><p style="margin: 0px; padding: 0px; text-indent: 21pt;">我们看到compiler:testCompile任务执行成功了，测试代码通过编译之后在<em>target/test-classes</em>下生成了二进制文件，紧接着surefire:test任务运行测试，surefire是Maven世界中负责执行测试的插件，这里它运行测试用例HelloWorldTest，并且输出测试报告，显示一共运行了多少测试，失败了多少，出错了多少，跳过了多少。显然，我们的测试通过了&#8212;&#8212;BUILD SUCCESSFUL。</p></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/410678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-06 11:39 <a href="http://www.blogjava.net/qileilove/articles/410678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven 使用入门编写pom 文件</title><link>http://www.blogjava.net/qileilove/articles/410638.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 05 Mar 2014 03:48:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410638.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410638.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410638.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410638.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410638.html</trackback:ping><description><![CDATA[我们利用ecilpse 创建1个简单的maven项目 来看看他的pom文件<br /><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">就像Make的Makefile、Ant的build.xml一样，Maven项目的核心是pom.xml。POM（Project Object Model，项目对象模型）定义了项目的基本信息，用于描述项目如何构建，声明项目依赖，等等。现在先为Hello World项目编写一个最简单的pom.xml。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">首先创建一个名为helloworld的文件夹，打开该文件夹，新建一个名为pom.xml的文件，输入其内容，如代码清单3-1所示。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">代码清单3-1 Hello World的POM</p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 591.015625px; overflow: auto; background-color: #e6e6e6; line-height: 28px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;?</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">xml</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">version</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"1.0"</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">encoding</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"UTF-8"</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">?&gt;</span>&nbsp;</span></li><li style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">project</span>&nbsp;<span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xmlns</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"http://maven.apache.org/POM/4.0.0"</span>&nbsp;</li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xmlns:xsi</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"http://www.w3.org/2001/XMLSchemainstance"</span>&nbsp;</li><li style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">xsi:schemaLocation</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">="http://maven.apache.org/POM/4.0.0 &nbsp;</span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">http://maven.apache.org/mavenv4_0_0.xsd"</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">modelVersion</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">4.0.0</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">modelVersion</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">groupId</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">com.juvenxu.mvnbook</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">groupId</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">artifactId</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">helloworld</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">artifactId</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">version</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">1.0SNAPSHOT</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">version</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">name</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Maven&nbsp;Hello&nbsp;World&nbsp;Project</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">name</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: decimal outside none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&lt;/</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">project</span><span style="margin: 0px 0px 10px; padding: 7px 0px 4px; border: none; color: #006699; background-color: inherit; width: 635px; font-weight: bold;">&gt;</span>&nbsp;</li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">代码的第一行是XML头，指定了该xml文档的版本和编码方式。紧接着是project元素，project是所有pom.xml的根元素，它还声明了一些POM相关的命名空间及xsd元素，虽然这些属性不是必须的，但使用这些属性能够让第三方工具（如IDE中的XML编辑器）帮助我们快速编辑POM。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">根元素下的第一个子元素modelVersion指定了当前POM模型的版本，对于Maven 2及Maven 3来说，它只能是4.0.0。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">这段代码中最重要的是包含groupId、artifactId和version的三行。这三个元素定义了一个项目基本的坐标，在Maven的世界，任何的jar、pom或者war都是以基于这些基本的坐标进行区分的。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">groupId定义了项目属于哪个组，这个组往往和项目所在的组织或公司存在关联。譬如在googlecode上建立了一个名为myapp的项目，那么groupId就应该是com.googlecode.myapp，如果你的公司是mycom，有一个项目为myapp，那么groupId就应该是com.mycom.myapp。本书中所有的代码都基于groupId com.juvenxu.mvnbook。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">artifactId定义了当前Maven项目在组中唯一的ID，我们为这个Hello World项目定义artifactId为helloworld，本书其他章节代码会分配其他的artifactId。而在前面的groupId为com.googlecode.myapp的例子中，你可能会为不同的子项目（模块）分配artifactId，如myapputil、myappdomain、myappweb等。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">顾名思义，version指定了Hello World项目当前的版本&#8212;&#8212;1.0SNAPSHOT。SNAPSHOT意为快照，说明该项目还处于开发中，是不稳定的版本。随着项目的发展，version会不断更新，如升级为1.0、1.1SNAPSHOT、1.1、2.0等。6.5节会详细介绍SNAPSHOT，第13章会介绍如何使用Maven管理项目版本的升级发布。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">最后一个name元素声明了一个对于用户更为友好的项目名称，虽然这不是必须的，但还是推荐为每个POM声明name，以方便信息交流。</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14px; line-height: 28px;">没有任何实际的Java代码，我们就能够定义一个Maven项目的POM，这体现了Maven的一大优点，它能让项目对象模型最大程度地与实际代码相独立，我们可以称之为解耦，或者正交性。这在很大程度上避免了Java代码和POM代码的相互影响。比如当项目需要升级版本时，只需要修改POM，而不需要更改Java代码；而在POM稳定之后，日常的Java代码开发工作基本不涉及POM的修改。</p><div></div><img src ="http://www.blogjava.net/qileilove/aggbug/410638.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-05 11:48 <a href="http://www.blogjava.net/qileilove/articles/410638.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven的安装配置</title><link>http://www.blogjava.net/qileilove/articles/410596.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 04 Mar 2014 07:50:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410596.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410596.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410596.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410596.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410596.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 2.1 在windows上安装maven先检查JDK&nbsp;Maven是一个java工具，所以请确保jdk环境已经正确安装在你的机器上。&nbsp;首先，请在此下载Maven。这里选择的是apache-maven-2.2.1-bin.zip&nbsp;window 7&nbsp;1.解压apache-maven-2.2.1-bin.zip 到你想要安装的目录。这里我们假设你选择了 C:\Pro...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/articles/410596.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/410596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-04 15:50 <a href="http://www.blogjava.net/qileilove/articles/410596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven简介</title><link>http://www.blogjava.net/qileilove/articles/410540.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 03 Mar 2014 06:46:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/articles/410540.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/410540.html</wfw:comment><comments>http://www.blogjava.net/qileilove/articles/410540.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/410540.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/410540.html</trackback:ping><description><![CDATA[我们学习了 强大的jenkins 下来我们学习其内在的联系的maven &nbsp;通过以前我们学习的文章 可以看到jenkins 和 maven 联系的很紧密<br />让我们来认识认识maven<br /><div>Maven是什么?<br /><div>&nbsp;Apache Maven Project</div><div>&nbsp;Maven是Java项目的构建和管理工具</div><div>&nbsp;Maven是一套项目管理框架，提供了标准的软件</div><div>生命周期模型，涵盖项目的创建、构建、测试、</div><div>集成和部署</div><div>Maven是一套标准，基于一个通用的软件对象模</div><div>型（Project Object Model）Maven提供一系列</div><div>工具（揑件Plug-in）,方便描述和管理项目<br />何为构建？<br />通俗的说就是当我们把代码从版本库中提取出来后，进行编译 &nbsp;单元测试 生成doc 打包 部署等工作 就可以称之为构建<br />maven 是优秀的构建工具<br /><br />maven 使用简单的命令 就能够帮助我们管理这些工具 &nbsp;而且跨平台 消除重复构建 &nbsp;它抽象了构建的生命周期 让我们可以通过配置来实现构建的生命周期 标准化的生命周期有利于项目的构建<br /><br />maven 不仅仅是构建工具<br />它还是一个java类文件管理的仓库，可以帮助我们整理jar文件，全世界的用户都会遵守maven的配置 这样便于整个软件开发的生命周期<br /><br /><br />为什么需要maven<br /><br />maven &nbsp;已经帮我们定制好了整个构建的周期 我们不需要额外的学习别的 增加成本<br /><br />1.3 maven 与极限编程<br /><br />简单<br /><br />交流与反馈<br /><br /><br />测试驱动开发 TDD<br /><br />10分钟构建<br />富有信息的工作区<br /><br /><br /><br />被误解的maven<br /><br /></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/410540.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-03-03 14:46 <a href="http://www.blogjava.net/qileilove/articles/410540.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>