<?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>Jeff Devine &#187; Jersey</title> <atom:link href="http://jeffdevine.com/tag/jersey/feed/" rel="self" type="application/rss+xml" /><link>http://jeffdevine.com</link> <description>I only tell you what to do because I love you</description> <lastBuildDate>Tue, 15 May 2012 21:22:39 +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>Simple-Build-Tool or: How I RTFM and stopped hating on Maven</title><link>http://jeffdevine.com/2009/09/27/simple-build-tool-or-how-i-rtfm-and-stopped-hating-on-maven/</link> <comments>http://jeffdevine.com/2009/09/27/simple-build-tool-or-how-i-rtfm-and-stopped-hating-on-maven/#comments</comments> <pubDate>Sun, 27 Sep 2009 07:51:44 +0000</pubDate> <dc:creator>Jeff</dc:creator> <category><![CDATA[tech]]></category> <category><![CDATA[10.6]]></category> <category><![CDATA[Jersey]]></category> <category><![CDATA[Scala]]></category> <category><![CDATA[Simple-Build-Tool]]></category> <category><![CDATA[WHY?]]></category><guid isPermaLink="false">http://jeffdevine.com/?p=162</guid> <description><![CDATA[<p>Tonight I was supposed to see <a href="http://www.myspace.com/whyanticon" target="_blank">WHY?</a> at <a href="http://lepoissonrouge.com" target="_blank">Le Poisson Rouge</a> but for some completely unknown reason, I felt I would be better served staying in and working....</p>]]></description> <content:encoded><![CDATA[<p>Tonight I was supposed to see <a href="http://www.myspace.com/whyanticon" target="_blank">WHY?</a> at <a href="http://lepoissonrouge.com" target="_blank">Le Poisson Rouge</a> but for some completely unknown reason, I felt I would be better served staying in and working.</p><p>I&#8217;m trying to prototype a Scala-based REST API that gets called by a <a href="http://code.google.com/webtoolkit/" target="_blank">GWT</a> front-end. My Scala is extremely weak but Martin Kleppmann&#8217;s <a href="http://www.yes-no-cancel.co.uk/" target="_blank">Yes/No/Cancel</a> had a great <a href="http://www.yes-no-cancel.co.uk/2009/05/13/building-go-test-it-fun-with-scala-and-rest-apis/" target="_blank">write-up</a> accomplishing the aforementioned task using <a href="https://jersey.dev.java.net/" target="_blank">Jersey</a> and Scala. Unfortunately for me, I&#8217;ve <a href="http://lists.apple.com/archives/java-dev/2009/Sep/msg00067.html" target="_blank">mangled</a> my java environment trying to get GWT to run on Snow Leopard and I was having no luck getting Martin&#8217;s Maven POM to work.</p><p>Already regretting my decision to pass on the concert, I wasn&#8217;t going to waste my entire night cursing at Maven. Instead I took this opportunity to use Martin&#8217;s examples but apply them to <a href="http://code.google.com/p/simple-build-tool/" target="_blank">Simple Build Tool</a>. The following is how I RTFM and started learned how to use SBT. I&#8217;d love feedback so please look it over or follow along and let me know if there is a better way to go about this.</p><p>First, start a new project by creating a directory for the project and running <strong>sbt</strong> from within this new directory. When SBT is run with no action specified and it doesn&#8217;t detect a project structure, it prompts to create a new project. I used the following, mostly taking the default values:</p><pre>
     Name: api
     Organization []: com.jeffdevine
     Version [1.0]:
     Scala version [2.7.5]:
     sbt version [0.5.3]:
</pre><p>The initial process downloads any dependencies needed and creates a default project structure:</p><pre>
    lib/
    project/
          boot/
          build.properties
    src/
          main
              resources/
              scala/
          test
              resources/
              scala/
    target/
</pre><p>My initial needs for prototyping the REST API are Jetty and Jersey, so I configured SBT to manage these dependencies by adding the file <em>./project/build/ApiProject.scala</em> (note: <em>build</em> is a new directory):</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> ApiProject<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> DefaultWebProject<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> snapshots <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;Java.net Repository&quot;</span> at <span style="color: #6666FF;">&quot;http://download.java.net/maven/2/&quot;</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.14&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;test-&gt;default&quot;</span>	
   <span style="color: #0000ff; font-weight: bold;">val</span> jersey <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;com.sun.jersey&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;jersey-server&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;1.1.2-ea&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;test-&gt;default&quot;</span> 
   <span style="color: #0000ff; font-weight: bold;">val</span> jsr311 <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;javax.ws.rs&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;jsr311-api&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;1.1-ea&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;compile-&gt;default&quot;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div><p>From the SBT interactive session, execute <strong>reload</strong> to recompile the project definition and <strong>update</strong> to download all the specified dependencies.</p><p>Back to Martin&#8217;s example, I slightly modified his Scala code and saved it in <em>./src/main/scala/Hello.scala</em>:</p><div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">package</span> com.<span style="color: #000000;">jeffdevine</span>.<span style="color: #000000;">api</span>
<span style="color: #0000ff; font-weight: bold;">import</span> javax.<span style="color: #000000;">ws</span>.<span style="color: #000000;">rs</span>.<span style="color: #000080;">_</span>
&nbsp;
<span style="color: #000080;">@</span>Path<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/hello&quot;</span><span style="color: #F78811;">&#41;</span>
<span style="color: #0000ff; font-weight: bold;">class</span> Hello <span style="color: #F78811;">&#123;</span>
  <span style="color: #000080;">@</span>GET <span style="color: #000080;">@</span>Produces<span style="color: #F78811;">&#40;</span>Array<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;text/html&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> doGet <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello? You could be seeing Why? right now...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div><p>The last bit is to tell Jetty what to do by creating a file in <em>./src/main/webapp/WEB-INF/web.xml</em> (note: you&#8217;ll need to create the directory structure <em>webapp/WEB-INF</em>):</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.4&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span></span>
<span style="color: #009900;">  <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://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.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;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Example REST API<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.spi.container.servlet.ServletContainer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.packages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.jeffdevine.api<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Example REST API<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>30<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p>Back in SBT,  execute <strong>jetty-run</strong>, and within a few seconds, jetty is serving the API on http://localhost:8080/hello. Firing off a GET request returns the HTML<pre>     Hello? You could be seeing Why? right now...</pre><p>Executing <strong>jetty-stop</strong> will kill the server, and <strong>jetty-restart</strong> restarts jetty, picking up any code changes.</p><p>While this is a basic example that could use a test case or two, it has given me what I need to start prototyping and I no longer feel like a schmuck for skipping tonight&#8217;s concert&#8230; which would have gone something like this:</p><p><object width="425px" height="360px" ><param name="allowFullScreen" value="true"/><param name="wmode" value="transparent"/><param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m=34274112,t=1,mt=video"/><embed src="http://mediaservices.myspace.com/services/media/embed.aspx/m=34274112,t=1,mt=video" width="425" height="360" allowFullScreen="true" type="application/x-shockwave-flash" wmode="transparent"></embed></object></p> ]]></content:encoded> <wfw:commentRss>http://jeffdevine.com/2009/09/27/simple-build-tool-or-how-i-rtfm-and-stopped-hating-on-maven/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: jeffdevine.com @ 2012-05-19 17:32:23 -->
