<?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>This is my blog &#187; maven</title>
	<atom:link href="http://www.ronniealleva.org/index.php/category/maven/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ronniealleva.org</link>
	<description>There are many like it but this one is mine</description>
	<lastBuildDate>Mon, 10 May 2010 07:06:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A better JMeter Maven plugin</title>
		<link>http://www.ronniealleva.org/index.php/2008/12/22/a-better-jmeter-maven-plugin/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/12/22/a-better-jmeter-maven-plugin/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 06:38:46 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[jmeter]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/?p=20</guid>
		<description><![CDATA[UPDATE: You can find the information about the JMeter Maven plugin here
Recently my co-worker James suggested we automate our tests on our project using JMeter and gave me his webpage about the trials and tribulations he went through to get it set up.  It linked to a wiki page, in which someone had created a [...]]]></description>
			<content:encoded><![CDATA[<p><i>UPDATE: You can find the information about the JMeter Maven plugin <a href="http://www.ronniealleva.org/index.php/maven-jmeter-plugin/">here</a></i></p>
<p>Recently my co-worker <a href="http://jlorenzen.blogspot.com/" target="_blank">James</a> suggested we automate our tests on our project using JMeter and gave me his <a href="http://jlorenzen.blogspot.com/2008/03/automated-performance-tests-using.html" target="_blank">webpage</a> about the trials and tribulations he went through to get it set up.  It linked to a <a href="http://wiki.apache.org/jakarta-jmeter/JMeterMavenPlugin">wiki page</a>, in which someone had created a JMeter plugin for Maven.</p>
<p>Well awesome, it shouldn&#8217;t be too hard to set up.  And it wasn&#8217;t, I had the JMeter tests up and running in a short amount of time.  But one of the problems was that I wanted to set it up in a more generic way so that we could define different parameters on each of the CI environments we ran.  </p>
<p>For this task, I first tried using filtering in maven, which I got working.  But what you end up with is a JMX file that is basically unusable by default in JMeter. If you ever wanted to run it again standalone in JMeter, you&#8217;d have to modify the variables in the JMX file to work correctly.  Vice versa, if you set up your test using JMeter, you have to remember to modify it so that the maven variables you need are in the places you need them.</p>
<p>JMeter already has a system in it where you can define variables in the JMX files (and give them defaults, fancy la la!).  For example, say you want to define a variable for a host name.  Inside your JMeter JMX file, you can do something like this:</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;stringProp</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HTTPSampler.domain&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>${__P(someVariableName, localhost)}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/stringProp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now, you have defined someVariableName to be a variable within your JMX file.  The second value, in this case localhost, is the default if no variable override has been given.</p>
<p>The way to override these variables is with the -J option on the command, in this form:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">-JsomeVariableName</span>=yourhost.com</pre></div></div>

<p>and all the variables called someVariableName will have the value yourhost.com.</p>
<p>Now, with the minor modifications I have made to the JMeter Maven plugin, you can now define the values for these variables inside of your pom.xml, like so:</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;jmeterUserProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;someVariableName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>yourhost.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/someVariableName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jmeterUserProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>and it is just the same as using -J on the JMeter command line.</p>
<p>The way we&#8217;re actually going to use it is to combine it with maven variables, like so:</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;jmeterUserProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;someVariableName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${ourhostname}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/someVariableName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jmeterUserProperties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So now, we can just do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mvn <span style="color: #660033;">-Dourhostname</span>=ourspecialhost ...</pre></div></div>

<p>and be able to run site specific JMeter tests with only changing the arguments on the command-line.</p>
<p>I will be putting together a page in the next day or so with all the libraries needed to set this up, similar to the wiki page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/12/22/a-better-jmeter-maven-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Maven and skinny wars</title>
		<link>http://www.ronniealleva.org/index.php/2008/03/06/maven-and-skinny-wars/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/03/06/maven-and-skinny-wars/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 15:38:51 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/index.php/2008/03/06/maven-and-skinny-wars/</guid>
		<description><![CDATA[As I explained in this post here, we used the magical Maven groovy plugin to check when our EAR gets to big, and fail the build.  It works great, because now we get instant notification in our CI environment when something is amiss, which might get&#8230;um&#8230;missed.  So our build has been failing lately, intermittently because [...]]]></description>
			<content:encoded><![CDATA[<p>As I explained in this <a href="http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/">post here</a>, we used the magical Maven groovy plugin to check when our EAR gets to big, and fail the build.  It works great, because now we get instant notification in our CI environment when something is amiss, which might get&#8230;um&#8230;missed.  So our build has been failing lately, intermittently because the EAR has been too big.</p>
<p>The problem was the latest version of the Maven war plugin (2.1-alpha-2-SNAPSHOT) changes the way that skinny WARs are created for packaging in EARs. The documentation hasn&#8217;t quite made it to the <a href="http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html">website</a> yet.  Instead of using &lt;warSourceExludes&gt; to exclude the JARs that you do not want, you have to now use &lt;packagingExcludes&gt;.  It&#8217;s described in this bug <a href="http://jira.codehaus.org/browse/MWAR-135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/03/06/maven-and-skinny-wars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Groovy Maven plugin to do magic</title>
		<link>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 18:53:47 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/</guid>
		<description><![CDATA[Recently, we had an issue that came up with creating our EAR for our web applications.  We were trying to package up individual WARs in an EAR so they could share the same libraries and such and only load stuff used between them once, to save on memory.
We had it working great and then [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we had an issue that came up with creating our EAR for our web applications.  We were trying to package up individual WARs in an EAR so they could share the same libraries and such and only load stuff used between them once, to save on memory.</p>
<p>We had it working great and then something ridiculous happened that caused WARs with their complete libraries (as opposed to stripped-down ones) to be included in the EAR, for no apparent reason.  This caused a number of headaches and issues with the application, that we didn&#8217;t know until it was deployed, because we failed to recognize that the EAR had nearly doubled in size.</p>
<p>You may be wondering, &#8220;Hey, I just read two of your dumb paragraphs and I haven&#8217;t seen the word &#8216;groovy&#8217;, &#8216;maven&#8217;, &#8216;magic&#8217;, or &#8216;using&#8217; yet.&#8221;  Well, wouldn&#8217;t it have been nice if we knew instantly that the EAR had grown, when trying to build?  That&#8217;s where the <strong>using </strong>the <strong>groovy maven magic </strong>plugin can help!</p>
<p>My co-worker <a href="http://jlorenzen.blogspot.com/">James </a>and I attempted to use the maven enforcer plugin, but it would have taken too much work and we would have needed to write a custom plugin for it to check the size of the EAR.  So we decided to do it with Groovy.  Here&#8217;s the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td 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;groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo.groovy<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>groovy-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;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-beta-4-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;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>verify<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>execute<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;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
          def ear = new File(&quot;$pom.basedir/target/${project.artifactId}-${project.version}.${project.packaging}&quot;)
          log.info(&quot;${ear?.length()}&quot;);
          def maxsize = project.properties['ear.maxsize'];
          if (ear?.length() &gt; maxsize?.toInteger()) {
            fail(&quot;EAR Exceeds maximum size allowed.&quot;);
          }
        <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;/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></pre></td></tr></table></div>

<p>This beginning part essentially defines the groovy plugin, and states run the code during the maven&#8217;s &#8220;verify&#8221; phase, so we know that the EAR is already created:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td 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;groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo.groovy<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>groovy-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;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-beta-4-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;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>verify<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>execute<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 style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The groovy code is really straight forward.  First we get a reference to the file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>13
14
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> ear <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$pom.basedir/target/${project.artifactId}-${project.version}.${project.packaging}&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
log.<span style="color: #006600;">info</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;${ear?.length()}&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>We&#8217;re using variables defined directly in the POM, so we know the name of the file.  We also print the length of the file out, for sanity&#8217;s sake.</p>
<p>Next we get the max size value:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> maxsize <span style="color: #66cc66;">=</span> project.<span style="color: #006600;">properties</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'ear.maxsize'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>This is defined later in the pom.xml file, under properties:</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;ear.maxsize<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>60000000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ear.maxsize<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>As you can see, it is set to near 60MBs.</p>
<p>Finally, and obviously, we check the two values against each other, and fail the build if the EAR is bigger than the size allowed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>16
17
18
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ear<span style="color: #66cc66;">?</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> maxsize<span style="color: #66cc66;">?</span>.<span style="color: #006600;">toInteger</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  fail<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;EAR Exceeds maximum size allowed.&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The <code>fail()</code> call in groovy allows you to fail the build with a message attached to it.</p>
<p>So now, if anything fishy happens with the EAR, we&#8217;ll be able to know as soon as our CI environment attempts to build it.  This is a really simple example, but you could see how integrating groovy into maven could allow for some very powerful things to be done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
