<?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>James Ward</title>
	<atom:link href="http://www.jamesward.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamesward.com</link>
	<description>Heroku &#124; Java &#124; Scala &#124; Cloud &#124; Open Source &#124; Linux</description>
	<lastBuildDate>Mon, 14 May 2012 21:19:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Graphs in the Cloud: Spring + Neo4j on Heroku</title>
		<link>http://www.jamesward.com/2012/05/14/graphs-in-the-cloud-spring-neo4j-on-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=graphs-in-the-cloud-spring-neo4j-on-heroku</link>
		<comments>http://www.jamesward.com/2012/05/14/graphs-in-the-cloud-spring-neo4j-on-heroku#comments</comments>
		<pubDate>Mon, 14 May 2012 21:19:50 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Neo4j]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3318</guid>
		<description><![CDATA[Last week I hosted a webinar about running Java apps on Heroku that use the Spring Framework and the Neo4j graph database. Here is the recording of that webinar: In the webinar I began by deploying a copy of the Spring MVC + Hibernate template app from heroku.com/java on Heroku. Then I made a few [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I hosted a webinar about running Java apps on Heroku that use the Spring Framework and the <a href="http://neo4j.org/">Neo4j graph database</a>.  Here is the recording of that webinar:</p>
<p><iframe id="video-player" title="Neo4j Videography Video Player" width="640" height="360" src="http://video.neo4j.org/player/DNgFF/native/" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></p>
<p>In the webinar I began by deploying a copy of the Spring MVC + Hibernate template app from <a href="http://heroku.com/java">heroku.com/java</a> on Heroku.  Then I made a few modifications to the app to switch the persistence from Hibernate / JPA to Neo4j.  You can get the <a href="https://github.com/jamesward/hello-java-spring-neo4j">full source code on GitHub</a>.</p>
<p>Here is a quick recap of what I did to switch the template app to use Neo4j:</p>
<ol>
<li>Added the <a href="https://addons.heroku.com/neo4j">Neo4j Heroku Add-on</a>:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku addons:add neo4j</pre></div></div>

</li>
<li>Added the Spring Data Neo4j dependencies (optionally you can remove the unused JPA dependencies) to the &#8220;<a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/pom.xml">pom.xml</a>&#8221; Maven build descriptor:

<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;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.springframework.data<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>spring-data-neo4j-rest<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>2.0.1.RELEASE<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.hibernate<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>hibernate-validator<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>4.2.0.Final<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></pre></div></div>

</li>
<li>Modified the &#8220;<a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/src/main/java/com/example/service/PersonService.java">src/main/java/com/example/service/PersonService.java</a>&#8221; interface to use the Neo4j GraphRepository:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.service</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.model.Person</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.data.neo4j.repository.GraphRepository</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> PersonService <span style="color: #000000; font-weight: bold;">extends</span> GraphRepository<span style="color: #339933;">&lt;</span>Person<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>Removed the unneeded &#8220;src/main/java/com/example/service/PersonServiceImpl.java&#8221; DAO.</li>
<li>Modified the &#8220;<a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/src/main/java/com/example/model/Person.java">src/main/java/com/example/model/Person.java</a>&#8221; POJO to be a <strong>@NodeEntity</strong> (instead of JPA Entity) and switched the &#8220;id&#8221; primary key property to be a <strong>Long</strong> annotated as a <strong>@GraphId</strong>:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.data.neo4j.annotation.GraphId</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.data.neo4j.annotation.NodeEntity</span><span style="color: #339933;">;</span>
&nbsp;
@NodeEntity
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #009900;">&#123;</span>
&nbsp;
    @GraphId
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// the rest is omitted</span></pre></div></div>

</li>
<li>Modified the &#8220;<a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/src/main/java/com/example/controller/PersonController.java">src/main/java/com/example/controller/PersonController.java</a>&#8221; Spring MVC controller to use the new &#8220;PersonService&#8221;, take a <strong>Long</strong> parameter in the &#8220;deletePerson&#8221; method, and make the &#8220;deletePerson&#8221; and &#8220;addPerson&#8221; methods transactional:

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.annotation.Autowired</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.stereotype.Controller</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.transaction.annotation.Transactional</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.ModelAttribute</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.PathVariable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestMapping</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestMethod</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.model.Person</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.service.PersonService</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
@Controller
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonController <span style="color: #009900;">&#123;</span>
&nbsp;
    @Autowired
    <span style="color: #000000; font-weight: bold;">private</span> PersonService personService<span style="color: #339933;">;</span>
&nbsp;
    @RequestMapping<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> listPeople<span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span>String, Object<span style="color: #339933;">&gt;</span> map<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;person&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;peopleList&quot;</span>, personService.<span style="color: #006633;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;people&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @RequestMapping<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/add&quot;</span>, method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">POST</span><span style="color: #009900;">&#41;</span>
    @Transactional
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> addPerson<span style="color: #009900;">&#40;</span>@ModelAttribute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;person&quot;</span><span style="color: #009900;">&#41;</span> Person person<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        personService.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;redirect:/people/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @RequestMapping<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/delete/{personId}&quot;</span><span style="color: #009900;">&#41;</span>
    @Transactional
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> deletePerson<span style="color: #009900;">&#40;</span>@PathVariable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;personId&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #003399;">Long</span> personId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        personService.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span>personId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;redirect:/people/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li>Then I modified the &#8220;<a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/src/main/resources/applicationContext.xml">src/main/resources/applicationContext.xml</a>&#8221; Spring config file to use a file for local Neo4j storage in the &#8220;default&#8221; profile and then in the &#8220;prod&#8221; profile the &#8220;NEO4J_REST_URL&#8221;, &#8220;NEO4J_LOGIN&#8221;, and &#8220;NEO4J_PASSWORD&#8221; environment variables are used to connect to the Neo4j Heroku add-on service:

<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;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&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;">xmlns:context</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/context&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:tx</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/tx&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:mvc</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/mvc&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:neo4j</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/data/neo4j&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd</span>
<span style="color: #009900;">                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd</span>
<span style="color: #009900;">                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd</span>
<span style="color: #009900;">                           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd</span>
<span style="color: #009900;">                           http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:annotation-config</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:spring-configured</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;com.example&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;neo4j:repositories</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;com.example.service&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mvc:annotation-driven</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jspViewResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;viewClass&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.JstlView&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;prefix&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/jsp/&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;suffix&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:annotation-driven</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">profile</span>=<span style="color: #ff0000;">&quot;default&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;neo4j:config</span> <span style="color: #000066;">storeDirectory</span>=<span style="color: #ff0000;">&quot;target/neo4j-db&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">profile</span>=<span style="color: #ff0000;">&quot;prod&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.data.neo4j.rest.SpringRestGraphDatabase&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;graphDatabaseService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{systemEnvironment['NEO4J_REST_URL']}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{systemEnvironment['NEO4J_LOGIN']}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{systemEnvironment['NEO4J_PASSWORD']}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;neo4j:config</span> <span style="color: #000066;">graphDatabaseService</span>=<span style="color: #ff0000;">&quot;graphDatabaseService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>After testing my changes locally (which actually didn&#8217;t work in my webinar due to a problem with Eclipse) I committed my changes to the git repo and pushed them to Heroku:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master</pre></div></div>

</li>
</ol>
<p>If you want to just skip to a working example on the cloud, simply follow the instructions in the <a href="https://github.com/jamesward/hello-java-spring-neo4j/blob/master/README.md">project README</a>.</p>
<p>Hopefully that helps you get started with Neo4j and Java applications on the cloud!</p>
<p>BTW: If you watched the webinar, you probably noticed that my Maven and Eclipse were misbehaving.  Turns out that M2E didn&#8217;t read my Maven config and all I had to do was right-click on the project, select Maven, and then Update Project Configuration.  That got everything back in sync.  My excuse for not being able to figure that out during the demo&#8230;  I usually use IntelliJ IDEA.  :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/05/14/graphs-in-the-cloud-spring-neo4j-on-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play 2 Java Tutorial</title>
		<link>http://www.jamesward.com/2012/05/08/play-2-java-tutorial?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=play-2-java-tutorial</link>
		<comments>http://www.jamesward.com/2012/05/08/play-2-java-tutorial#comments</comments>
		<pubDate>Tue, 08 May 2012 13:57:02 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3310</guid>
		<description><![CDATA[I&#8217;ve created a Play 2 Tutorial and posted it on GitHub! The tutorial covers how to: Create a Play App Set up an IDE Start the Play Server Routes Test a Route Update a Controller Test a Controller Update a View Test a View Deploy your app on the Cloud with Heroku Create a Model [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a Play 2 Tutorial and <a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md">posted it on GitHub</a>!  The tutorial covers how to:</p>
<ul>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#create-a-play-app">Create a Play App</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#set-up-an-ide">Set up an IDE</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#start-the-play-server">Start the Play Server</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#routes">Routes</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#test-a-route">Test a Route</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#update-a-controller">Update a Controller</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#test-a-controller">Test a Controller</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#update-a-view">Update a View</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#test-a-view">Test a View</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#deploy-your-app-on-the-cloud-with-heroku">Deploy your app on the Cloud with Heroku</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#create-a-model">Create a Model</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#create-ui-for-adding-tasks">Create UI for Adding Tasks</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#get-tasks-as-json">Get Tasks as JSON</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#display-the-tasks-via-coffeescript-and-jquery">Display the Tasks via CoffeeScript and jQuery</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#make-the-app-pretty-with-twitter-bootstrap">Make the App Pretty with Twitter Bootstrap</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#add-form-validation">Add Form Validation</a></li>
<li><a href="https://github.com/jamesward/play2torial/blob/master/JAVA.md#update-the-app-on-heroku">Update the App on Heroku</a></li>
</ul>
<p>Each section has a <a href="https://github.com/jamesward/play2torial/branches">corresponding branch in git</a> so you can diff against my version to see if you&#8217;ve done everything correctly.  Right now this is just for Play 2 with Java and Ebean but I&#8217;m working on doing this for Play 2 with Scala as well.</p>
<p>You can see a live demo of the final app at:<br />
<a href="http://play2torial.herokuapp.com/">play2torial.herokuapp.com</a></p>
<p>It&#8217;s a pretty simple app but it should get you started building Play 2 apps and deploying them on the cloud with Heroku.  If you want to take the shortcut to the end and get your own copy of the app running on Heroku then just do the following:</p>
<ol>
<li>Install <a href="http://git-scm.com/">git</a> and the <a href="http://toolbelt.heroku.com">Heroku Toolbelt</a>.</li>
<li><a href="http://heroku.com/signup">Signup for an account on Heroku</a>. (Don&#8217;t worry, this stuff is free.)</li>
<li>Clone the play2torial git repo:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jamesward<span style="color: #000000; font-weight: bold;">/</span>play2torial.git</pre></div></div>

</li>
<li>Login to Heroku:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku <span style="color: #c20cb9; font-weight: bold;">login</span></pre></div></div>

</li>
<li>Create a new app on Heroku (from within the play2torial directory):

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create <span style="color: #660033;">--stack</span> cedar</pre></div></div>

</li>
<li>Upload the app to Heroku (from within the play2torial directory):

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push heroku java-heroku_update:master</pre></div></div>

</li>
<li>Check out your app on the cloud:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku open</pre></div></div>

</li>
<li>If you want to run the app locally, <a href="http://www.playframework.org/documentation/2.0.1/Installing">install Play 2</a> and then run:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> checkout java-heroku_update
play ~run</pre></div></div>

</li>
</ol>
<p>I hope this helps you learn Play 2!  Let me know if you have any questions or comments.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/05/08/play-2-java-tutorial/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Heroku, Java, Play and Neo4j Presos: Denver JUG, Atlanta JUG, London Flash UG &amp; Webinar</title>
		<link>http://www.jamesward.com/2012/05/07/heroku-java-play-neo4j-presos-denver-jug-atlanta-jug-london-flash-ug-webinar?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-java-play-and-neo4j-presos-denver-jug-atlanta-jug-london-flash-ug-webinar</link>
		<comments>http://www.jamesward.com/2012/05/07/heroku-java-play-neo4j-presos-denver-jug-atlanta-jug-london-flash-ug-webinar#comments</comments>
		<pubDate>Mon, 07 May 2012 21:16:54 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Neo4j]]></category>
		<category><![CDATA[Play Framework]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3300</guid>
		<description><![CDATA[Over the next couple weeks I&#8217;ll be doing two Java User Group presentations, a Flash Platform User Group presentation and one Webinar. Hope to see you at one of these events: Wednesday May 9 &#8211; Denver Java User Group: Running Java, Play! and Scala Apps in the Cloud Thursday May 10 &#8211; Webinar hosted by [...]]]></description>
			<content:encoded><![CDATA[<p>Over the next couple weeks I&#8217;ll be doing two Java User Group presentations, a Flash Platform User Group presentation and one Webinar.  Hope to see you at one of these events:</p>
<ul>
<li>Wednesday May 9 &#8211; Denver Java User Group:<br />
<a href="http://www.denverjug.org/?p=585">Running Java, Play! and Scala Apps in the Cloud</a></li>
<li style="margin-top: 20px;">Thursday May 10 &#8211; Webinar hosted by Neo4j:<br />
<a href="http://info.neotechnology.com/0510-cloud.html">Graphs in the Cloud: Neo4j and Heroku</a></li>
<li style="margin-top: 20px;">Tuesday May 15 &#8211; Atlanta Java User Group:<br />
<a href="http://www.ajug.org/site/5964245/running-java-play-and-scala-apps-on-the-cloud">Running Java, Play! and Scala Apps on the Cloud</a></li>
<li style="margin-top: 20px;">Thursday May 24 &#8211; London Flash Platform User Group:<br />
<a href="http://www.lfpug.com/24th-may-2012-24052012/">HTML5 Apps in Java &#038; Scala with the Play Framework</a><br />
<a href="http://www.lfpug.com/24th-may-2012-24052012/">Deploying Apps on the Cloud with Heroku</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/05/07/heroku-java-play-neo4j-presos-denver-jug-atlanta-jug-london-flash-ug-webinar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Heroku Presos: Denver Open Source UG and Future Insights Live</title>
		<link>http://www.jamesward.com/2012/04/30/heroku-presos-denver-open-source-ug-and-future-insights-live?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-presos-denver-open-source-ug-and-future-insights-live</link>
		<comments>http://www.jamesward.com/2012/04/30/heroku-presos-denver-open-source-ug-and-future-insights-live#comments</comments>
		<pubDate>Mon, 30 Apr 2012 23:48:14 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3286</guid>
		<description><![CDATA[This week I&#8217;ll be doing two presentation about Heroku: Tuesday May 1 &#8211; 5:30 PM at the Denver Open Source Users Group:Heroku Cloud Computing Platform Thursday May 3 &#8211; 12:25pm at Future Insights Live (Las Vegas):Client/Server Apps with HTML5 and Java Hope to see you there!]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ll be doing two presentation about Heroku:</p>
<ul>
<li>Tuesday May 1 &#8211; 5:30 PM at the Denver Open Source Users Group:<br/><a href="http://meetup.denveropensource.org/events/27121221/">Heroku Cloud Computing Platform</a></li>
<li style="margin-top: 20px">Thursday May 3 &#8211; 12:25pm at Future Insights Live (Las Vegas):<br/><a href="http://futureinsightslive.com/schedule">Client/Server Apps with HTML5 and Java</a></li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/04/30/heroku-presos-denver-open-source-ug-and-future-insights-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebJars in Spring MVC</title>
		<link>http://www.jamesward.com/2012/04/30/webjars-in-spring-mvc?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=webjars-in-spring-mvc</link>
		<comments>http://www.jamesward.com/2012/04/30/webjars-in-spring-mvc#comments</comments>
		<pubDate>Mon, 30 Apr 2012 15:54:20 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[WebJars]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3278</guid>
		<description><![CDATA[Last week I announced the WebJars project that allows you to specify your web libraries (JavaScript, CSS, etc) as dependencies in your Java web applications. With some help from Jeremy Grelle I was able to get a simple WebJars Spring MVC example working. First you will need to add the WebJars repository to your build. [...]]]></description>
			<content:encoded><![CDATA[<p>Last week <a href="http://www.jamesward.com/2012/04/25/introducing-webjars-web-libraries-as-managed-dependencies">I announced the WebJars project</a> that allows you to specify your web libraries (JavaScript, CSS, etc) as dependencies in your Java web applications.  With some help from <a href="https://twitter.com/#!/jeremyg484">Jeremy Grelle</a> I was able to get a <a href="https://github.com/jamesward/spring_webjars_demo">simple WebJars Spring MVC example</a> working.</p>
<p>First you will need to add the WebJars repository to your build.  For Maven, just add the following to your &#8220;pom.xml&#8221; build file:</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;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<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>webjars<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;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://webjars.github.com/m2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then add a WebJar dependency, like Twitter Bootstrap:</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;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>com.github.twitter<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>bootstrap<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>2.0.2<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></pre></div></div>

<p>Then you need to add a resource handler to Spring MVC that maps requests from a given path to files in the classpath.  The WebJars are all inside of a &#8220;public&#8221; directory.  If you are using Java configuration in Spring then you would do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Configuration
@EnableWebMvc
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WebConfig <span style="color: #000000; font-weight: bold;">extends</span> WebMvcConfigurerAdapter <span style="color: #009900;">&#123;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addResourceHandlers<span style="color: #009900;">&#40;</span>ResourceHandlerRegistry registry<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    registry.<span style="color: #006633;">addResourceHandler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/public/**&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addResourceLocations</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;classpath:/public/&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>Or if you are using XML config then add the following to your Spring config:</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;mvc:resources</span> <span style="color: #000066;">mapping</span>=<span style="color: #ff0000;">&quot;/public/**&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;classpath:/public/&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Then you can reference a WebJar&#8217;s assets with something like:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel='stylesheet' media='screen' href='/public/stylesheets/bootstrap.min.css'&gt;</pre></div></div>

<p>How easy is that?  Now you are managing your web libraries as versioned dependencies and you even get transitive dependencies!  Check out the full source code for this example on GitHub: <a href="https://github.com/jamesward/spring_webjars_demo">https://github.com/jamesward/spring_webjars_demo</a></p>
<p>Right now there are only a <a href="http://webjars.github.com">couple of WebJars</a> so if you need something else then simply <a href="https://github.com/webjars/webjars.github.com/issues/new">request a new one</a> via a new issue on GitHub.</p>
<p>Please let me know what you think about this.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/04/30/webjars-in-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Introducing WebJars &#8211; Web Libraries as Managed Dependencies</title>
		<link>http://www.jamesward.com/2012/04/25/introducing-webjars-web-libraries-as-managed-dependencies?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introducing-webjars-web-libraries-as-managed-dependencies</link>
		<comments>http://www.jamesward.com/2012/04/25/introducing-webjars-web-libraries-as-managed-dependencies#comments</comments>
		<pubDate>Wed, 25 Apr 2012 16:46:25 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Dropwizard]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[WebJars]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3257</guid>
		<description><![CDATA[Update: I&#8217;ve created a Spring MVC WebJars example. Our web apps are using more and more web libraries like jQuery, Backbone.js and Twitter Bootstrap. The traditional way to use those libraries is to locate &#038; download the JavaScript and CSS source then just copy it into a project. To me this resembles how we used [...]]]></description>
			<content:encoded><![CDATA[<p><font style="color: #ff0000; weight: bold;">Update: I&#8217;ve created a <a href="http://www.jamesward.com/2012/04/30/webjars-in-spring-mvc">Spring MVC WebJars example</a>.</font></p>
<p>Our web apps are using more and more web libraries like jQuery, Backbone.js and Twitter Bootstrap.  The traditional way to use those libraries is to locate &#038; download the JavaScript and CSS source then just copy it into a project.  To me this resembles how we used to just copy JAR files into a project&#8217;s WEB-INF/lib dir.  But why not do with web libraries like we now do with Java libraries and specify them as managed dependencies?  This allows us to declaratively set the version, use a consistent version across an application, and easily deal with transitive dependencies.  Then we just need web frameworks that can serve static assets from JAR files and we are good to go!  Luckily <a href="http://playframework.org">Play 2</a> and <a href="http://dropwizard.codahale.com/">Dropwizard</a> both have out-of-the-box support for this.  So I decided to give it a try&#8230;</p>
<p>I packaged up some JavaScript and CSS web libraries into JARs, put them into a Maven repo and it worked!  And thus the <a href="http://github.com/webjars">WebJars</a> project was born!</p>
<p>Lets look at an example for how to use the <a href="http://twitter.github.com/bootstrap">Twitter Bootstrap</a> WebJar in a Play 2 app.  First we need to add the WebJars Maven repo to the Play 2 dependency resolvers and specify Bootstrap as a dependency.  For Play 2 this is done in the &#8220;project/Build.scala&#8221; file.  Here is one for my <a href="https://github.com/jamesward/play2_webjars_demo">Play 2 WebJars Demo</a> project:</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>
<span style="color: #0000ff; font-weight: bold;">import</span> Keys.<span style="color: #000080;">_</span>
<span style="color: #0000ff; font-weight: bold;">import</span> PlayProject.<span style="color: #000080;">_</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> ApplicationBuild <span style="color: #0000ff; font-weight: bold;">extends</span> Build <span style="color: #F78811;">&#123;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">val</span> appName         <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;play2_webjars_demo&quot;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> appVersion      <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;1.0-SNAPSHOT&quot;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">val</span> appDependencies <span style="color: #000080;">=</span> Seq<span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;com.github.twitter&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;bootstrap&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;2.0.2&quot;</span>
    <span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">val</span> main <span style="color: #000080;">=</span> PlayProject<span style="color: #F78811;">&#40;</span>appName, appVersion, appDependencies, mainLang <span style="color: #000080;">=</span> JAVA<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">settings</span><span style="color: #F78811;">&#40;</span>
      resolvers +<span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;webjars&quot;</span> at <span style="color: #6666FF;">&quot;http://webjars.github.com/m2&quot;</span>
    <span style="color: #F78811;">&#41;</span>
&nbsp;
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>Now to use Bootstrap in a Scala template, we can just do:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel='stylesheet' media='screen' href='@routes.Assets.at(&quot;stylesheets/bootstrap.min.css&quot;)'&gt;</pre></div></div>

<p>The &#8220;@routes.Assets.at&#8221; thing just gets a reverse route for the URL that will serve the &#8220;bootstrap.min.css&#8221; file from the Bootstrap WebJar.  Note: It&#8217;s not necessary in Play 2 to use the reverse routing but it is a type safe way to get a URL.  Based on the default routes in Play 2 the route to that file will be &#8220;/assets/javascripts/bootstrap.min.js&#8221; which we could have used instead.</p>
<p>Now here is the super cool part&#8230;  The Bootstrap WebJar depends on jQuery so now I can also just use jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type='text/javascript' src='@routes.Assets.at(&quot;javascripts/jquery.min.js&quot;)'&gt;&lt;/script&gt;</pre></div></div>

<p>That is super simple and now I&#8217;m managing my web libraries as dependencies!</p>
<p>Note: Play 2 actually puts a copy of jQuery in the default project template but hopefully for Play 2.1 they will pull it out and instead use the jQuery WebJar.  In my demo project I&#8217;ve removed that copy of jQuery because it&#8217;s no longer needed.</p>
<p>If you want to use WebJars with Dropwizard then first setup the Maven &#8220;pom.xml&#8221; file with the WebJars repo and add the dependency:</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;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<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>webjars<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;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://webjars.github.com/m2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <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>com.github.twitter<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>bootstrap<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>2.0.2<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>Then add an &#8220;AssetBundle&#8221; that will serve static assets in the &#8220;public&#8221; directory on the &#8220;/public&#8221; URL path:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    addBundle<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AssetsBundle<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/public/&quot;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0000ff;">&quot;/public&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you can load the static assets in a web page:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">    &lt;link rel='stylesheet' media='screen' href='/public/stylesheets/bootstrap.min.css'&gt;
    &lt;script type='text/javascript' src='/public/javascripts/jquery.min.js'&gt;&lt;/script&gt;</pre></div></div>

<p>Get the <a href="https://github.com/jamesward/dropwizard_webjars_demo">full source code for the Dropwizard WebJars demo on GitHub</a>.</p>
<p>I&#8217;m sure there are other Java web frameworks that support WebJars, so if you know of one, let me know and I&#8217;ll try to create more demo projects.</p>
<p>Right now there are just a <a href="http://webjars.github.com">couple WebJars in the repository</a> but if you&#8217;d like to see others then <a href="https://github.com/webjars/webjars.github.com/issues/new">create a new issue on GitHub</a> and I&#8217;ll build a new WebJar.</p>
<p>Let me know what you think about WebJars.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/04/25/introducing-webjars-web-libraries-as-managed-dependencies/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Heroku for Java, Scala &amp; Play at the Houston JUG and NFJS Virginia</title>
		<link>http://www.jamesward.com/2012/04/24/heroku-for-java-scala-play-at-the-houston-jug-and-nfjs-virginia?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=heroku-for-java-scala-play-at-the-houston-jug-and-nfjs-virginia</link>
		<comments>http://www.jamesward.com/2012/04/24/heroku-for-java-scala-play-at-the-houston-jug-and-nfjs-virginia#comments</comments>
		<pubDate>Tue, 24 Apr 2012 16:25:30 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3249</guid>
		<description><![CDATA[This week I will be presenting about Running Java, Scala, and Play apps on Heroku at the Houston JUG and at No Fluff Just Stuff in Reston, VA: Houston JUG &#8211; Wednesday April 25 at 6:30pmRunning Java and Play! Apps on the Cloud NFJS &#8211; Reston, VA &#8211; Saturday April 28 at 3:15pmRunning Java and [...]]]></description>
			<content:encoded><![CDATA[<p>This week I will be presenting about Running Java, Scala, and Play apps on Heroku at the Houston JUG and at No Fluff Just Stuff in Reston, VA:</p>
<ul>
<li>Houston JUG &#8211; Wednesday April 25 at 6:30pm<br/><a href="http://hjug.org">Running Java and Play! Apps on the Cloud</a></li>
<li style="margin-top: 30px;">NFJS &#8211; Reston, VA &#8211; Saturday April 28 at 3:15pm<br/><a href="http://www.nofluffjuststuff.com/conference/reston/2012/04/schedule">Running Java and Scala Apps on Heroku</a></li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/04/24/heroku-for-java-scala-play-at-the-houston-jug-and-nfjs-virginia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play Framework 2 &amp; HTML5 on Heroku at Philly ETE and Devoxx Paris</title>
		<link>http://www.jamesward.com/2012/04/04/play-framework-2-html5-on-heroku-at-philly-ete-and-devoxx-paris?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=play-framework-2-html5-on-heroku-at-philly-ete-and-devoxx-paris</link>
		<comments>http://www.jamesward.com/2012/04/04/play-framework-2-html5-on-heroku-at-philly-ete-and-devoxx-paris#comments</comments>
		<pubDate>Wed, 04 Apr 2012 20:49:00 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3233</guid>
		<description><![CDATA[Over the next few weeks I&#8217;ll be doing a few presentations about Java, Scala, Play Framework 2, HTML5, and Heroku: Wednesday April 11 @ 11:30am &#8211; Emerging Technologies for the Enterprise (Philedephia, PA) &#8211; HTML5 Apps in Java &#038; Scala with the Play Framework Wednesday April 18 @ 13:30 &#8211; Devoxx (Paris, France) &#8211; Developing, [...]]]></description>
			<content:encoded><![CDATA[<p>Over the next few weeks I&#8217;ll be doing a few presentations about Java, Scala, Play Framework 2, HTML5, and Heroku:</p>
<ul>
<li>Wednesday April 11 @ 11:30am &#8211; Emerging Technologies for the Enterprise (Philedephia, PA) &#8211; <a href="http://phillyemergingtech.com/2012/sessions/html5-apps-in-java-scala-with-the-play-framework">HTML5 Apps in Java &#038; Scala with the Play Framework</a></li>
</ul>
<ul>
<li>Wednesday April 18 @ 13:30 &#8211; Devoxx (Paris, France) &#8211; <a href="http://www.devoxx.com/display/FR12/Developing%2C+Deploying+and+Scaling+in+the+Cloud+with+Play">Developing, Deploying and Scaling in the Cloud with Play</a></li>
</ul>
<ul>
<li>Thursday April 19 @ 14:30 &#8211; Devoxx (Paris, France) &#8211; <a href="http://www.devoxx.com/display/FR12/Client+Server+Apps+with+HTML5+and+Java">Client/Server Apps with HTML5 and Java</a></li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/04/04/play-framework-2-html5-on-heroku-at-philly-ete-and-devoxx-paris/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Java on Heroku at NH JUG and DevNexus 2012</title>
		<link>http://www.jamesward.com/2012/03/19/java-on-heroku-at-nh-jug-and-devnexus-2012?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-on-heroku-at-nh-jug-and-devnexus-2012</link>
		<comments>http://www.jamesward.com/2012/03/19/java-on-heroku-at-nh-jug-and-devnexus-2012#comments</comments>
		<pubDate>Mon, 19 Mar 2012 14:27:06 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Play Framework]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3226</guid>
		<description><![CDATA[This week I&#8217;ll will be doing a few presentations about running Java and Play apps on Heroku: Portsmouth, NH on Tuesday March 20 @ 6:30pm &#8211; Running Java, Play! and Scala Apps on the Cloud DevNexus in Atlanta, GA on Wednesday March 21 @ 2:30pm &#8211; Introduction to Heroku DevNexus in Atlanta, GA on Thursday [...]]]></description>
			<content:encoded><![CDATA[<p>This week I&#8217;ll will be doing a few presentations about running Java and Play apps on Heroku:</p>
<ul>
<li><a href="http://nhjug.org/">Portsmouth, NH on Tuesday March 20 @ 6:30pm</a> &#8211; Running Java, Play! and Scala Apps on the Cloud</li>
<li><a href="http://www.devnexus.com/s/schedule">DevNexus in Atlanta, GA on Wednesday March 21 @ 2:30pm</a> &#8211; Introduction to Heroku</li>
<li><a href="http://www.devnexus.com/s/schedule">DevNexus in Atlanta, GA on Thursday March 22 @ 2:30pm</a> &#8211; Intro to Play Framework</li>
</ul>
<p>Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/03/19/java-on-heroku-at-nh-jug-and-devnexus-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screencast: Java Template Apps on Heroku</title>
		<link>http://www.jamesward.com/2012/03/15/screencast-java-template-apps-on-heroku?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=screencast-java-template-apps-on-heroku</link>
		<comments>http://www.jamesward.com/2012/03/15/screencast-java-template-apps-on-heroku#comments</comments>
		<pubDate>Thu, 15 Mar 2012 18:55:57 +0000</pubDate>
		<dc:creator>James Ward</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.jamesward.com/?p=3200</guid>
		<description><![CDATA[Today Heroku launched a new way to get started deploying Java apps on the cloud. There are four different template apps you can start with including a Spring + Hibernate + Tomcat app, a Containerless Jetty app, a Play! app, and a JAX-RS app. Pick a template and with a few clicks a copy of [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://blog.heroku.com/archives/2012/3/15/java_template_apps_on_heroku/">Heroku launched a new way</a> to get started deploying Java apps on the cloud.  There are four different template apps you can start with including a Spring + Hibernate + Tomcat app, a Containerless Jetty app, a Play! app, and a JAX-RS app.  Pick a template and with a few clicks a copy of the template will be deployed on Heroku &#8211; just for you!  Get started at:<center><br />
<h1 style="padding-top: 0px;"><a href="http://heroku.com/java">heroku.com/java</a></h1>
<p></center></p>
<p>Here is a screencast that walks through the steps to deploy a new Java template app on Heroku, then setup SSH authentication (for pulling and pushing code with git), pull the code into Eclipse, make a change, and push the changes back to Heroku.  Check it out and let me know what you think.<br />
<iframe width="640" height="360" src="http://www.youtube.com/embed/mkmWwA0EoGg?rel=0" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamesward.com/2012/03/15/screencast-java-template-apps-on-heroku/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

