<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sparkle&#039;s Workshop</title>
	<atom:link href="http://weavesky.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://weavesky.com</link>
	<description></description>
	<lastBuildDate>Tue, 24 Apr 2012 03:32:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>4月18日在qcon上的ppt</title>
		<link>http://weavesky.com/2012/04/24/scala-qcon/</link>
		<comments>http://weavesky.com/2012/04/24/scala-qcon/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 03:31:13 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=685</guid>
		<description><![CDATA[Scala View more presentations from popeast]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_12586992"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/popeast/scala-12586992" title="Scala" target="_blank">Scala</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/12586992" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/popeast" target="_blank">popeast</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2012/04/24/scala-qcon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2月25日在珠三角沙龙上的ppt</title>
		<link>http://weavesky.com/2012/04/24/scala-techparty/</link>
		<comments>http://weavesky.com/2012/04/24/scala-techparty/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 03:29:43 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=682</guid>
		<description><![CDATA[Scala View more presentations from popeast]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_11752660"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/popeast/scala-11752660" title="Scala" target="_blank">Scala</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/11752660" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/popeast" target="_blank">popeast</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2012/04/24/scala-techparty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sbt 0.7</title>
		<link>http://weavesky.com/2011/12/30/sbt-7/</link>
		<comments>http://weavesky.com/2011/12/30/sbt-7/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 08:13:06 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[sbt]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=665</guid>
		<description><![CDATA[前言：sbt是一个用scala写的构建工具，跟maven、gradle差不多，目前最新的版本是0.11。不过本文是讲sbt 0.7的使用方法，sbt继承了scala优良的不兼容传统，从0.7升级到0.10是完全不兼容的两个版本，虽然0.7已经基本没人用了，但还是有一些开源项目还没切换到0.11上。我这篇文章比较早就完成了，但因为各种原因现在才发出来。 sbt 0.7的项目地址是 http://code.google.com/p/simple-build-tool/，官方为了让大家尽快升级到0.10以上的版本，已经将这个地址里面大部分文档都删除了，目前要找到0.7的资料已经很难了，建议大家新项目还是直接用0.11。 先来看一下sbt（没有特殊说明的话，以下sbt都是指sbt 0.7）的配置结构，sbt使用maven的约定目录来放置项目文件，比如说src/main/java、src/main/resources等等，当然这是可以通过配置进行修改。而sbt本身的配置，是放在项目根目录下的project目录下，如果你见到一些scala的开源项目有个project目录不要觉得奇怪，那是sbt的配置。如果你的项目是多个子项目组成的，只需要在总的根目录下进行sbt配置即可，不需要像maven那样每个项目下配置pom.xml。 一般来说，sbt的配置有以下三个文件 /project/build.properties /project/build/MyProject.scala （文件名随意） /project/plugins/Plugins.scala （文件名随意） 第一个文件是项目的基本信息配置，这里一个范例 project.organization=org.sparkle project.name=myproject project.version=1.0-SNAPSHOT sbt.version=0.7.7 build.scala.versions=2.9.0-1 前三项对应maven里面的groupId、artifactId、version 后面两项分别定义项目所用的sbt和scala版本 第二个文件是主要的配置文件，得益于scala强大的描述能力，项目配置直接用实际的scala代码来编写，具体的含义直接看代码中的注释 import sbt._ &#160; class MyProject&#40;info: ProjectInfo&#41; extends ParentProject&#40;info&#41; &#123; // 通过at方法定义的变量自动成为额外的jar下载路径 val mavenLocal = &#34;Local Maven Repository&#34; at &#34;file://&#34; + Path.userHome + &#34;/.m2/repository&#34; val central = &#34;central&#34; at &#34;http://192.168.1.88:18081/nexus/content/groups/public/&#34; &#160; // 定义项目路径名、使用的定义类（见下方）、依赖关系（这里web依赖core） lazy <a href='http://weavesky.com/2011/12/30/sbt-7/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>前言：sbt是一个用scala写的构建工具，跟maven、gradle差不多，目前最新的版本是0.11。不过本文是讲sbt 0.7的使用方法，sbt继承了scala优良的不兼容传统，从0.7升级到0.10是完全不兼容的两个版本，虽然0.7已经基本没人用了，但还是有一些开源项目还没切换到0.11上。我这篇文章比较早就完成了，但因为各种原因现在才发出来。</p>
<p>sbt 0.7的项目地址是 http://code.google.com/p/simple-build-tool/，官方为了让大家尽快升级到0.10以上的版本，已经将这个地址里面大部分文档都删除了，目前要找到0.7的资料已经很难了，建议大家新项目还是直接用0.11。</p>
<p>先来看一下sbt（没有特殊说明的话，以下sbt都是指sbt 0.7）的配置结构，sbt使用maven的约定目录来放置项目文件，比如说src/main/java、src/main/resources等等，当然这是可以通过配置进行修改。而sbt本身的配置，是放在项目根目录下的project目录下，如果你见到一些scala的开源项目有个project目录不要觉得奇怪，那是sbt的配置。如果你的项目是多个子项目组成的，只需要在总的根目录下进行sbt配置即可，不需要像maven那样每个项目下配置pom.xml。</p>
<p>一般来说，sbt的配置有以下三个文件</p>
<pre>
/project/build.properties
/project/build/MyProject.scala （文件名随意）
/project/plugins/Plugins.scala （文件名随意）
</pre>
<p>第一个文件是项目的基本信息配置，这里一个范例</p>
<pre>
project.organization=org.sparkle
project.name=myproject
project.version=1.0-SNAPSHOT
sbt.version=0.7.7
build.scala.versions=2.9.0-1
</pre>
<p>前三项对应maven里面的groupId、artifactId、version<br />
后面两项分别定义项目所用的sbt和scala版本</p>
<p>第二个文件是主要的配置文件，得益于scala强大的描述能力，项目配置直接用实际的scala代码来编写，具体的含义直接看代码中的注释</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">import</span> sbt.<span style="color: #000080;">_</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> MyProject<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> ParentProject<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #008000; font-style: italic;">// 通过at方法定义的变量自动成为额外的jar下载路径</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> mavenLocal <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;Local Maven Repository&quot;</span> at <span style="color: #6666FF;">&quot;file://&quot;</span> + Path.<span style="color: #000000;">userHome</span> + <span style="color: #6666FF;">&quot;/.m2/repository&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> central <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;central&quot;</span> at <span style="color: #6666FF;">&quot;http://192.168.1.88:18081/nexus/content/groups/public/&quot;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;">// 定义项目路径名、使用的定义类（见下方）、依赖关系（这里web依赖core）</span>
  lazy <span style="color: #0000ff; font-weight: bold;">val</span> myprojectCore <span style="color: #000080;">=</span> project<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;myproject-core&quot;</span>, <span style="color: #6666FF;">&quot;myproject-core&quot;</span>, <span style="color: #0000ff; font-weight: bold;">new</span> MyprojectCoreProject<span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
  lazy <span style="color: #0000ff; font-weight: bold;">val</span> myprojectWeb <span style="color: #000080;">=</span> project<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;myproject-web&quot;</span>, <span style="color: #6666FF;">&quot;myproject-web&quot;</span>, <span style="color: #0000ff; font-weight: bold;">new</span> MyprojectWebProject<span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span><span style="color: #F78811;">&#41;</span>, myprojectCore<span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;">// 通过类继承来定义通用配置</span>
  <span style="color: #0000ff; font-weight: bold;">abstract</span> <span style="color: #0000ff; font-weight: bold;">class</span> MyprojectBaseProject<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> DefaultProject<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #008000; font-style: italic;">// 编译选项</span>
    <span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> javaCompileOptions <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">super</span>.<span style="color: #000000;">javaCompileOptions</span> ++ javaCompileOptions<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;-encoding&quot;</span>, <span style="color: #6666FF;">&quot;utf8&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// 直接调整ivy配置</span>
    <span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> ivyXML <span style="color: #000080;">=</span>
      <span style="color: #000080;">&lt;</span>dependencies<span style="color: #000080;">&gt;</span>
          <span style="color: #000080;">&lt;</span>exclude module<span style="color: #000080;">=</span><span style="color: #6666FF;">&quot;commons-logging&quot;</span>/<span style="color: #000080;">&gt;</span>
      <span style="color: #000080;">&lt;</span>/dependencies<span style="color: #000080;">&gt;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// 直接定义一个sbt指令，如果用maven实现的话新建一个plugin项目啊</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> deployPath <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;target&quot;</span> / <span style="color: #6666FF;">&quot;deploy&quot;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> deployClean <span style="color: #000080;">=</span> task <span style="color: #F78811;">&#123;</span>
      FileUtilities.<span style="color: #000000;">clean</span><span style="color: #F78811;">&#40;</span>deployPath, log<span style="color: #F78811;">&#41;</span>
      None
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;">// 以下的代码都是定义项目所依赖的类库</span>
  <span style="color: #0000ff; font-weight: bold;">class</span> MyprojectCoreProject<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> MyprojectBaseProject<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> springJdbc <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.springframework&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;spring-jdbc&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;3.0.5.RELEASE&quot;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> springContextSupport <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.springframework&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;spring-context-support&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;3.0.5.RELEASE&quot;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// runtime scope</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> mysqlConnectorJava <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;mysql&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;mysql-connector-java&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;5.1.16&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;runtime&quot;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// test scope</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> junit <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;junit&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;junit&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;4.8.2&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;test&quot;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">class</span> MyprojectWebProject<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> MyprojectBaseProject<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> springWebmvc <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.springframework&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;spring-webmvc&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;3.0.5.RELEASE&quot;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// provided scope</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> jetty6 <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.mortbay.jetty&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;jetty&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;6.1.26&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;provided&quot;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>是不是比maven的pom.xml简洁非常多，而且还可以直接inline使用scala代码实现各种额外的功能，<a href="http://weavesky.com/2011/08/19/write-maven-plugin-1/">maven就要开一个plugin项目才能实现</a> </p>
<p>第三个文件是插件配置，sbt支持插件，可以理解为maven中的插件，大致的写法跟上一个文件很类似</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">import</span> sbt.<span style="color: #000080;">_</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> Plugins<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> PluginDefinition<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #008000; font-style: italic;">//val junitInterface = &quot;com.novocode&quot; % &quot;junit-interface&quot; % &quot;0.7&quot;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/12/30/sbt-7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>如何编写maven plugin（三） 测试</title>
		<link>http://weavesky.com/2011/08/23/write-maven-plugin-3/</link>
		<comments>http://weavesky.com/2011/08/23/write-maven-plugin-3/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 08:23:45 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=653</guid>
		<description><![CDATA[写完一个插件之后，我们就需要对他进行测试 如果我们用人工测试的话，将会非常麻烦，因为maven插件本身的发布流程就非常复杂 你需要编译打包你的maven插件，然后安装到本地库（或远程私库中），然后写一个sample project，再运行，看一下是否正确 当然你也可以用单元测试来解决一些问题，但是单元测试比较难保证插件最终正确，而且maven插件很经常是跟文件打交道 这里我们就需要对maven插件进行自动化的集成测试 maven的生命周期是包含集成测试的，默认是没有绑定任何功能。不过如果你google一下，会找到一些maven进行集成测试的例子，大致就是启动jetty，然后通过http访问验证，再关闭jetty 我们这里使用的是maven-invoker-plugin，它就是用于maven插件的集成测试 先在pom.xml中加入 &#60;build&#62; &#60;plugins&#62; &#60;plugin&#62; &#60;artifactId&#62;maven-invoker-plugin&#60;/artifactId&#62; &#60;configuration&#62; &#60;cloneProjectsTo&#62;${project.build.directory}/it&#60;/cloneProjectsTo&#62; &#60;/configuration&#62; &#60;executions&#62; &#60;execution&#62; &#60;id&#62;integration-test&#60;/id&#62; &#60;goals&#62; &#60;goal&#62;install&#60;/goal&#62; &#60;goal&#62;run&#60;/goal&#62; &#60;/goals&#62; &#60;/execution&#62; &#60;/executions&#62; &#60;/plugin&#62; &#60;/plugins&#62; &#60;/build&#62; cloneProjectsTo是先将测试案例拷贝出来再运行 execution段的设定是把maven-invoker-plugin的两个goal绑定到integration-test上 integration-test这个生命周期会在mvn install之前调用 集成测试的内容放在 src/it 目录下，每新建一个目录代表一个独立的测试，里面放一个完整的maven项目，当然你在这个项目里面需要引入自己编写的maven插件并且运行 另外还需要一个postbuild.groovy文件，放在测试案例的根目录，这个脚本的用处是检查运行后的maven项目是否达到自己要的效果。很明显，看名字就知道用groovy来写，一般我们会检查一下，是否产生了某某文件等等来判定，如果不正确的话抛出异常 然后我们在maven插件目录运行mvn integration-test就能进行集成测试了 如何编写maven plugin（一） 基础 如何编写maven plugin（二） 注入 如何编写maven plugin（三） 测试]]></description>
			<content:encoded><![CDATA[<p>写完一个插件之后，我们就需要对他进行测试<br />
如果我们用人工测试的话，将会非常麻烦，因为maven插件本身的发布流程就非常复杂<br />
你需要编译打包你的maven插件，然后安装到本地库（或远程私库中），然后写一个sample project，再运行，看一下是否正确<br />
当然你也可以用单元测试来解决一些问题，但是单元测试比较难保证插件最终正确，而且maven插件很经常是跟文件打交道</p>
<p>这里我们就需要对maven插件进行自动化的集成测试<br />
maven的生命周期是包含集成测试的，默认是没有绑定任何功能。不过如果你google一下，会找到一些maven进行集成测试的例子，大致就是启动jetty，然后通过http访问验证，再关闭jetty</p>
<p>我们这里使用的是maven-invoker-plugin，它就是用于maven插件的集成测试</p>
<p>先在pom.xml中加入</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-invoker-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cloneProjectsTo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${project.build.directory}/it<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cloneProjectsTo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>integration-test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>install<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>run<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>cloneProjectsTo是先将测试案例拷贝出来再运行<br />
execution段的设定是把maven-invoker-plugin的两个goal绑定到integration-test上<br />
integration-test这个生命周期会在mvn install之前调用</p>
<p>集成测试的内容放在 src/it 目录下，每新建一个目录代表一个独立的测试，里面放一个完整的maven项目，当然你在这个项目里面需要引入自己编写的maven插件并且运行<br />
另外还需要一个postbuild.groovy文件，放在测试案例的根目录，这个脚本的用处是检查运行后的maven项目是否达到自己要的效果。很明显，看名字就知道用groovy来写，一般我们会检查一下，是否产生了某某文件等等来判定，如果不正确的话抛出异常</p>
<p>然后我们在maven插件目录运行mvn integration-test就能进行集成测试了</p>
<ul>
<li><a href="/2011/08/19/write-maven-plugin-1/">如何编写maven plugin（一） 基础</a></li>
<li><a href="/2011/08/22/write-maven-plugin-2/">如何编写maven plugin（二） 注入</a></li>
<li>如何编写maven plugin（三） 测试</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/08/23/write-maven-plugin-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>如何编写maven plugin（二） 注入</title>
		<link>http://weavesky.com/2011/08/22/write-maven-plugin-2/</link>
		<comments>http://weavesky.com/2011/08/22/write-maven-plugin-2/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 08:57:15 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=647</guid>
		<description><![CDATA[Mojo是一个很简单的Java Bean模式的类，你会发现Mojo所继承的AbstractMojo里面之后非常少的方法。那我们需要在Mojo.execute里面获取当前运行中的上下文如何处理呢？答案是注入，就是跟spring ioc差不多的注入方式。 常用的注入主要有两种，第一种是xml配置中的额外设置 比如说我们有这么一个plugin的配置 &#60;plugin&#62; &#60;artifactId&#62;maven-eclipse-plugin&#60;/artifactId&#62; &#60;configuration&#62; &#60;downloadSources&#62;true&#60;/downloadSources&#62; &#60;/configuration&#62; &#60;/plugin&#62; 所有写在configuration里面的属性都可以注入到Mojo中，比如说以下代码 /** * @parameter */ private boolean downloadSources; 就可以通过downloadSources变量获得配置中的值 值得注意的是，这里是不用生成完整的JavaBean模式的get/set的，并且private是有效的 javadoc里面还可以加入其他属性，比如说 /** * @parameter default-value=&#34;true&#34; * @readonly */ private boolean downloadSources; 就是默认为true，并且不能通过配置修改（当然我们这里肯定不会有这样的需求） 更多的javadoc可以参看官方文档中的说明 第二种注入的数据就是上下文，跟HttpServlet.getServletContext这种写法不一样，如果我们需要Mojo运行期的上下文，也是通过注入获得的 /** * @parameter expression=&#34;${project}&#34; * @readonly */ private MavenProject project; &#160; /** * @component * @readonly */ private ArtifactFactory artifactFactory; <a href='http://weavesky.com/2011/08/22/write-maven-plugin-2/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Mojo是一个很简单的Java Bean模式的类，你会发现Mojo所继承的AbstractMojo里面之后非常少的方法。那我们需要在Mojo.execute里面获取当前运行中的上下文如何处理呢？答案是注入，就是跟spring ioc差不多的注入方式。</p>
<p>常用的注入主要有两种，第一种是xml配置中的额外设置<br />
比如说我们有这么一个plugin的配置</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-eclipse-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;downloadSources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/downloadSources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>所有写在configuration里面的属性都可以注入到Mojo中，比如说以下代码</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @parameter
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> downloadSources<span style="color: #339933;">;</span></pre></div></div>

<p>就可以通过downloadSources变量获得配置中的值<br />
值得注意的是，这里是不用生成完整的JavaBean模式的get/set的，并且private是有效的</p>
<p>javadoc里面还可以加入其他属性，比如说</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @parameter default-value=&quot;true&quot;
 * @readonly
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> downloadSources<span style="color: #339933;">;</span></pre></div></div>

<p>就是默认为true，并且不能通过配置修改（当然我们这里肯定不会有这样的需求）<br />
更多的javadoc可以参看官方文档中的说明</p>
<p>第二种注入的数据就是上下文，跟HttpServlet.getServletContext这种写法不一样，如果我们需要Mojo运行期的上下文，也是通过注入获得的</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">/**
 * @parameter expression=&quot;${project}&quot;
 * @readonly
 */
private MavenProject project;
&nbsp;
/**
 * @component
 * @readonly
 */
private ArtifactFactory artifactFactory;</pre></div></div>

<p>例如这里我们就能获得ArtifactFactory和MavenProject<br />
需要注意的是这里可能有两种方法，第一种跟xml配置获得的方法差不多，通过expression指定名字<br />
实际上，你在xml里面，也可以通过${project}获得相应的东西进行一些简单的操作（当然xml里面只能文本描述，这里是一个类）</p>
<p>另外一种就是使用@component这个标注，可以获得一些基本的组件实例</p>
<ul>
<li><a href="/2011/08/19/write-maven-plugin-1/">如何编写maven plugin（一） 基础</a></li>
<li>如何编写maven plugin（二） 注入</li>
<li><a href="/2011/08/23/write-maven-plugin-3/">如何编写maven plugin（三） 测试</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/08/22/write-maven-plugin-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何编写maven plugin（一） 基础</title>
		<link>http://weavesky.com/2011/08/19/write-maven-plugin-1/</link>
		<comments>http://weavesky.com/2011/08/19/write-maven-plugin-1/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 07:41:53 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=639</guid>
		<description><![CDATA[当maven内置的功能不能满足需求的时候怎么办，那就只能给它写插件了。 （话说回来，给maven扩展只能写一个很完整的插件，而不能是一个简单的script，真的是太笨重了） 网络上很多maven的文章，但基本很少谈及如何给它写插件，即使你搜索maven plugin，也只是给你返回一堆如何使用maven插件的文章。希望这边文章能给一些maven使用者带来帮助。 我在这里先假设你已经懂得使用maven，我不会贴出完整的pom.xml文件 首先，你需要创建一个maven项目，插件是一种特殊的maven项目 然后修改pom.xml，将packaging改为maven-plugin &#60;packaging&#62;maven-plugin&#60;/packaging&#62; 通过properties定义maven的版本 &#60;properties&#62; &#60;maven.version&#62;2.2.1&#60;/maven.version&#62; &#60;/properties&#62; maven3已经出了很久，并且兼容maven2，因此我们团队内部都是统一使用maven3，但是我这里编写插件使用的是maven2，可以同时在maven2和maven3下使用，不过其实这个原因并不重要，真正的原因是因为maven3的代码实在太烂了，最初的时候我用maven3的api lib来写，发现里面很多代码根本没有注释，而且很多代码已经废弃，但是并没有明确说明究竟用什么方法代替。最后我使用了maven2中被maven3废弃的api来完成我的功能，跑的挺好的，就是有时可能会有一些使用准备废弃的api的提醒而已。 接着添加依赖 &#60;dependencies&#62; &#60;dependency&#62; &#60;groupId&#62;org.apache.maven&#60;/groupId&#62; &#60;artifactId&#62;maven-plugin-api&#60;/artifactId&#62; &#60;version&#62;${maven.version}&#60;/version&#62; &#60;/dependency&#62; &#60;dependency&#62; &#60;groupId&#62;org.apache.maven&#60;/groupId&#62; &#60;artifactId&#62;maven-core&#60;/artifactId&#62; &#60;version&#62;${maven.version}&#60;/version&#62; &#60;/dependency&#62; &#60;/dependencies&#62; 然后开始创建Mojo类，maven插件里面每一个具体的功能都是一个Mojo 比如说eclipse:clean和eclipse:eclipse就是两个Mojo /** * @goal helloWorld */ public class HelloWorldMojo extends AbstractMojo &#123; public void execute&#40;&#41; throws MojoExecutionException &#123; getLog&#40;&#41;.info&#40;&#34;Hello, world!&#34;&#41;; &#125; &#125; 首先继承AbstractMojo，并且实现execute()方法，这个就是每次调用进入的地方 然后需要在类的Javadoc上定义，这是一个annotation出来之前常用的定义方法（或许未来maven会将它改成annotation，那就能提供编译校验和IDE校验）。我们必须定义@goal，代表运行目标，简单来说就是eclipse:clean中的clean Mojo写在哪个package底下都是可以的 这样，我们就完成了一个简单的maven plugin，然后我们需要一个简单的测试来确定他正确运行 <a href='http://weavesky.com/2011/08/19/write-maven-plugin-1/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>当maven内置的功能不能满足需求的时候怎么办，那就只能给它写插件了。<br />
（话说回来，给maven扩展只能写一个很完整的插件，而不能是一个简单的script，真的是太笨重了）</p>
<p>网络上很多maven的文章，但基本很少谈及如何给它写插件，即使你搜索maven plugin，也只是给你返回一堆如何使用maven插件的文章。希望这边文章能给一些maven使用者带来帮助。</p>
<p>我在这里先假设你已经懂得使用maven，我不会贴出完整的pom.xml文件</p>
<p>首先，你需要创建一个maven项目，插件是一种特殊的maven项目<br />
然后修改pom.xml，将packaging改为maven-plugin</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>通过properties定义maven的版本</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maven.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.2.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/maven.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>maven3已经出了很久，并且兼容maven2，因此我们团队内部都是统一使用maven3，但是我这里编写插件使用的是maven2，可以同时在maven2和maven3下使用，不过其实这个原因并不重要，真正的原因是因为maven3的代码实在太烂了，最初的时候我用maven3的api lib来写，发现里面很多代码根本没有注释，而且很多代码已经废弃，但是并没有明确说明究竟用什么方法代替。最后我使用了maven2中被maven3废弃的api来完成我的功能，跑的挺好的，就是有时可能会有一些使用准备废弃的api的提醒而已。</p>
<p>接着添加依赖</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-plugin-api<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${maven.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${maven.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>然后开始创建Mojo类，maven插件里面每一个具体的功能都是一个Mojo<br />
比如说eclipse:clean和eclipse:eclipse就是两个Mojo</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @goal helloWorld
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorldMojo <span style="color: #000000; font-weight: bold;">extends</span> AbstractMojo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MojoExecutionException
    <span style="color: #009900;">&#123;</span>
        getLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello, world!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>首先继承AbstractMojo，并且实现execute()方法，这个就是每次调用进入的地方<br />
然后需要在类的Javadoc上定义，这是一个annotation出来之前常用的定义方法（或许未来maven会将它改成annotation，那就能提供编译校验和IDE校验）。我们必须定义@goal，代表运行目标，简单来说就是eclipse:clean中的clean<br />
Mojo写在哪个package底下都是可以的</p>
<p>这样，我们就完成了一个简单的maven plugin，然后我们需要一个简单的测试来确定他正确运行<br />
先通过maven install将它安装到本地仓库</p>
<p>然后打开任意maven的项目（比如说我们原来已经在用maven的项目），在pom.xml增加一个plugin</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>compile<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>helloWorld<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>需要留意的是phase部分，我们将这个plugin绑定到compile这个周期<br />
然后我们运行mvn compile，就能成功看见Hello, world!输出<br />
（当然你也可以直接通过命令行运行，需要带上完整的groupId和artifactId才能调用）</p>
<ul>
<li>如何编写maven plugin（一） 基础</li>
<li><a href="/2011/08/22/write-maven-plugin-2/">如何编写maven plugin（二） 注入</a></li>
<li><a href="/2011/08/23/write-maven-plugin-3/">如何编写maven plugin（三） 测试</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/08/19/write-maven-plugin-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用maven进行scala项目的构建</title>
		<link>http://weavesky.com/2011/08/16/maven-scala/</link>
		<comments>http://weavesky.com/2011/08/16/maven-scala/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 03:49:10 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=627</guid>
		<description><![CDATA[目标： 1、命令行用maven进行scala项目构建 2、产生eclipse项目文件 pom.xml文件 &#60;project xmlns=&#34;http://maven.apache.org/POM/4.0.0&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xsi:schemaLocation=&#34;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&#34;&#62; &#60;groupId&#62;com.xxx&#60;/groupId&#62; &#60;artifactId&#62;xxx&#60;/artifactId&#62; &#60;version&#62;1.0-SNAPSHOT&#60;/version&#62; &#60;modelVersion&#62;4.0.0&#60;/modelVersion&#62; &#160; &#60;properties&#62; &#60;scala.version&#62;2.8.1&#60;/scala.version&#62; &#60;/properties&#62; &#160; &#60;build&#62; &#60;plugins&#62; &#60;plugin&#62; &#60;artifactId&#62;maven-eclipse-plugin&#60;/artifactId&#62; &#60;configuration&#62; &#60;downloadSources&#62;true&#60;/downloadSources&#62; &#60;buildcommands&#62; &#60;buildcommand&#62;org.scala-ide.sdt.core.scalabuilder&#60;/buildcommand&#62; &#60;/buildcommands&#62; &#60;projectnatures&#62; &#60;projectnature&#62;org.scala-ide.sdt.core.scalanature&#60;/projectnature&#62; &#60;projectnature&#62;org.eclipse.jdt.core.javanature&#60;/projectnature&#62; &#60;/projectnatures&#62; &#60;classpathContainers&#62; &#60;classpathContainer&#62;org.eclipse.jdt.launching.JRE_CONTAINER&#60;/classpathContainer&#62; &#60;classpathContainer&#62;org.scala-ide.sdt.launching.SCALA_CONTAINER&#60;/classpathContainer&#62; &#60;/classpathContainers&#62; &#60;sourceIncludes&#62; &#60;sourceInclude&#62;**/*.scala&#60;/sourceInclude&#62; &#60;/sourceIncludes&#62; &#60;/configuration&#62; &#60;/plugin&#62; &#60;plugin&#62; &#60;groupId&#62;org.scala-tools&#60;/groupId&#62; &#60;artifactId&#62;maven-scala-plugin&#60;/artifactId&#62; &#60;executions&#62; &#60;execution&#62; &#60;goals&#62; &#60;goal&#62;compile&#60;/goal&#62; &#60;goal&#62;testCompile&#60;/goal&#62; &#60;/goals&#62; &#60;/execution&#62; &#60;/executions&#62; &#60;/plugin&#62; &#60;plugin&#62; &#60;groupId&#62;org.codehaus.mojo&#60;/groupId&#62; &#60;artifactId&#62;build-helper-maven-plugin&#60;/artifactId&#62; <a href='http://weavesky.com/2011/08/16/maven-scala/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><strong>目标：</strong><br />
1、命令行用maven进行scala项目构建<br />
2、产生eclipse项目文件</p>
<p><strong>pom.xml文件</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modelVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modelVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scala.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.8.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scala.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-eclipse-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;downloadSources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/downloadSources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;buildcommands<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;buildcommand<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.scala-ide.sdt.core.scalabuilder<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/buildcommand<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/buildcommands<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;projectnatures<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;projectnature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.scala-ide.sdt.core.scalanature<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/projectnature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;projectnature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jdt.core.javanature<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/projectnature<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/projectnatures<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpathContainers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpathContainer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jdt.launching.JRE_CONTAINER<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/classpathContainer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpathContainer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.scala-ide.sdt.launching.SCALA_CONTAINER<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/classpathContainer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/classpathContainers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sourceIncludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sourceInclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>**/*.scala<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sourceInclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sourceIncludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.scala-tools<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-scala-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>compile<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>testCompile<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>build-helper-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>add-source<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>generate-sources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>add-source<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
								<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>src/main/scala<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>add-test-source<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>generate-sources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>add-test-source<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
								<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>src/test/scala<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>要点分析</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scala.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.8.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scala.version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>通过properties定义scala的版本<br />
因为scala的版本是不兼容的，比如说2.8编译的class文件不能跟2.9的类库一起使用<br />
这个定义同时会影响maven-scala-plugin中使用的scala版本<br />
当然你也可以在dependencies中通过${scala.version}使用这个版本号</p>
<p>maven-eclipse-plugin部分是产生eclipse项目，对应使用scala-ide<br />
打开downloadSources下载类库源代码，可以在eclipse中直接查看<br />
sourceIncludes段必须加入，不然会出现代码目录中看不到scala文件的情况</p>
<p>maven-scala-plugin段用于命令行用maven进行构建</p>
<p>build-helper-maven-plugin段用于引入额外的代码目录<br />
这个配置同时对命令行构建和eclipse项目生成有效<br />
我这个是一个mixed Java/Scala项目</p>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/08/16/maven-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Sandy Bridge上安装Snow Leopard</title>
		<link>http://weavesky.com/2011/05/03/sandy-bridge-snow-leopard/</link>
		<comments>http://weavesky.com/2011/05/03/sandy-bridge-snow-leopard/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:18:15 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=608</guid>
		<description><![CDATA[把家里的主机从AMD平台转到Intel平台之后，就一直想在上面装一个Snow Leopard来使用，虽然曾经拥有过一台最早的Intel MacBook，不过已经有一段时间没有使用Mac OS了。坦白说，三大操作系统（Windows、Linux、Mac OS）里面，Mac OS同时拥有对程序员良好的*NIX内核，比美Windows的操作界面（甚至更好），可能是最好的开发平台。 Mac的笔记本不算太贵，个人比较推荐，至于台式机部分，Mac mini有点太弱（不过外观相当好），iMac也相当划算（前提是你还没买显示器），我已经有了自己的主机，所以打算在上面装黑苹果。不过，如果你想用Mac OS来开发的话，其实最好买一台真正的Mac，这样可以减少你折腾的时间，把时间花在使用上。 先来说我的机器主要配置： 华擎 H67M + i5 2300 + 华硕 GT240（后加） 如果你不是太新或者太旧的Intel CPU的话，基本上都能支持，因为Mac用过这些CPU，所以AMD比较悲剧了，不过你依然能找到一些被修改过的kernel来使用。Sandy Bridge的CPU属于太新的CPU，虽然最新的MacBook Pro是使用这个CPU，但不知道为什么苹果是给他做了一个单独的10.6.7的更新包，也就是说默认的10.6.7更新包里面所包含的kernel是不支持Sandy Bridge的，有人从专用更新包里面提取了kernel出来，但是不知道为什么在很多主板上，这个kernel不能启动，我的主板就是这样的情况，因此我最后只能使用修改过的kernel。 一般来说，主板和CPU是决定你是否能够启动Snow Leopard的主要因素。不过，决定你的黑苹果是否好用的就是能否找到外设的驱动了，比如说网卡、声卡、显卡等等。目前黑苹果已经很成熟了，能找到很多爱好者写的驱动。我的主板上的外设基本上都被支持，可惜i5 2300的核显暂时还没有解决方案（虽然最新版的MacBook Pro就是使用这个显卡，理论上苹果已经提供了它的驱动，可惜目前还没有办法在黑苹果上使用它），于是上淘宝买了一张GT240，完美支持。 安装方法有几种，一个就是用一些已经打包好的整合碟，里面有破解内核和第三方驱动等，如果你是AMD的CPU最好用这些碟来安装，另一个就是用iBoot+MultiBeast和原版碟来安装，只支持Intel CPU，如果你是Intel CPU的话，推荐用这个方案，装出来的系统比较纯正一点。 网上已经有一些iBoot+MultiBeast的安装方法，大家可以搜索参考一些，这里就不说一些细节，重点是在Sandy Bridge的问题上。到http://www.tonymacx86.com/下载iBoot，必须注意的是必须使用Legacy版，因为Sandy Bridge CPU未被支持的缘故。刻碟启动，然后换Snow Leopard安装碟，安装。装完之后再用iBoot启动，就可以引导硬盘中的系统。 启动成功后，先安装10.6.7更新，不要重启，下载MultiBeast，安装。虽然DSDT的方法是最完美的，不过也很麻烦，需要导出主板等的BIOS来修改。我这里就用EasyBeast的方法来安装，必选EasyBeast、System Utilities，下面的驱动就看自己需要选择。声卡部分，我用ALC8xxHDA（优先选择，不行的话可以尝试VoodooHDA），还需要选上AppleHDA Rollback，这里还需要把自己的声卡ID写进DSDT里面，因为我不用DSDT，所以还需要勾上Non-DSDT HDAEnabler里面相应的声卡型号，显卡部分直接勾上NVEnabler就行了。 接下来是针对Sandy Bridge的处理，官方给出的方法是一个BridgeHelper的软件，其实就是安装最新的MacBook Pro里面的kernel，你可以先试一下这个方案，如果可以启动系统的话，优先选择这个方案。可惜我的主板不行，于是我从iBoot Legacy里提取了kernel，替换系统的。 另外，我还遇到一个问题是鼠标的移动会很卡的情况，好像是因为时钟频率不正确的缘故，需要在启动参数里面增加busratio=28（28是我的CPU的实际倍频数） 这样，我的黑苹果就装好了。虽然还有些小问题，不过我暂时不打算处理了，能正常使用就行了。 下一步需要处理的问题有 1、休眠。需要相应kernel的sleep enabler。由于我的是台式机，我觉得休眠不是很重要就不处理了。 2、HDMI输出，并且带上声音。是的，黑苹果也能这样。tonymacx86上已经提供了解决方案 3、DSDT，为了让系统属性里面正确显示各种硬件信息 4、真正的Sandy Bridge支持。CPU和显卡]]></description>
			<content:encoded><![CDATA[<p>把家里的主机从AMD平台转到Intel平台之后，就一直想在上面装一个Snow Leopard来使用，虽然曾经拥有过一台最早的Intel MacBook，不过已经有一段时间没有使用Mac OS了。坦白说，三大操作系统（Windows、Linux、Mac OS）里面，Mac OS同时拥有对程序员良好的*NIX内核，比美Windows的操作界面（甚至更好），可能是最好的开发平台。</p>
<p>Mac的笔记本不算太贵，个人比较推荐，至于台式机部分，Mac mini有点太弱（不过外观相当好），iMac也相当划算（前提是你还没买显示器），我已经有了自己的主机，所以打算在上面装黑苹果。不过，如果你想用Mac OS来开发的话，其实最好买一台真正的Mac，这样可以减少你折腾的时间，把时间花在使用上。</p>
<p>先来说我的机器主要配置：<br />
华擎 H67M + i5 2300 + 华硕 GT240（后加）</p>
<p>如果你不是太新或者太旧的Intel CPU的话，基本上都能支持，因为Mac用过这些CPU，所以AMD比较悲剧了，不过你依然能找到一些被修改过的kernel来使用。Sandy Bridge的CPU属于太新的CPU，虽然最新的MacBook Pro是使用这个CPU，但不知道为什么苹果是给他做了一个单独的10.6.7的更新包，也就是说默认的10.6.7更新包里面所包含的kernel是不支持Sandy Bridge的，有人从专用更新包里面提取了kernel出来，但是不知道为什么在很多主板上，这个kernel不能启动，我的主板就是这样的情况，因此我最后只能使用修改过的kernel。</p>
<p>一般来说，主板和CPU是决定你是否能够启动Snow Leopard的主要因素。不过，决定你的黑苹果是否好用的就是能否找到外设的驱动了，比如说网卡、声卡、显卡等等。目前黑苹果已经很成熟了，能找到很多爱好者写的驱动。我的主板上的外设基本上都被支持，可惜i5 2300的核显暂时还没有解决方案（虽然最新版的MacBook Pro就是使用这个显卡，理论上苹果已经提供了它的驱动，可惜目前还没有办法在黑苹果上使用它），于是上淘宝买了一张GT240，完美支持。</p>
<p>安装方法有几种，一个就是用一些已经打包好的整合碟，里面有破解内核和第三方驱动等，如果你是AMD的CPU最好用这些碟来安装，另一个就是用iBoot+MultiBeast和原版碟来安装，只支持Intel CPU，如果你是Intel CPU的话，推荐用这个方案，装出来的系统比较纯正一点。</p>
<p>网上已经有一些iBoot+MultiBeast的安装方法，大家可以搜索参考一些，这里就不说一些细节，重点是在Sandy Bridge的问题上。到http://www.tonymacx86.com/下载iBoot，必须注意的是<strong>必须使用Legacy版</strong>，因为Sandy Bridge CPU未被支持的缘故。刻碟启动，然后换Snow Leopard安装碟，安装。装完之后再用iBoot启动，就可以引导硬盘中的系统。</p>
<p>启动成功后，先安装10.6.7更新，不要重启，下载MultiBeast，安装。虽然DSDT的方法是最完美的，不过也很麻烦，需要导出主板等的BIOS来修改。我这里就用EasyBeast的方法来安装，必选EasyBeast、System Utilities，下面的驱动就看自己需要选择。声卡部分，我用ALC8xxHDA（优先选择，不行的话可以尝试VoodooHDA），还需要选上AppleHDA Rollback，这里还需要把自己的声卡ID写进DSDT里面，因为我不用DSDT，所以还需要勾上Non-DSDT HDAEnabler里面相应的声卡型号，显卡部分直接勾上NVEnabler就行了。</p>
<p>接下来是针对Sandy Bridge的处理，官方给出的方法是一个BridgeHelper的软件，其实就是安装最新的MacBook Pro里面的kernel，你可以先试一下这个方案，如果可以启动系统的话，优先选择这个方案。可惜我的主板不行，于是我<strong>从iBoot Legacy里提取了kernel</strong>，替换系统的。</p>
<p>另外，我还遇到一个问题是鼠标的移动会很卡的情况，好像是因为时钟频率不正确的缘故，需要在启动参数里面<strong>增加busratio=28</strong>（28是我的CPU的实际倍频数）</p>
<p>这样，我的黑苹果就装好了。虽然还有些小问题，不过我暂时不打算处理了，能正常使用就行了。</p>
<p>下一步需要处理的问题有<br />
1、休眠。需要相应kernel的sleep enabler。由于我的是台式机，我觉得休眠不是很重要就不处理了。<br />
2、HDMI输出，并且带上声音。是的，黑苹果也能这样。tonymacx86上已经提供了解决方案<br />
3、DSDT，为了让系统属性里面正确显示各种硬件信息<br />
4、真正的Sandy Bridge支持。CPU和显卡</p>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2011/05/03/sandy-bridge-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB介绍</title>
		<link>http://weavesky.com/2010/11/22/mongodb/</link>
		<comments>http://weavesky.com/2010/11/22/mongodb/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 08:59:25 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=603</guid>
		<description><![CDATA[2010-11-20在广州小沙龙的ppt，时间比较匆忙写的比较简单 MongoDB介绍 View more presentations from popeast.]]></description>
			<content:encoded><![CDATA[<div id="__ss_5855482" style="width: 425px;">2010-11-20在广州小沙龙的ppt，时间比较匆忙写的比较简单</div>
<div style="width: 425px;"></div>
<div style="width: 425px;"><strong><a title="MongoDB介绍" href="http://www.slideshare.net/popeast/mongodb-5855482">MongoDB介绍</a></strong><object id="__sse5855482" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mongodb-101121193802-phpapp02&amp;stripped_title=mongodb-5855482&amp;userName=popeast" /><param name="name" value="__sse5855482" /><param name="allowfullscreen" value="true" /><embed id="__sse5855482" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mongodb-101121193802-phpapp02&amp;stripped_title=mongodb-5855482&amp;userName=popeast" name="__sse5855482" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<div id="__ss_5855482" style="width: 425px;">
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/popeast">popeast</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2010/11/22/mongodb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>基于MINA构建简单高性能的NIO应用-优化指南</title>
		<link>http://weavesky.com/2010/02/19/mina-article-4/</link>
		<comments>http://weavesky.com/2010/02/19/mina-article-4/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:26:13 +0000</pubDate>
		<dc:creator>Sparkle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[mina]]></category>

		<guid isPermaLink="false">http://weavesky.com/?p=600</guid>
		<description><![CDATA[本文为Sparkle发于《程序员》2008年2月刊的文章，与《程序员》的协议，可以在个人博客中发布，转载请保留出处。 优化指南 MINA默认配置的性能并不是很高的，部分原因是MINA目前还保留初期版本的架构，另外一个原因是因为JVM的发展。 首先我们关闭默认的ThreadModel设置 IoAcceptor acceptor = ...; IoServiceConfig acceptorConfig = acceptor.getDefaultConfig&#40;&#41;; acceptorConfig.setThreadModel&#40;ThreadModel.MANUAL&#41;; ThreadModel是一个很简单的线程实现，用于IoService。但是它实在太弱，以至于在并发环境产生大量问题。在MINA 2.0中，ThreadModel直接被取消。你应该使用ExecutorFilter来实现线程。 然后我们增加I/O处理线程(Article by Sparkle) 每一个Acceptor/Connector都使用一个线程来处理连接，然后把连接发送给I/O processor进行读写操作，我们只可以修改I/O processor使用的线程数，用以下代码设置 IoAcceptor acceptor = new SocketAcceptor&#40;Runtime.getRuntime&#40;&#41;.availableProcessors&#40;&#41; + 1, Executors.newCachedThreadPool&#40;&#41;&#41;; 当然是要将ExecutorFilter加入，上文已经很详细地描述了 acceptor.getDefaultConfig&#40;&#41;.getFilterChain&#40;&#41;.addLast&#40;&#34;threadPool&#34;, new ExecutorFilter&#40;Executors.newCachedThreadPool&#40;&#41;&#41;; 笔者在开发过程中，多次遇到OutOfMemoryError，经过研究之后才发现原因。MINA默认是使用direct memory实现ByteBuffer池的方案（以下简称direct buffer），通过JNI在内存开辟一段空间来使用，该方案在早期的MINA版本中是一个非常好的特性，那是因为MINA开发初期，JVM并没有现在的强大，带有池效果的direct buffer性能比较好。但是当我们使用-Xms -Xmx等指令增加JVM可使用的内存，那仅仅增加了堆的内存空间，而direct memory的空间并没有增加，导致MINA实际使用的时候经常出现OutOfMemoryError。如果你的确想使用direct memory，可以通过-XX:MaxDirectMemorySize选项来设置。不过笔者不建议这样做，因为最新的测试表明，在现代的JVM里面，direct memory比堆的表现更差。这里可能有读者会觉得奇怪，为什么不用池，而要用堆呢，而且还需要gc。那是因为现在的JVM gc能力已经很强了，而且在并发环境里面，pool的同步也是一个性能的问题。我们可以通过这样的代码进行设置(Article by Sparkle) ByteBuffer.setUseDirectBuffers&#40;false&#41;; ByteBuffer.setAllocator&#40;new SimpleByteBufferAllocator&#40;&#41;&#41;; MINA 2.0已经默认把直接内存分配改成堆，为了提供最好的性能和稳定性。 最后一条优化技巧就是，把你的应用部署在Linux上，并且打开Java NIO使用Linux epoll的功能。可能你还没听过epoll，但是你应该听过Lighttpd、Nginx、Squid等，得益于epoll，它们提供很高的网络性能，还占用非常少的系统资源。JDK6已经默认把epoll配置打开，因此笔者建议把你的应用部署在JDK6上面，也同时因为JDK6还有别的优化特性。如果你的应用必须部署在JDK5上，你也可以通过参数把epoll支持打开。 文章快速索引 前言 一个简单的例子 <a href='http://weavesky.com/2010/02/19/mina-article-4/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>本文为Sparkle发于《程序员》2008年2月刊的文章，与《程序员》的协议，可以在个人博客中发布，转载请保留出处。</p></blockquote>
<p><strong>优化指南</strong><br />
MINA默认配置的性能并不是很高的，部分原因是MINA目前还保留初期版本的架构，另外一个原因是因为JVM的发展。</p>
<p>首先我们关闭默认的ThreadModel设置</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">IoAcceptor acceptor <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span>
IoServiceConfig acceptorConfig <span style="color: #339933;">=</span> acceptor.<span style="color: #006633;">getDefaultConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
acceptorConfig.<span style="color: #006633;">setThreadModel</span><span style="color: #009900;">&#40;</span>ThreadModel.<span style="color: #006633;">MANUAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ThreadModel是一个很简单的线程实现，用于IoService。但是它实在太弱，以至于在并发环境产生大量问题。在MINA 2.0中，ThreadModel直接被取消。你应该使用ExecutorFilter来实现线程。</p>
<p>然后我们增加I/O处理线程<span style="color: #ffffff;">(Article by Sparkle)</span><br />
每一个Acceptor/Connector都使用一个线程来处理连接，然后把连接发送给I/O processor进行读写操作，我们只可以修改I/O processor使用的线程数，用以下代码设置</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">IoAcceptor acceptor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SocketAcceptor<span style="color: #009900;">&#40;</span><span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">availableProcessors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span>, Executors.<span style="color: #006633;">newCachedThreadPool</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>当然是要将ExecutorFilter加入，上文已经很详细地描述了</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">acceptor.<span style="color: #006633;">getDefaultConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFilterChain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addLast</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;threadPool&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> ExecutorFilter<span style="color: #009900;">&#40;</span>Executors.<span style="color: #006633;">newCachedThreadPool</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>笔者在开发过程中，多次遇到OutOfMemoryError，经过研究之后才发现原因。MINA默认是使用direct memory实现ByteBuffer池的方案（以下简称direct buffer），通过JNI在内存开辟一段空间来使用，该方案在早期的MINA版本中是一个非常好的特性，那是因为MINA开发初期，JVM并没有现在的强大，带有池效果的direct buffer性能比较好。但是当我们使用-Xms -Xmx等指令增加JVM可使用的内存，那仅仅增加了堆的内存空间，而direct memory的空间并没有增加，导致MINA实际使用的时候经常出现OutOfMemoryError。如果你的确想使用direct memory，可以通过-XX:MaxDirectMemorySize选项来设置。不过笔者不建议这样做，因为最新的测试表明，在现代的JVM里面，direct memory比堆的表现更差。这里可能有读者会觉得奇怪，为什么不用池，而要用堆呢，而且还需要gc。那是因为现在的JVM gc能力已经很强了，而且在并发环境里面，pool的同步也是一个性能的问题。我们可以通过这样的代码进行设置<span style="color: #ffffff;">(Article by Sparkle)</span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ByteBuffer.<span style="color: #006633;">setUseDirectBuffers</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ByteBuffer.<span style="color: #006633;">setAllocator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimpleByteBufferAllocator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>MINA 2.0已经默认把直接内存分配改成堆，为了提供最好的性能和稳定性。</p>
<p>最后一条优化技巧就是，把你的应用部署在Linux上，并且打开Java NIO使用Linux epoll的功能。可能你还没听过epoll，但是你应该听过Lighttpd、Nginx、Squid等，得益于epoll，它们提供很高的网络性能，还占用非常少的系统资源。JDK6已经默认把epoll配置打开，因此笔者建议把你的应用部署在JDK6上面，也同时因为JDK6还有别的优化特性。如果你的应用必须部署在JDK5上，你也可以通过参数把epoll支持打开。</p>
<p><strong>文章快速索引</strong></p>
<ol>
<li><a href="http://weavesky.com/2010/02/19/mina-article-1/">前言</a></li>
<li><a href="http://weavesky.com/2010/02/19/mina-article-2/">一个简单的例子</a></li>
<li><a href="http://weavesky.com/2010/02/19/mina-article-3/">MINA架构</a></li>
<li>优化指南</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://weavesky.com/2010/02/19/mina-article-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

