<?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>Jesse Peterson &#187; maven</title>
	<atom:link href="http://www.jpeterson.com/tag/maven/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jpeterson.com</link>
	<description>Personal ramblings of a computer geek in Iowa</description>
	<lastBuildDate>Thu, 26 Jan 2012 04:16:38 +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>Using a Maven profile to run a test program</title>
		<link>http://www.jpeterson.com/2009/08/25/using-a-maven-profile-to-run-a-test-program/</link>
		<comments>http://www.jpeterson.com/2009/08/25/using-a-maven-profile-to-run-a-test-program/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 03:19:19 +0000</pubDate>
		<dc:creator>cubeinhabitant</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.jpeterson.com/?p=184</guid>
		<description><![CDATA[This is a new (to me) trick for my programming toolbox. I discovered (copied) it from the Apache CXF project. (I don&#8217;t know if they originated it or not.) Basically, you can use a Maven profile configuration in your pom.xml to easily run a test program in your project that has a public static void [...]]]></description>
			<content:encoded><![CDATA[<p>This is a new (to me) trick for my programming toolbox. I discovered (copied) it from the <a href="http://cxf.apache.org/">Apache CXF</a> project. (I don&#8217;t know if they originated it or not.) Basically, you can use a <a href="http://maven.apache.org/">Maven</a> profile configuration in your pom.xml to easily run a test program in your project that has a <code>public static void main(String[] args)</code> method. I discovered this technique reading the <a href="http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/README.txt?view=co">README.txt</a> of the Apache CXF sample &#8220;<code>java_first_jaxws</code>&#8220;. Here is what the Maven command looks like:</p>
<p><code>mvn -Pserver</code></p>
<p>Here is what the profile configuration in the pom.xml looks like:</p>
<pre>...
&lt;profiles&gt;
  &lt;profile&gt;
    &lt;id&gt;server&lt;/id&gt;
    &lt;build&gt;
      &lt;defaultGoal&gt;test&lt;/defaultGoal&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;phase&gt;test&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;java&lt;/goal&gt;
              &lt;/goals&gt;
              &lt;configuration&gt;
                &lt;mainClass&gt;demo.hw.server.Server&lt;/mainClass&gt;
              &lt;/configuration&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/profile&gt;
...
&lt;/profiles&gt;
...</pre>
<p>When the &#8220;<code>mvn -Pserver</code>&#8221; command is executed, the <code>exec-maven-plugin</code> will run the <code>demo.hw.server.Server</code> class. The <code>id</code> identifies the profile id used in the mvn command after the &#8220;<code>-p</code>&#8220;. The <code>mainClass</code> element defines the class with the main method to execute. The <a href="http://mojo.codehaus.org/exec-maven-plugin/"><code>exec-maven-plugin</code></a> does all of the hard work. One of the benefits of this technique is the standard Maven classpath for the project defined in the pom to build and unit test your software is used to run the <code>mainClass</code>. This comes in quite handy if your program uses many jar files. I used to use a Windows batch file (copied from the <a href="http://tomcat.apache.org/">Tomcat</a> startup script <a href="http://svn.apache.org/repos/asf/tomcat/trunk/bin/catalina.bat"><code>catalina.bat</code></a>) to run little test programs. This Maven profile technique is much easier to use for me, since I use Maven for most all of my Java development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpeterson.com/2009/08/25/using-a-maven-profile-to-run-a-test-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

