<?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>Marco Mastrodonato &#187; Glassfish</title>
	<atom:link href="http://mastrodonato.info/index.php/tag/glassfish/feed/" rel="self" type="application/rss+xml" />
	<link>http://mastrodonato.info</link>
	<description>Non c&#039;e&#039; prezzo per la miticita&#039;</description>
	<lastBuildDate>Mon, 06 Sep 2010 21:05:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Configurare un ambiente per jRuby on Rails</title>
		<link>http://mastrodonato.info/index.php/2009/07/configurare-un-ambiente-per-jruby-on-rails/</link>
		<comments>http://mastrodonato.info/index.php/2009/07/configurare-un-ambiente-per-jruby-on-rails/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 16:52:31 +0000</pubDate>
		<dc:creator>Marco Mastrodonato</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[jRuby]]></category>

		<guid isPermaLink="false">http://mastrodonato.info/?p=54</guid>
		<description><![CDATA[Nei prossimi articoli utilizzerò jruby 1.3.1 con Rails 2.3.3 e ne approfitto per scrivere due righe su come configurare il sistema. A proposito, il sistema utilizzato è un windows xp virtualizzato, java sdk 6, glassfish come application server e javadb. Scarichiamo e installiamo l&#8217;sdk java, siamo alla versione 6 update 14. C&#8217;è anche il download [...]]]></description>
			<content:encoded><![CDATA[<p>Nei prossimi articoli utilizzerò jruby 1.3.1 con Rails 2.3.3 e ne approfitto per scrivere due righe su come configurare il sistema.<br />
A proposito, il sistema utilizzato è un windows xp virtualizzato, java sdk 6, glassfish come application server e javadb.</p>
<p>Scarichiamo e installiamo l&#8217;<a href="http://java.sun.com/javase/downloads/index.jsp" target="_blank">sdk java</a>, siamo alla versione 6 update 14.</p>
<p>C&#8217;è anche il download dell&#8217;sdk con netbeans, un ottimo IDE per gestire progetti ruby on rails. Potrebbe essere un occasione per provarlo. Il pacchetto comprende anche l&#8217;application server glassfish V3.</p>
<p>Ora scarichiamo e installiamo <a href="http://www.jruby.org/" target="_blank">jRuby</a>, siamo alla versione 1.3.1.</p>
<p>L&#8217;installazione è semplicissima: scompattiamo lo zip in un percorso del tipo C:\ruby\jruby-131</p>
<p>Andiamo ad impostare le variabili d&#8217;ambiente, tasto destro su &#8220;Risorse del computer&#8221; sul desktop -> &#8220;Proprietà&#8221; -> seleziona il tab &#8220;Avanzate&#8221; -> click su &#8220;variabili d&#8217;ambiente&#8221;.</p>
<ul>
<li>Aggiungiamo alla variabile <strong>PATH</strong> il percorso della cartella bin dove abbiamo installato jruby, per esempio C:\ruby\jruby-131\bin.</li>
<li>Impostiamo la variabile d&#8217;ambiente <strong>JAVA_HOME</strong>.  Nella zona &#8220;variabili di sistema&#8221; -> &#8220;nuovo&#8221; -> come nome &#8220;JAVA_HOME&#8221; come valore il percorso di installazione dell&#8217;sdk per esempio C:\Programmi\Java\jdk1.6.0_14</li>
</ul>
<p>Non è necessario riavviare il sistema operativo, testiamo il risultato:<br />
<code><br />
C:\><strong>jruby -v</strong><br />
jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]<br />
</code></p>
<p>Eureka! Ora abbiamo jruby, jirb ed il solito gem. <strong>Se nel sistema è presente anche ruby classico è necessario specificare jruby -S</strong> per richiamare gem, utilizziamolo subito per installare rails 2.3.3:<br />
<code><br />
C:\><strong>jruby -S gem install rails</strong><br />
Successfully installed activesupport-2.3.3<br />
Successfully installed activerecord-2.3.3<br />
Successfully installed actionpack-2.3.3<br />
Successfully installed actionmailer-2.3.3<br />
Successfully installed activeresource-2.3.3<br />
Successfully installed rails-2.3.3<br />
6 gems installed<br />
Installing ri documentation for activesupport-2.3.3...<br />
Installing ri documentation for activerecord-2.3.3...<br />
Installing ri documentation for actionpack-2.3.3...<br />
Installing ri documentation for actionmailer-2.3.3...<br />
Installing ri documentation for activeresource-2.3.3...<br />
Installing ri documentation for rails-2.3.3...<br />
Installing RDoc documentation for activesupport-2.3.3...<br />
Installing RDoc documentation for activerecord-2.3.3...<br />
Installing RDoc documentation for actionpack-2.3.3...<br />
Installing RDoc documentation for actionmailer-2.3.3...<br />
Installing RDoc documentation for activeresource-2.3.3...<br />
Installing RDoc documentation for rails-2.3.3...<br />
</code></p>
<p>Installiamo l&#8217;adapter jdbc per collegarci a java DB (da ora ometto jruby -S, nel mio sistema non è necessario):<br />
<code><br />
C:\><strong>gem install activerecord-jdbcderby-adapter</strong><br />
Successfully installed activerecord-jdbc-adapter-0.9.1<br />
Successfully installed jdbc-derby-10.4.2.0<br />
Successfully installed activerecord-jdbcderby-adapter-0.9.1<br />
3 gems installed<br />
Installing ri documentation for activerecord-jdbc-adapter-0.9.1...<br />
Installing ri documentation for jdbc-derby-10.4.2.0...<br />
Installing ri documentation for activerecord-jdbcderby-adapter-0.9.1...<br />
Installing RDoc documentation for activerecord-jdbc-adapter-0.9.1...<br />
Installing RDoc documentation for jdbc-derby-10.4.2.0...<br />
Installing RDoc documentation for activerecord-jdbcderby-adapter-0.9.1...<br />
</code></p>
<p>Poi installiamo la gemma per glassfish:<br />
<code><br />
C:\><strong>gem install glassfish</strong><br />
Successfully installed rack-1.0.0<br />
Successfully installed glassfish-0.9.5-universal-java<br />
2 gems installed<br />
Installing ri documentation for rack-1.0.0...<br />
Installing ri documentation for glassfish-0.9.5-universal-java...<br />
Installing RDoc documentation for rack-1.0.0...<br />
Installing RDoc documentation for glassfish-0.9.5-universal-java...<br />
</code></p>
<p>Siamo pronti, creiamo un nuovo progetto:<br />
<code><br />
C:\>rails ProvaArticolo<br />
</code></p>
<p>&#8230;nel file di configurazione dei db utilizziamo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># config/database.yml</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># JavaDB Setup</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># You may need to copy derby.jar into</span>
<span style="color:#008000; font-style:italic;">#  TODO: location C:\ruby\jruby-131\lib</span>
<span style="color:#008000; font-style:italic;"># With Java SE 6 and later this is not necessary.</span>
development:
  adapter: derby
  database: db<span style="color:#006600; font-weight:bold;">/</span>development.<span style="color:#9900CC;">db</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Warning: The database defined as 'test' will be erased and</span>
<span style="color:#008000; font-style:italic;"># re-generated from your development database when you run 'rake'.</span>
<span style="color:#008000; font-style:italic;"># Do not set this db to the same as development or production.</span>
test:
  adapter: derby
  database: db<span style="color:#006600; font-weight:bold;">/</span>test.<span style="color:#9900CC;">db</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Warning: The database defined as 'test' will be erased and</span>
<span style="color:#008000; font-style:italic;"># re-generated from your development database when you run 'rake'.</span>
<span style="color:#008000; font-style:italic;"># Do not set this db to the same as development or production.</span>
production:
  adapter: derby
  database: db<span style="color:#006600; font-weight:bold;">/</span>production.<span style="color:#9900CC;">db</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Warning: The database defined as 'test' will be erased and</span>
<span style="color:#008000; font-style:italic;"># re-generated from your development database when you run 'rake'.</span>
<span style="color:#008000; font-style:italic;"># Do not set this db to the same as development or production.</span></pre></div></div>

<p>Facciamo partire il server, dal prompt dentro la nostra applicazione:<br />
<code><br />
C:\ProvaArticolo><strong>glassfish</strong><br />
Starting GlassFish server at: 127.0.0.1:3000 in development environment...<br />
Writing log messages to: C:/ProvaArticolo/log/development.log.<br />
Press Ctrl+C to stop.<br />
</code></p>
<p>All&#8217;indirizzo http://localhost:3000/ dovremmo vedere la pagina di benvenuto.<br />
Ora fermiamo il server con Ctrl+C e creiamo il db in ambiente sviluppo:</p>
<p><code>C:\ProvaArticolo><strong>rake db:create</strong><br />
(in C:/ProvaArticolo)<br />
db/development.db already exists</code></p>
<p>Creiamo qualcosa all&#8217;interno del database, iniziamo con la risorsa di rails:<br />
<code><br />
C:\ProvaArticolo>jruby script/generate scaffold article name:string body:text<br />
      create  app/models/<br />
      exists  app/controllers/<br />
      exists  app/helpers/<br />
      exists  app/views/articles<br />
      create  app/views/layouts/<br />
      create  test/functional/<br />
      create  test/unit/<br />
      create  test/unit/helpers/<br />
      create  public/stylesheets/<br />
      create  app/views/articles/index.html.erb<br />
      create  app/views/articles/show.html.erb<br />
      create  app/views/articles/new.html.erb<br />
      create  app/views/articles/edit.html.erb<br />
      create  app/views/layouts/articles.html.erb<br />
      create  public/stylesheets/scaffold.css<br />
      create  app/controllers/articles_controller.rb<br />
      create  test/functional/articles_controller_test.rb<br />
      create  app/helpers/articles_helper.rb<br />
      create  test/unit/helpers/articles_helper_test.rb<br />
       route  map.resources :articles<br />
  dependency  model<br />
      exists    app/models/<br />
      exists    test/unit/<br />
      create    test/fixtures/<br />
      create    app/models/article.rb<br />
      create    test/unit/article_test.rb<br />
      create    test/fixtures/articles.yml<br />
      exists    db/migrate<br />
      create    db/migrate/20090729171105_create_articles.rb<br />
</code></p>
<p>e creiamo la tabella nel db con la migrate:<br />
<code><br />
<strong>C:\ProvaArticolo>rake db:migrate</strong><br />
(in C:/ProvaArticolo)<br />
==  CreateArticles: migrating =================================================<br />
-- create_table(:articles)<br />
   -> 0.0700s<br />
   -> 0 rows<br />
==  CreateArticles: migrated (0.0700s) ========================================<br />
</code></p>
<p>Infine eliminiamo il file index.html da dentro la cartella public e creiamo la route iniziale:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#config\routes.rb</span>
map.<span style="color:#9900CC;">root</span> <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;articles&quot;</span></pre></div></div>

<p>Riavviamo il server e sempre all&#8217;indirizzo http://localhost:3000/ questa volta dovremmo vedere la lista degli articoli.</p>
<p>Se non mi sono dimenticato qualcosa, jruby on rails è pronto, buon divertimento!</p>
]]></content:encoded>
			<wfw:commentRss>http://mastrodonato.info/index.php/2009/07/configurare-un-ambiente-per-jruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
