<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"
>

<channel>
	<title>acidum.de &#187; Glassfish</title>
	<atom:link href="http://www.acidum.de/tag/glassfish/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.acidum.de</link>
	<description></description>
	<lastBuildDate>Sun, 08 Nov 2009 20:12:26 +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>Deploy a Grails Application into Glassfish</title>
		<link>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/</link>
		<comments>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 15:34:04 +0000</pubDate>
		<dc:creator>Christoph Hartmann</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Code Examples]]></category>
		<category><![CDATA[Glassfish]]></category>

		<guid isPermaLink="false">http://www.acidum.de/?p=220</guid>
		<description><![CDATA[In most cases a Grails application uses a database to store its content. Fortunately Grails is tightly coupled with GORM to ease the use. Since Grails distinguish between different deployment environments, it uses a special configuration for development and production. Therefore you have to think of a database in production environment while you don not [...]]]></description>
			<content:encoded><![CDATA[<p>In most cases a <a title="Grails Site" href="http://www.grails.org/" target="_blank">Grails</a> application uses a database to store its content. Fortunately Grails is tightly coupled with GORM to ease the use. Since Grails distinguish between different deployment environments, it uses a special configuration for development and production. Therefore you have to think of a database in production environment while you don not in development stage.</p>
<p><a title="Glassfish Site" href="http://www.glassfish.org/" target="_blank">Glassfish</a> v2 and v3 Prelude comes with an internal database JavaDB (based on the Apache Derby) that could be used for first tests. It would be great to use the default database by default for deployments for Glassfish via JNDI. This article shows how to use the bundled database with an Grails application.</p>
<p>In preparation for the next steps you have to install <a title="Grails Installation" href="http://www.grails.org/Installation" target="_blank">Grails 1.1</a> and <a title="Glassfish v2 Installation Instructions" href="https://glassfish.dev.java.net/downloads/v2.1-b60e.html">Glassfish v2</a> or <a title="Glassfish v3 Prelude Installation Instructions" href="http://docs.sun.com/app/docs/doc/820-5968/ggssq?a=view">Glassfish v3 Prelude.</a></p>
<p>To create the demo app just run the following at command line:<br />
<code><br />
grails create-app glassfishapp<br />
cd glassfishapp<br />
grails create-domain-class Bookmark<br />
grails create-controller Bookmark<br />
</code></p>
<p>As the next step edit the domain class and the controller. E.g. open Eclipse with installed <a title="Eclipse Groovy Plugin" href="http://groovy.codehaus.org/Eclipse+Plugin" target="_blank">Groovy plugin.</a></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BookmarkController <span style="color: #009900;">&#123;</span>
    def scaffold <span style="color: #339933;">=</span> Bookmark
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Bookmark <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> constraints <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003399;">String</span> url
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now you are ready to test your app with</p>
<p><code><br />
grails run-app<br />
</code></p>
<p>To prepare the Grails application for Glassfish the data source for the production environment has to be changed. Open the <em>DataSource.groovy</em> and change</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">production <span style="color: #009900;">&#123;</span>
	dataSource <span style="color: #009900;">&#123;</span>
		dbCreate <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update&quot;</span>
		url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:hsqldb:file:prodDb;shutdown=true&quot;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">production <span style="color: #009900;">&#123;</span>
	dataSource <span style="color: #009900;">&#123;</span>
		dbCreate <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update&quot;</span>
		<span style="color: #666666; font-style: italic;">// do not use java:/jdbc as documented</span>
		jndiName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc/__default&quot;</span>
		username <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;APP&quot;</span>
		password <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;APP&quot;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Do not use <code>jndiName = "java:jdbc/__default"</code> as <a href="http://www.grails.org/doc/1.1/guide/3.%20Configuration.html">documented</a>. Be aware that it may be dangerous to use <code>dbCreate= "update"</code> in production environments.</p>
<p>Now compile the web archive with </p>
<p><code>grails war</code></p>
<p>Start your database and the application server<br />
<code>./asadmin start-database<br />
./asadmin start-domain</code></p>
<p>Finally open the sun web interface at http://localhost:4848/ to deploy the war file</p>
<p><code>http://localhost:8080/glassfishapp-0.1/</code></p>
<p>I experienced some memory problems by using Grails with Glassfish. To fix that problem I added <code>-XX:MaxPermSize=256m</code> and <code>-Xmx1024m</code> as JVM option. JVM options can be changed via the web interface (Common Tasks -> Application Server -> JVM Settings -> JVM Options)</p>
<div id="attachment_225" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.acidum.de/wp-content/uploads/2009/04/grails_glassfish.png" rel="lightbox"><img class="size-thumbnail wp-image-225" title="Grails running in Glassfish" src="http://www.acidum.de/wp-content/uploads/2009/04/grails_glassfish-150x150.png" alt="Grails running in Glassfish" width="150" height="150" /></a><p class="wp-caption-text">Grails running in Glassfish</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.acidum.de/2009/04/16/deploy-a-grails-application-into-glassfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.618 seconds -->
