<?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>A Day At The Races &#187; osgi</title>
	<atom:link href="http://blog.jetztgrad.net/category/osgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jetztgrad.net</link>
	<description>Programming was my first love, and it will be my last.</description>
	<lastBuildDate>Mon, 26 Jul 2010 22:27:41 +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>Grails on OSGi (3): Released Grails OSGi plugin 0.1</title>
		<link>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/</link>
		<comments>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 02:35:54 +0000</pubDate>
		<dc:creator>jetztgradnet</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=133</guid>
		<description><![CDATA[The Grails OSGi plugin provides scripts to package a Grails application as an OSGi bundle. Additionally the bundle(s) may be run in an OSGi container assembled ad hoc by the excellent Pax Runner or deployed to a SpringSource DM Server.
License
The OSGi plugin is released under the Apache License 2.0.
Installation
Simply call grails install-plugin osgi to install [...]]]></description>
			<content:encoded><![CDATA[<p>The Grails OSGi plugin provides scripts to package a Grails application as an OSGi bundle. Additionally the bundle(s) may be run in an OSGi container assembled ad hoc by the excellent <a href="http://paxrunner.ops4j.org">Pax Runner</a> or deployed to a <a href="http://www.springsource.org/dmserver">SpringSource DM Server</a>.</p>
<p><b>License</b></p>
<p>The OSGi plugin is released under the <a href="http://apache.org/licenses/LICENSE-2.0.txt">Apache License 2.0</a>.</p>
<p><b>Installation</b></p>
<p>Simply call <code>grails install-plugin osgi</code> to install the OSGi plugin. </p>
<p><b>Usage:</b></p>
<p><b>Creating an OSGi bundle from the Grails application</b></p>
<p><code>grails bundle<br />
grails prod bundle</code></p>
<p><b>Running the bundle</b></p>
<p><code>grails run-bundle<br />
grails prod run-bundle</code></p>
<p>The application can be accessed at <a href="http://localhost:8080/myapp/">http://localhost:8080/myapp/</a>.</p>
<p>Note: at first start the OSGi runtime is assembled, which may take some time, while Maven is downloading the internet&#8230;</p>
<p><b>Creating a zipped OSGi runtime</b></p>
<p><code>grails assemble-osgi-runtime<br />
grails prod assemble-osgi-runtime</code></p>
<p><b>Deploy bundle to DM Server</b></p>
<p><code>grails dmserver deploy</code> (Not yet implemented)</p>
<p><b>Getting around the OSGi runtime</b></p>
<p>The OSGi runtime is based on the <a href="http://www.eclipse.org/equinox">Equinox</a> OSGi framework, <a href="http://paxweb.ops4j.org">Pax Web</a> and some additional bundles.</p>
<p><b>Web Console</b></p>
<p>The <a href="http://felix.apache.org/site/apache-felix-web-console.html">Felix Web Management Console</a> provides excellent insight into the inner workings (see Screenshots). It can be accessed at <a href="http://localhost:8080/system/console/">http://localhost:8080/system/console/</a> with user &#8220;admin&#8221; and password &#8220;admin&#8221;.</p>
<p><a href="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole.png"><img src="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-197x300.png" alt="" title="Web Management Console" width="197" height="300" class="aligncenter size-medium wp-image-158" /></a></p>
<p><a href="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-GrailsAppBundle.png"><img src="http://blog.jetztgrad.net/wp-content/uploads/2010/01/ManagementConsole-GrailsAppBundle-77x300.png" alt="" title="Management Console: Details of the Grails application bundle" width="77" height="300" class="aligncenter size-medium wp-image-160" /></a></p>
<p><b>Shell Console</b></p>
<p>The command <code>grails run-bundle</code> drops the user in the Equinox Shell. Typing <code>help</code> shows the available commands.</p>
<p><b>How it works</b></p>
<p>In order to be a valid OSGi bundle, the application is war&#8217;ed and provided with the necessary bundle manifest headers (see <code>scripts/_Event.groovy</code> for details).<br />
The bundle can be created using <code>grails bundle</code>.  </p>
<p>The OSGi runtime is assembled in the <code>target/osgi</code> directory.</p>
<p><b>Source code and Issues</b></p>
<p>The source code is hosted at <a href="http://github.com/jetztgradnet/grails-osgi-plugin">GitHub</a>, issues can be reported <a href="http://github.com/jetztgradnet/grails-osgi-plugin/issues">here</a>.</p>
<p><b>Roadmap</b></p>
<ul>
<li>make bundle generation configurable (e.g. include/exclude dependencies, &#8230;)</li>
<li>make OSGi runtime created by <code>grails run-bundle</code> and <code>grails assemble-osgi-runtime</code> configurable</li>
<li>support auto-reloading of changed artifacts</li>
<li>use Spring DM instead of Pax Web as Web extender</li>
<li>remove dependencies from bundle and package them as their own plugins (re-using existing bundles from the <a href="http://www.springsource.com/repository">SpringSource Enterprise Repository</a></li>
<li>export main Grails beans and application context as OSGi service</li>
<li>export services as OSGi service (via <code>static expose = 'osgi'</code>)</li>
<li>provide access to OSGi <code>BundleContext</code> to artifacts (controllers, services, &#8230;)</li>
<li>implement deployment to DM Server</li>
<li>consider other deployment options: Apache Karaf, &#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2010/01/released-grails-osgi-plugin-0-1/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Grails on OSGi (2): First steps</title>
		<link>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/</link>
		<comments>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 11:43:07 +0000</pubDate>
		<dc:creator>jetztgradnet</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=77</guid>
		<description><![CDATA[This part of the series shows the necessary step to get a Grails application running in an OSGi environment as a monolithic bundle.]]></description>
			<content:encoded><![CDATA[<p>The first step on the road to running Grails applications in an OSGi environment is to get a simple application to run as a monolithic bundle (almost) without changes.</p>
<p><br/></p>
<p><b>Test application</b></p>
<p>We create a simple Grails application (e.g. the one described in a <a href="https://www.ibm.com/developerworks/java/library/j-grails01158/">article on developer works</a>; the application has a single domain class <code>Trip</code>, the controller and all views are generated). A single domain class and the corresponding controller is all we need for a simple test.</p>
<p><br/></p>
<p><b>Bundle 101</b></p>
<p>For the first attempt, the Grails application will be transformed, into a single, monolithic bundle (see <a href="/2009/11/grails-on-osgi-1-thoughts">part 1</a> for possible modularization levels) containing all dependencies like Grails, Groovy, Hibernate, Spring, &#8230; </p>
<p>A bundle is basically a JAR or WAR with some special headers in its manifest file. Required headers are <code>Bundle-SymbolicName</code>, which uniquely identifies the bundle, <code>Bundle-Version</code>, which specifies the bundle version (multiple versions of the bundle can run concurrently!) and <code>Bundle-ClassPath</code>, which specifies the classpath within the bundle. Other important headers are <code>Import-Package</code> and <code>Export-Package</code>, which are necessary when using code and resources from and providing classes to other bundles.</p>
<p><br/></p>
<p><b>Preparing the bundle</b></p>
<p>In order to create a valid bundle manifest, <code>$GRAILS_HOME/scripts/_GrailsWar.groovy</code> must be patched with <a href="http://github.com/jetztgradnet/grails-osgi-testenv/blob/master/bundle-manifest.patch"> bundle-manifest.patch</a>:</p>
<p><code>cd $GRAILS_HOME<br />
patch -p0 < /pacth/to/bundle-manifest.patch<br />
</code></p>
<p>In the future, the changes could either be integrated into Grails directly  or into a OSGi plugin.</p>
<p>Our Grails application will need to be transformed into a bundle, so we package it using <code>grails war</code>. The application and all dependencies are contained in the resulting WAR file.</p>
<p>The bundle manifest can now be inspected using the following command (on Linux or Mac OSX):</p>
<p><code>unzip -p target/trip-planner-0.1.war META-INF/MANIFEST.MF</code></p>
<p>The manifest now looks like this:</p>
<p><code><br />
Manifest-Version: 1.0<br />
Ant-Version: Apache Ant 1.7.1<br />
Created-By: 14.1-b02-92 (Apple Inc.)<br />
Bundle-ManifestVersion: 2<br />
Bundle-Name: trip-planner<br />
Bundle-SymbolicName: trip-planner<br />
Bundle-Version: 0.1<br />
Bundle-ClassPath: WEB-INF/classes,WEB-INF/lib/antlr-2.7.6.jar,WEB-INF/<br />
 lib/aopalliance-1.0.jar,WEB-INF/lib/aspectjrt-1.6.2.jar,WEB-INF/lib/a<br />
 spectjweaver-1.6.2.jar,WEB-INF/lib/cglib-nodep-2.1_3.jar,WEB-INF/lib/<br />
 commons-beanutils-1.8.0.jar,WEB-INF/lib/commons-codec-1.3.jar,WEB-INF<br />
 /lib/commons-collections-3.2.1.jar,WEB-INF/lib/commons-dbcp-1.2.2.jar<br />
 ,WEB-INF/lib/commons-el-1.0.jar,WEB-INF/lib/commons-fileupload-1.2.1.<br />
 jar,WEB-INF/lib/commons-io-1.4.jar,WEB-INF/lib/commons-lang-2.4.jar,W<br />
 EB-INF/lib/commons-pool-1.5.3.jar,WEB-INF/lib/commons-validator-1.3.1<br />
 .jar,WEB-INF/lib/dom4j-1.6.1.jar,WEB-INF/lib/ehcache-1.6.1.jar,WEB-IN<br />
 F/lib/ejb3-persistence-1.0.2.GA.jar,WEB-INF/lib/grails-bootstrap-1.2-<br />
 M4.jar,WEB-INF/lib/grails-core-1.2-M4.jar,WEB-INF/lib/grails-crud-1.2<br />
 -M4.jar,WEB-INF/lib/grails-docs-1.2-M4.jar,WEB-INF/lib/grails-gorm-1.<br />
 2-M4.jar,WEB-INF/lib/grails-resources-1.2-M4.jar,WEB-INF/lib/grails-s<br />
 pring-1.2-M4.jar,WEB-INF/lib/grails-web-1.2-M4.jar,WEB-INF/lib/groovy<br />
 -all-1.6.5.jar,WEB-INF/lib/hibernate-annotations-3.4.0.GA.jar,WEB-INF<br />
 /lib/hibernate-commons-annotations-3.3.0.ga.jar,WEB-INF/lib/hibernate<br />
 -core-3.3.1.GA.jar,WEB-INF/lib/hibernate-ehcache-3.3.1.GA.jar,WEB-INF<br />
 /lib/hsqldb-1.8.0.10.jar,WEB-INF/lib/javassist-3.4.GA.jar,WEB-INF/lib<br />
 /jcl-over-slf4j-1.5.6.jar,WEB-INF/lib/jta-1.1.jar,WEB-INF/lib/jul-to-<br />
 slf4j-1.5.6.jar,WEB-INF/lib/log4j-1.2.15.jar,WEB-INF/lib/org.springfr<br />
 amework.aop-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.asm-3.0.0.R<br />
 C1.jar,WEB-INF/lib/org.springframework.aspects-3.0.0.RC1.jar,WEB-INF/<br />
 lib/org.springframework.beans-3.0.0.RC1.jar,WEB-INF/lib/org.springfra<br />
 mework.context-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.context.<br />
 support-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.core-3.0.0.RC1.<br />
 jar,WEB-INF/lib/org.springframework.expression-3.0.0.RC1.jar,WEB-INF/<br />
 lib/org.springframework.instrument-3.0.0.RC1.jar,WEB-INF/lib/org.spri<br />
 ngframework.jdbc-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.jms-3.<br />
 0.0.RC1.jar,WEB-INF/lib/org.springframework.orm-3.0.0.RC1.jar,WEB-INF<br />
 /lib/org.springframework.oxm-3.0.0.RC1.jar,WEB-INF/lib/org.springfram<br />
 ework.transaction-3.0.0.RC1.jar,WEB-INF/lib/org.springframework.web-3<br />
 .0.0.RC1.jar,WEB-INF/lib/org.springframework.web.servlet-3.0.0.RC1.ja<br />
 r,WEB-INF/lib/oro-2.0.8.jar,WEB-INF/lib/oscache-2.4.1.jar,WEB-INF/lib<br />
 /sitemesh-2.4.jar,WEB-INF/lib/slf4j-api-1.5.6.jar,WEB-INF/lib/slf4j-l<br />
 og4j12-1.5.6.jar,WEB-INF/lib/standard-1.1.2.jar,WEB-INF/lib/xpp3_min-<br />
 1.1.3.4.O.jar<br />
Import-Package: javax.servlet,javax.servlet.http,javax.servlet.resourc<br />
 es,javax.servlet.jsp.resources;resolution:=optional,javax.xml.parsers<br />
 ,org.w3c.dom,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers<br />
Webapp-Context: trip-planner</p>
<p>Name: Grails Application<br />
Implementation-Title: trip-planner<br />
Implementation-Version: 0.1<br />
Grails-Version: 1.2-M4<br />
</code></p>
<p>Note that <code>Bundle-ClassPath</code> contains all dependencies required by Grails, JAR files from the <code>lib/</code> directory, and those contributed by installed Grails plugins.</p>
<p>The bundle imports some packages from the <a href="http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html">Servlet specification</a>. This is to ensure, that the bundle uses the same classes as the web container, otherwise the classes would not be compatible, as they would be loaded by different class loaders.</p>
<p>BTW: if you need to have a look at the generated web.xml, you can achieve it like this:</p>
<p><code>unzip -p target/trip-planner-0.1.war WEB-INF/web.xml | xmllint --format -</code></p>
<p><br/></p>
<p><b>Running the bundle</b></p>
<p>In order to run the bundle, it must be installed into an OSGi container like <a href="http://eclipse.org/equinox">Equinox</a> (the base for the Eclipse IDE), <a href="http://felix.apache.org">Apache Felix</a>, or <a href="http://www.knopflerfish.org/">Knopflerfish</a>. The test environment described below uses Equinox. Other frameworks could be used as well, but I haven't tested them yet.</p>
<p>Additionally we need a web container like <a href="http://tomcat.apache.org/">Tomcat</a> or <a href="http://www.mortbay.org/jetty/">Jetty</a>. The web container needs also to be installed within the OSGi container, so we skip the download on the main site(s), but go looking for OSGI-fied versions. Jetty is OSGi-capable out of the box, an adapted Tomcat also used in <a href="http://www.springsource.com/products/dmserver">Spring dm server</a> can be found at the SpringSource <a href="http://www.springsource.com/repository/app/">Enterprise Bundle Repository</a>. (Note: Tomcat does not yet work, so we currently use Jetty. I get no errors, but all requests seem to get silently ignored.)</p>
<p>The remaining part is a module usually called Web Extender, which bridges the gap between web applications and the web container. The web extender looks for bundles matching a certain criteria (e.g. existance of <code>WEB-INF/web.xml</code> or some bundle headers) and configures these as a web application. Candidates are <a href="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</a> and <a href="http://www.springsource.org/osgi">Spring-DM</a>.</p>
<p>As Pax Web is currently not able to configure a Grails applications because of <a href="http://issues.ops4j.org/browse/PAXWEB-148">PAXWEB-148</a>, and Spring-DM will probably be required for other OSGi and Spring related stuff anyway, we use the latter as Web Extender.</p>
<p><br/></p>
<p><b>Test environment</b></p>
<p>The test environment is made up of the excellent <a href="http://paxrunner.ops4j.org/">Pax Runner</a> with a <a href="http://github.com/jetztgradnet/grails-osgi-testenv">set of configuration files</a>. Pax Runner is basically a starter for OSGi applications. It supports different OSGi frameworks and provisions both framework and bundles from sources like Maven repos, web servers, or directories.</p>
<p>The test environment loads the Equinox OSGi Framework (version 3.5.1), Spring-DM 2.0M1, Spring 3.0RC1, and Jetty (Tomcat doesn’t work right know). All configuration files be found on <a href="http://github.com/jetztgradnet/grails-osgi-testenv">GitHub</a>.</p>
<p>The test environment can be installed using the following commands:</p>
<p>Create a directory and change into it:</p>
<p><code>mkdir testenv; cd testenv</code></p>
<p>Download Pax Runner, extract it and create a version agnostic link:</p>
<p><code>curl -o pax-runner-assembly-1.3.0-jdk15.tar.gz http://repo1.maven.org/maven2/org/ops4j/pax/runner/pax-runner-assembly/1.3.0/pax-runner-assembly-1.3.0-jdk15.tar.gz</code></p>
<p><code>tar xzf pax-runner-assembly-1.3.0-jdk15.tar.gz</code></p>
<p><code>ln -s pax-runner-1.3.0 pax-runner</code></p>
<p>Get the example configuration:</p>
<p><code>git clone git://github.com/jetztgradnet/grails-osgi-testenv.git</code></p>
<p>The framework can be started with the following command:</p>
<p><code>cd grails-osgi-testenv<br />
./pax-osgitest</code></p>
<p>After lots of log messages, we arrive at a prompt of the command shell. Help is available using <code>help</code>.</p>
<p>We now type <code>ss</code> to get an overview over all running bundles:</p>
<p><code><br />
osgi> ss</p>
<p>Framework is launched.</p>
<p>id	State       Bundle<br />
0	ACTIVE      org.eclipse.osgi_3.5.1.R35x_v20090827<br />
1	ACTIVE      org.eclipse.osgi.util_3.2.0.v20090520-1800<br />
2	ACTIVE      org.eclipse.osgi.services_3.2.0.v20090520-1800<br />
3	ACTIVE      org.springframework.aop_3.0.0.RC1<br />
4	ACTIVE      org.springframework.asm_3.0.0.RC1<br />
5	ACTIVE      org.springframework.aspects_3.0.0.RC1<br />
6	ACTIVE      org.springframework.beans_3.0.0.RC1<br />
7	ACTIVE      org.springframework.context_3.0.0.RC1<br />
8	ACTIVE      org.springframework.context.support_3.0.0.RC1<br />
9	ACTIVE      org.springframework.core_3.0.0.RC1<br />
10	ACTIVE      org.springframework.expression_3.0.0.RC1<br />
11	ACTIVE      org.springframework.jdbc_3.0.0.RC1<br />
12	INSTALLED   org.springframework.jms_3.0.0.RC1<br />
13	ACTIVE      org.springframework.orm_3.0.0.RC1<br />
14	ACTIVE      org.springframework.transaction_3.0.0.RC1<br />
15	ACTIVE      org.springframework.web_3.0.0.RC1<br />
16	ACTIVE      org.springframework.web.servlet_3.0.0.RC1<br />
17	ACTIVE      com.springsource.org.aopalliance_1.0.0<br />
18	ACTIVE      com.springsource.org.objectweb.asm_2.2.3<br />
19	ACTIVE      com.springsource.net.sf.cglib_2.1.3<br />
20	ACTIVE      org.springframework.osgi.core_2.0.0.M1<br />
21	ACTIVE      org.springframework.osgi.extender_2.0.0.M1<br />
22	ACTIVE      org.springframework.osgi.io_2.0.0.M1<br />
23	ACTIVE      org.springframework.osgi.web_2.0.0.M1<br />
24	ACTIVE      org.springframework.osgi.web.extender_2.0.0.M1<br />
	            Fragments=28<br />
25	ACTIVE      com.springsource.org.mortbay.jetty.server_6.1.9<br />
26	ACTIVE      com.springsource.org.mortbay.util_6.1.9<br />
27	ACTIVE      org.springframework.osgi.jetty.start.osgi_1.0.0<br />
28	RESOLVED    org.springframework.osgi.jetty.web.extender.fragment.osgi_1.0.1<br />
	            Master=24<br />
29	ACTIVE      com.springsource.javax.activation_1.1.1<br />
30	ACTIVE      com.springsource.javax.annotation_1.0.0<br />
31	ACTIVE      com.springsource.javax.el_1.0.0<br />
32	ACTIVE      com.springsource.javax.ejb_3.0.0<br />
33	ACTIVE      com.springsource.javax.mail_1.4.1<br />
34	ACTIVE      com.springsource.javax.persistence_1.99.0<br />
35	ACTIVE      com.springsource.javax.transaction_1.1.0<br />
36	ACTIVE      com.springsource.javax.servlet_2.5.0<br />
37	ACTIVE      com.springsource.javax.servlet.jsp_2.1.0<br />
38	ACTIVE      com.springsource.javax.xml.bind_2.1.7<br />
39	ACTIVE      com.springsource.javax.xml.rpc_1.1.0<br />
40	ACTIVE      com.springsource.javax.xml.soap_1.3.0<br />
41	ACTIVE      com.springsource.javax.xml.stream_1.0.1<br />
42	ACTIVE      com.springsource.javax.xml.ws_2.1.1<br />
43	ACTIVE      org.apache.felix.webconsole_2.0.2<br />
45	ACTIVE      org.ops4j.pax.logging.pax-logging-api_1.4.0<br />
46	ACTIVE      org.ops4j.pax.logging.pax-logging-service_1.4.0<br />
47	ACTIVE      org.eclipse.equinox.util_1.0.100.v20090520-1800<br />
48	ACTIVE      org.eclipse.equinox.ds_1.1.1.R35x_v20090806<br />
49	ACTIVE      org.eclipse.equinox.cm_1.0.100.v20090520-1800<br />
50	ACTIVE      org.eclipse.equinox.supplement_1.1.0.v20080421-2006<br />
51	ACTIVE      org.eclipse.equinox.common_3.4.0.v20080421-2006<br />
52	ACTIVE      org.eclipse.equinox.preferences_3.2.201.R34x_v20080709<br />
53	ACTIVE      org.ops4j.pax.url.assembly_1.1.1<br />
54	ACTIVE      org.ops4j.pax.url.classpath_1.1.1<br />
55	ACTIVE      org.ops4j.pax.url.cache_1.1.1<br />
56	ACTIVE      org.ops4j.pax.url.mvn_1.1.1<br />
57	ACTIVE      org.ops4j.pax.url.link_1.1.1<br />
58	ACTIVE      org.ops4j.pax.url.war_1.1.1<br />
59	ACTIVE      org.ops4j.pax.url.wrap_1.1.1<br />
</code></p>
<p>We can now install our bundle:</p>
<p><code>install file:/path/to/trip-planner-0.1.war<br />
Bundle id is 60<br />
</code></p>
<p>After installing we run <code>ss</code> again. Our bundle is now installed and in the <code>RESOLVED</code> state. With the id of our bundle (the number in the first column), we can now start it:</p>
<p><code>start 60</code></p>
<p>The application should now be reachable at <a href="http://localhost:8080/trip-planner-0.1/">http://localhost:8080/trip-planner-0.1/</a>. If you get a <code>404</code> HTTP error, wait a moment, to give the web extender time to configure the bundle.</p>
<p>The <code>system</code> directory serves as the current directory of the OSGi container. The HSQLdb files from our test application will be created there, log messages of the container are written to the <code>system/logs</code> directory.</p>
<p>If our web bundle has been changed, we can simply update it using <code> update 60</code>. If this does not work, we can un- and reinstall it using <code>uninstall 60</code> and the installation procedure described above.</p>
<p><br/></p>
<p><b>Next steps</b></p>
<p>As outlined in <a href="/2009/11/grails-on-osgi-1-thoughts">part 1</a>, the ultimate goal is to create modular Grails applications. The next step will be to extract the dependencies from the monolithic bundle and put them into their own bundles. Spring and Groovy are already available as bundles, other dependencies may need to be replaced with an OSGi-ready version, e.g. from the SpringSource <a href="http://www.springsource.com/repository/app/">Bundle Repository</a>. </p>
<p>There will be some issues regarding singletons (e.g. <code>ApplicationHolder</code>, <code>ConfigurationHolder</code>) and class loading (Hibernate), but I think, they can be resolved with some work.</p>
<p>The findings may finally find their way into Grails or a Grails OSGi plugin.</p>
<p>Stay tuned...</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2009/11/grails-on-osgi-2-first-steps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grails on OSGi (1): Thoughts</title>
		<link>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/</link>
		<comments>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 01:41:02 +0000</pubDate>
		<dc:creator>jetztgradnet</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://blog.jetztgrad.net/?p=30</guid>
		<description><![CDATA[Running a Grails application in an OSGi environment provides many benefits such as better modularization. There are different levels of OSGi support, each with its own set of advantages and disadvantages.]]></description>
			<content:encoded><![CDATA[<p><b>What is OSGi</b></p>
<p>The <a href="http://www.osgi.org">OSGi</a> Alliance (formerly known as the Open Services Gateway initiative) is a consortium of companies in the Java world, which develop the OSGi Service Platform, a framework for component-oriented software. Originally developed for embeded devices, OSGi frameworks can now also be found in enterprise, mobile, home, telematics and consumer products.</p>
<p>Applications in an OSGi environment are split into individual modules called bundles, which are usually provided as jar files. Each bundle provides a manifest file containing meta data, which describe its name, version, dependencies and offerings, i.e. code and services. An OSGi container can host multiple applications at once, each application can be started or stopped any time.</p>
<p>The OSGi <a href="http://www.osgi.org/Specifications/HomePage">specifications</a> describe both the core framework and a set of standard services for common functionality such as logging, web access, declarative services, etc.  A more detailed description can be found <a href="http://www.osgi.org/About/Technology">here</a>.</p>
<p>There are multiple OSGi implementations available. Well-known open source implementations include <a href="http://eclipse.org/equinox">Equinox</a>, which is the base for the Eclipse IDE and eco system, <a href="http://felix.apache.org">Apache Felix</a> and <a href="http://www.knopflerfish.org/">Knopflerfish</a>.</p>
<p><br/></p>
<p><b>Benefits</b></p>
<p>Running a Grails application in an OSGi environment would bring some benefits:</p>
<ul>
<li>Support for modularization</li>
<li>Handling and versioning of components and dependencies (*)</li>
<li>Separation of applications</li>
<li>Dependencies and used libraries can be transferred independently to the application server, which makes for smaller application bundles and therefore faster transmission</li>
<li>Easy in-place update and reloading of individual components during runtime</li>
<li>Service-oriented architecture</li>
</ul>
<p>(*) Alltough starting with version 1.2 Grails provides good support for <a href="http://grails.org/doc/1.2.x/guide/3.%20Configuration.html#3.7%20Dependency%20Resolution"> versioning and  dependency resolution</a> with the integration of Ivy)</p>
<p><br/></p>
<p><b>Progress so far</b></p>
<p>JIRA issue <a href="http://jira.codehaus.org/browse/GRAILS-2221">GRAILS-2221</a> for OSGi support for Grails exists for quite some time. Originally OSGi support was requested with an eye towards a plugin system. Grails now has its own plugin system, but OSGi support is on the roadmap for Grails 2.0, whenever that will be released <img src='http://blog.jetztgrad.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><em>Update:</em> Grails 1.2 will contain a valid OSGi <a href="http://github.com/grails/grails/blob/master/grails/maven/grails-core.mf">bundle manifest</a>, so the Grails jars may already be pulled out of a Grails application bundle and installed sepearately.</p>
<p><br/></p>
<p><b>Possible implementation levels</b></p>
<p>There are several possibilities running a Grails application in an OSGi environment:</p>
<ul>
<li>Monolithic application (Compatibility mode)</li>
<li>Modularized application</li>
<li>Fully componentized application</li>
</ul>
<p><br/></p>
<p><b> Monolithic application (Compatibility mode)</b></p>
<p>This can be seen as a first step of an OSGi-fied Grails application and should be already possible today with some manual steps. </p>
<p>The Grails application is packaged as a WAR file with the manifest file containing necessary OSGi headers, like <code>Bundle-SymbolicName</code>, <code>Bundle-Version</code>, <code>Bundle-ClassPath</code>, and <code>Import-Package</code>. </p>
<p>An OSGi framework providing a web service and corresponding web extender like <a href="http://www.springsource.org/osgi">Spring-DM</a> or <a href="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</a> can now run this application. </p>
<p>Advantages:</p>
<ul>
<li>Already possible today</li>
<li>No classloading issues</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>No modularization</li>
<li>Big, monolithic bundle, slow upload to an application server</li>
</ul>
<p><br/></p>
<p><b>Modularized application</b></p>
<p>The next step will be splitting a Grails application into individual bundles. Ideally each of Grails&#8217; and the application&#8217;s dependencies like Hibernate, Sitemesh, etc. would come as its own (set of) bundle(s). </p>
<p>Spring and Groovy already contain OSGi meta data and can be run unmodified in an OSGi environment, OSGi-fied bundles of some other dependencies can be found in the bundle repositories provided by <a href="http://www.springsource.com/repository/app/">SpringSource</a>, <a href="http://felix.apache.org/obr/">Apache Felix</a>, or <a href="http://www.knopflerfish.org/repo/repository.xml">Knopflerfish</a>. Eclipse also hosts some third-party libraries, e.g. many commonly-used Apache jars, which were converted to OSGi bundles, in the <a href="http://eclipse.org/orbit/">Orbit</a> project.</p>
<p>The Grails application itself would be another bundle. As it contains no dependencies, it would be quite small and can therefore easily be transferred to an application server.</p>
<p>Advantages:</p>
<ul>
<li>Shared dependencies for all Grails applications</li>
<li>Small bundle for faster upload to an application server</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Issues with Grails&#8217; singletons, when running more than one Grails application in a single VM (*)</li>
<li>Classloading issues</li>
</ul>
<p>(*) This is also the case when running more than one Grails application in a servlet container with shared jars, e.g. using <code>grails war --nojars</code>.</p>
<p><br/></p>
<p><b>Fully componentized application</b></p>
<p>Many posts on the Grails <a href="http://grails.org/Mailing+lists">mailing list</a> ask for ways to modularize big web applications. The most common answer and approach is to split the application into multiple Grails plugins. </p>
<p>In an OSGi environment, the Grails application could be split into multiple bundles, each of which can be individually updated or reloaded. Each Grails plugin would compose a bundle of its own, which could be used and shared by multiple Grails applications.</p>
<p>A starting point for implementing this approach could be the newly created <a href="http://blog.springsource.com/2009/06/22/modular-web-applications-with-springsource-slices/">Spring Slices</a> project.</p>
<p>Advantages:</p>
<ul>
<li>Full modularization</li>
<li>Small bundles for fast uploads to an application server</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Issues with Grails&#8217; singletons, when running more than one Grails application in a single VM</li>
<li>Classloading issues</li>
</ul>
<p><br/></p>
<p><b>OSGi-fied Development mode</b></p>
<p>The Grails development mode (aka <code>grails run-app</code>) could also profit from OSGi support. With the OSGi framework constantly running, changes could be integrated by simply updating or reloading individual bundles. Even major changes would only mean reloading some bundles. This would reduce startup times, as the VM is always running and does not need to be stopped and restarted.</p>
<p>For extreme cases, each controller/domain class/Grails artefact could even be temporarily packaged in its own bundle. </p>
<p><br/></p>
<p><b>Conclusion</b></p>
<p>Real OSGi support for Grails is still some time in the future. There is a lot to do and some issues regarding classloading and singletons to resolve. This series of blog posts will look at OSGi support from different angles and try to find solutions to emerging problems. Stay tuned&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jetztgrad.net/2009/11/grails-on-osgi-1-thoughts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
