<?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>/home/totex</title>
	<atom:link href="http://www.totex.cl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.totex.cl</link>
	<description>@TODO: inventar frase ingeniosa</description>
	<lastBuildDate>Mon, 26 Jul 2010 04:17:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ServiceMix 4.2 en Tomcat6</title>
		<link>http://www.totex.cl/2010/07/26/servicemix-4-en-tomcat6/</link>
		<comments>http://www.totex.cl/2010/07/26/servicemix-4-en-tomcat6/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 04:03:37 +0000</pubDate>
		<dc:creator>Jorge Riquelme</dc:creator>
				<category><![CDATA[Desarrollo de Software]]></category>
		<category><![CDATA[karaf]]></category>
		<category><![CDATA[servicemix]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.totex.cl/?p=125</guid>
		<description><![CDATA[Este fin de semana estuve “destripando” ServiceMix, específicamente la distribución 4.2.0-fuse-02-00 de Fuse. El objetivo era generar un war desplegable en Tomcat6, ya que la versión de Fuse sólo viene como aplicación standalone. Al final fue no fue tan complicado, porque hay un ejemplo que facilita enormemente la tarea. Al grano Para ejecutivos de tiempo [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-126 alignleft" title="jw-1212-esb2" src="http://www.totex.cl/wp-content/uploads/2010/07/jw-1212-esb2-300x200.jpg" alt="ServiceMix" width="180" height="120" /></p>
<p style="text-align: justify;">Este fin de semana estuve “destripando” <a href="http://servicemix.apache.org" target="_blank">ServiceMix</a>, específicamente la distribución <strong>4.2.0-fuse-02-00</strong> de <a href="http://www.fusesource.com" target="_blank">Fuse</a>. El objetivo era generar un war desplegable en <a href="http://tomcat.apache.org" target="_blank">Tomcat6</a>, ya que la versión de Fuse sólo viene como aplicación standalone.</p>
<p style="text-align: justify;">Al final fue no fue tan complicado, porque hay un ejemplo que facilita enormemente la tarea.</p>
<p style="text-align: justify;">
<h1>Al grano</h1>
<p style="text-align: justify;">
<p style="text-align: justify;">Para ejecutivos de tiempo escaso, estos son los pasos a seguir.</p>
<p style="text-align: justify;">Supuestos:</p>
<ul>
<li>Linux, distribución <a href="http://releases.ubuntu.com/karmic/" target="_blank">Ubuntu Karmic</a> x86_64.</li>
<li>Tomcat6 instalado vía apt (relevante, porque determina rutas, permisos y usuario tomcat6).</li>
<li>estar conectado a internet (se bajarán componentes en la instalación).</li>
</ul>
<p style="text-align: justify;">Pasos:</p>
<ul>
<li>Baja el war <a href="http://www.totex.cl/wp-content/uploads/2010/07/karaf-smx-1.4.0-fuse-02-00.war">karaf-smx-1.4.0-fuse-02-00.war</a></li>
<li>Como root, crea el directorio .karaf en el home de tomcat6: <em>mkdir /usr/share/tomcat6/.karaf</em></li>
<li>Cambia el owner de .karaf a tomcat6: <em>chown tomcat6:tomcat6 /usr/share/tomcat6/.karaf</em></li>
<li>Crea un link a etc en el directorio de trabajo de tomcat: <em>ln -sf /var/lib/tomcat6/webapps/karaf-smx/WEB-INF/karaf/etc /var/lib/tomcat6/etc</em></li>
<li>Despliega el war: <em>cp /path/to/karaf-smx-1.4.0-fuse-02-00.war /var/lib/tomcat6/webapps/karaf-smx.war</em></li>
</ul>
<p style="text-align: justify;">Ahora deberás esperar un buen rato, porque <a href="http://karaf.apache.org" target="_blank">Karaf</a> empezará a bajar e instalar los bundles de ServiceMix. Puedes ir vigilando lo que pasa en el log:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ tail -f /var/lib/tomcat6/webapps/karaf-smx/WEB-INF/karaf/data/log/servicemix.log</pre></div></div>

<p style="text-align: justify;">Para verificar que todo está listo, abre una consola (el password es smx):</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ ssh -p 8101 -l smx localhost</pre></div></div>

<p style="text-align: justify;">Ejecuta el comando list, para ver los bundles instalados:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">smx@root&gt; list
START LEVEL 100
   ID   State         Blueprint      Spring    Level  Name
[   0] [Active     ] [            ] [       ] [    0] OSGi System Bundle (3.5.1.R35x_v20090827)
[   1] [Active     ] [            ] [       ] [    5] OPS4J Pax Url - mvn: (1.1.2)
[   2] [Active     ] [            ] [       ] [    5] OPS4J Pax Url - wrap: (1.1.2)
...
[ 173] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: commons-io-1.3.2 (1.3.2.3)
[ 174] [Active     ] [            ] [       ] [   60] camel-cxf (2.2.0.fuse-02-00)
[ 175] [Active     ] [            ] [       ] [   60] camel-jms (2.2.0.fuse-02-00)
smx@root&gt;</pre></div></div>

<p style="text-align: justify;">Cuando sean 175 debería esta todo listo para la acción <img src='http://www.totex.cl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p style="text-align: justify;"><span id="more-125"></span></p>
<p style="text-align: justify;">
<h1>Explicación</h1>
<p style="text-align: justify;">
<p style="text-align: justify;">El war de arriba es una versión modificada del proyecto web, ubicado en <em>examples/karaf-demos</em>. El código fuente lo puedes bajar desde <a href="http://www.totex.cl/wp-content/uploads/2010/07/karaf-smx-4.2.0-fuse-02-00.tar.gz">karaf-smx-4.2.0-fuse-02-00.tar.gz</a>. Los cambios realizados son:</p>
<ul>
<li>El parent es directamente <em>org.apache.felix.karaf:karaf:1.4.0-fuse-02-00</em>.</li>
<li>Las coordenadas del proyecto son <em>org.apache.felix.karaf:karaf-smx:1.4.0-fuse-02-00:war</em>.</li>
<li>El directorio <em>etc</em> de <strong>apache-felix-karaf</strong> fue reemplazado por los archivos de la distribución de Fuse, así no hay que agregar a mano el repositorio de Fuse, los features de ServiceMix, bundles, etc.</li>
<li>El listener <em>org.apache.felix.karaf.web.WebAppListener</em> fue modificado para:
<ul>
<li>verificar la existencia del link <em>etc</em> en el directorio de trabajo del usuario tomcat6.</li>
<li>verificar la existencia del directorio <em>.karaf</em> (y sus permisos) en el home del usuario tomcat6.</li>
<li>asignar a storage.location el directorio <em>.karaf</em> del home del usuario tomcat6.</li>
</ul>
</li>
</ul>
<h2>Karaf</h2>
<p style="text-align: justify;"><strong>Karaf</strong> es un contenedor liviano que corre sobre una plataforma <strong>OSGI</strong> –<a href="http://felix.apache.org" target="_blank">Felix</a> o <a href="http://www.eclipse.org/equinox" target="_blank">Equinox</a>- y provee un conjunto de servicios, como logging, hot deploy, configuración dinámica, etc. Karaf actúa como kernel de ServiceMix, por lo que para poder ejecutar ServiceMix en Tomcat (o cualquier otro contenedor) basta lograr ejecutar Karaf en dicho ambiente y luego desplegar los bundles de ServiceMix.</p>
<h2>Ubuntu</h2>
<p style="text-align: justify;">Ubuntu da problemas para el demo web debido a su esquema de permisos. Cuando uno accede a la shell de Karaf vía SSH, se crea en el home del usuario que corre el proceso Karaf (en este caso tomcat6) el archivo <em>.karaf/karaf.history</em>. Como en Ubuntu el home del usuario tomcat6 es <em>/usr/share/tomcat6</em>, que no tiene permisos de escritura para tomcat6, ocurre una excepción cuando Karaf trata de crear el archivo. Por eso se debe crear a mano <em>/usr/share/tomcat6/.karaf</em> y asignarle permisos de escritura a tomcat6.</p>
<h2>Bundle activemq-broker</h2>
<p style="text-align: justify;">Otro problema, esta vez relacionado a ServiceMix, es que bundle activemq-broker trata de leer el archivo <em>etc/activemq-broker.xml</em> desde el directorio de trabajo. Esto es “poco amistoso” con un esquema de despliegue web, donde los archivos de la aplicación no se encuentran en el directorio de trabajo. La solución “parche” es crear el link <em>/var/lib/tomcat6/etc</em> a <em>/var/lib/tomcat6/webapps/karaf-smx/WEB-INF/karaf/etc</em>, así el bundle activemq-broker pordrá encontrar <em>etc/ activemq-broker.xml</em>.</p>
<p style="text-align: justify;">
<h1>Conclusiones</h1>
<p style="text-align: justify;">
<p style="text-align: justify;">No es complicado desplegar Karaf 1.4, y sobre él ServiceMix 4.2, en Tomcat. Sin embarago, por los detalles expuestos en este post, es notorio que las cosas están hechas para funcionar en forma standalone.</p>
<p style="text-align: justify;">Hace poco (23/07) se liberó <strong>Karaf 2.0.0</strong>, que define nuevas variables de entorno que permiten distribuir diferentes partes de karaf en el sistema de archivos. Esto permitiría, por ejemplo, dejar la configuración en /etc, los datos en /var, y en el war sólo los binarios.</p>
<p style="text-align: justify;">Otra cosa destacable es que ServiceMix “es sólo” un conjunto de bundles sobre Karaf. Además, hay esfuerzos en Karaf para apoyar la generación de distribuciones personalizadas, lo que es atractivo, pues se podría lograr un runtime “a medida”, con los bunldes justos (y evitar así los 170 y tanto que trae ServiceMix).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totex.cl/2010/07/26/servicemix-4-en-tomcat6/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Jar ejecutable con Maven</title>
		<link>http://www.totex.cl/2010/06/23/jar-ejecutable-con-maven/</link>
		<comments>http://www.totex.cl/2010/06/23/jar-ejecutable-con-maven/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 03:04:26 +0000</pubDate>
		<dc:creator>Jorge Riquelme</dc:creator>
				<category><![CDATA[Desarrollo de Software]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.totex.cl/?p=76</guid>
		<description><![CDATA[Una pregunta común que hacen usuarios nuevos de Maven es cómo crear un jar ejecutable. Generalmente las soluciones propuestas van en la línea de generar un sólo jar gigante &#8211;con todas las dependencias dentro&#8211; utilizando algo como uberjar, fatjar o el descriptor jar-with-dependencies de maven-assembly-plugin. Esto, en mi opinión, es inconveniente y poco estético, por [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><img class="alignright size-full wp-image-87" title="maven" src="http://www.totex.cl/wp-content/uploads/2010/06/maven.jpg" alt="" width="182" height="100" />Una pregunta común que hacen usuarios nuevos de <a href="http://maven.apache.org" target="_blank">Maven</a> es cómo crear un jar ejecutable. Generalmente las soluciones propuestas van en la línea de generar un sólo jar gigante &#8211;con todas las dependencias dentro&#8211; utilizando algo como uberjar, fatjar o el descriptor jar-with-dependencies de <a href="http://maven.apache.org/plugins/maven-assembly-plugin" target="_blank">maven-assembly-plugin</a>. Esto, en mi opinión, es inconveniente y poco estético, por varias razones:</p>
<ul>
<li style="text-align: justify;">El jar resultante es una sopa de artefactos, ya que se mezclan todas las dependencias directas y transitivas con la aplicación misma.</li>
<li style="text-align: justify;">No escala; para proyectos con muchas dependencias, el proceso de formar el “super jar” es lento, por lo que no es una opción viable para utilizar en tiempo de desarrollo (sólo al hacer un release).</li>
<li style="text-align: justify;">Pueden haber problemas de licencia. Algunas dependencias pueden exigir que se mantenga la integridad de los binarios que distribuyen, prohibiendo “reempaques”.</li>
</ul>
<p style="text-align: justify;">Los requerimientos que deseo satisfacer son bastante simples:</p>
<ol>
<li style="text-align: justify;">Generar un jar con el manifiesto necesario; esto es, que indique la clase con el punto de entrada main y las dependencias.</li>
<li style="text-align: justify;">Poder obtener todos los jars de las dependencias, directas y transitivas, en un directorio de salida aparte (<strong>lib</strong>, por ejemplo).</li>
<li style="text-align: justify;">Generar un pequeño script bash, que lance el jar con el classpath configurado.</li>
<li style="text-align: justify;">Obtener una distribución de la aplicación, o sea, copiar todo lo anterior en un directorio del sistema (o en target).</li>
<li style="text-align: justify;">Debe ser <strong>rápido</strong>!, ya que será ejecutado recurrentemente, en tiempo de desarrollo.</li>
</ol>
<p style="text-align: justify;">En algún momento del pasado lejano llegué a una configuración que satisface los objetivos listados, consistente en una combinación de <a href="http://maven.apache.org/plugins/maven-jar-plugin" target="_blank">maven-jar-plugin</a>, <a href="http://maven.apache.org/plugins/maven-dependency-plugin" target="_blank">maven-dependency-plugin</a> y <a href="http://maven.apache.org/plugins/maven-resources-plugin" target="_blank">maven-resources-plugin</a>.<span id="more-76"></span></p>
<h2>La aplicación</h2>
<p style="text-align: justify;">La sofisticada aplicación de ejemplo es un “hola mundo” camuflado:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">cl.totex.demo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.LoggerFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Demo
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>Demo.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;holo {}&quot;</span>, args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;duh!&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></td></tr></table></div>

<h2>El POM</h2>
<p style="text-align: justify;">Aparte de toda la información usual de un POM, uso la propiedad <strong>install-dir</strong>, que indicará a Maven el directorio de instalación de la aplicación.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;install-dir<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${build.directory}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/install-dir<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">Las únicas dependencias son las correspondientes al logger, <strong>slf4j</strong>. Por simplicidad, el binding elegido es SimpleLogger <img src='http://www.totex.cl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ; por lo tanto, las dependencias necesarias en el POM son:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td 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.slf4j<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>slf4j-api<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>1.6.0<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.slf4j<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>slf4j-simple<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>1.6.0<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></td></tr></table></div>

<p style="text-align: justify;">El requerimiento 1 se puede  solucionar con plugin <strong>maven-jar-plugin</strong>, que permite generar un jar con un manifiesto donde queda establecida la clase con el punto de entrada main y el classpath.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<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>maven-jar-plugin<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.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;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cl.totex.demo.Demo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mainClass<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;addClasspath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/addClasspath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpathPrefix<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>lib<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/classpathPrefix<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/archive<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">Para el segundo requerimiento se puede usar el plugin <strong>maven-dependency-plugin</strong>, que permite copiar las dependencias directas y transitivas al directorio lib. El plugin sólo copiará los jars faltantes, por lo que la ejecución de la fase install no se ralentiza.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<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>maven-dependency-plugin<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<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;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<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>copy-dependencies<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;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>install<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>copy-dependencies<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outputDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${install-dir}/${artifactId}/lib<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outputDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;overWriteReleases<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/overWriteReleases<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;overWriteSnapshots<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/overWriteSnapshots<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;overWriteIfNewer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/overWriteIfNewer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">El plugin <strong>maven-resources-plugin</strong> permite satisfacer los últimos dos requerimientos: generar un script de lanzamiento y copiar el jar de la aplicación al directorio install-dir.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<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>maven-resources-plugin<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.4.3<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;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<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>copy-jar<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;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>install<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>copy-resources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outputDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${install-dir}/${artifactId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outputDirectory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${build.directory}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
							<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${build.finalName}.jar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${project.basedir}/src/main/resources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
						<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p style="text-align: justify;">La opción filtering, le indica a Maven que debe filtrar es el script run.sh, esto es, reemplazar todas las propiedades que encuentra. El código original de run.sh es:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
java <span style="color: #660033;">-cp</span> <span style="color: #800000;">${install-dir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${artifactId}</span><span style="color: #000000; font-weight: bold;">/</span>lib\
 <span style="color: #660033;">-jar</span> <span style="color: #800000;">${install-dir}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${artifactId}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${build.finalName}</span>.jar <span style="color: #007800;">$*</span></pre></td></tr></table></div>

<p style="text-align: justify;">Al filtrar el script anterior, se reemplazan los placeholders <strong>${install-dir}</strong>, <strong>${artifactId}</strong> y <strong>${build.finalName}</strong> por sus valores reales.</p>
<h2>Instalación</h2>
<p style="text-align: justify;">Por ejemplo, al ejecutar <strong>mvn -Dinstall-dir=/home/totex install</strong><em> se crea el directorio <em>/home/totex/demo</em>, con el siguiente contenido:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tree</span> <span style="color: #660033;">-f</span>
.
<span style="color: #000000; font-weight: bold;">|</span>-- .<span style="color: #000000; font-weight: bold;">/</span>demo-<span style="color: #000000;">1.0</span>-SNAPSHOT.jar
<span style="color: #000000; font-weight: bold;">|</span>-- .<span style="color: #000000; font-weight: bold;">/</span>lib
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">|</span>-- .<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>slf4j-api-1.6.0.jar
<span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000; font-weight: bold;">`</span>-- .<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>slf4j-simple-1.6.0.jar
<span style="color: #000000; font-weight: bold;">`</span>-- .<span style="color: #000000; font-weight: bold;">/</span>run.sh
&nbsp;
<span style="color: #000000;">1</span> directory, <span style="color: #000000;">4</span> files</pre></td></tr></table></div>

<p style="text-align: justify;">El script run.sh resultante es:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
java <span style="color: #660033;">-cp</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>totex<span style="color: #000000; font-weight: bold;">/</span>demo<span style="color: #000000; font-weight: bold;">/</span>lib\
 <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>totex<span style="color: #000000; font-weight: bold;">/</span>demo<span style="color: #000000; font-weight: bold;">/</span>demo-<span style="color: #000000;">1.0</span>-SNAPSHOT.jar <span style="color: #007800;">$*</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<p style="text-align: justify;">La mayor ventaja de este mecanismo, es que se puede ir trabajando en el proyecto y probando la instalación al mismo tiempo, ya que el proceso es rápido.</p>
<p style="text-align: justify;">Puedes bajar el archivo <a href='http://www.totex.cl/wp-content/uploads/2010/06/demo.tar.gz'>demo.tar.gz</a>, que contiene el proyecto de ejemplo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totex.cl/2010/06/23/jar-ejecutable-con-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cha chaaan!</title>
		<link>http://www.totex.cl/2010/04/14/cha-chaaan/</link>
		<comments>http://www.totex.cl/2010/04/14/cha-chaaan/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 19:36:47 +0000</pubDate>
		<dc:creator>Jorge Riquelme</dc:creator>
				<category><![CDATA[Cotidianidad]]></category>

		<guid isPermaLink="false">http://localhost/~totex/wordpress/?p=3</guid>
		<description><![CDATA[Para alegría de la internecz , he vuelto! (dejavú) . Claramente no tengo alma de bloguero, es cosa de ver haber visto las espaciadas fechas entre mis post cero-aporte. No es que la pereza me consuma o que no tenga nada que decir, si no que simplemente, hace rato, “no estoy ni ahí loco”. Desde [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><img class="alignleft size-full wp-image-45" title="chachan" src="http://www.totex.cl/wp-content/uploads/2010/04/chachan.png" alt="" width="250" height="159" />Para alegría de la internecz , he vuelto! (dejavú) <img src='http://www.totex.cl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . Claramente no tengo alma de bloguero, es cosa de <del datetime="2010-04-14T23:19:17+00:00">ver</del> haber visto las espaciadas fechas entre mis post cero-aporte. No es que la pereza me consuma o que no tenga nada que decir, si no que simplemente, hace rato, “no estoy ni ahí loco”. Desde hace un par de primaveras he estado más concentrado en mis propios afanes, que se reducen a la lectura y al perfeccionamiento de mis habilidades ninja en el área del desarrollo de software (y de forma marginal, a cosas más mundanas que no vale la pena mencionar). Digamos que, con los años, el espíritu voyerista de mi adolescencia se ha ido extinguiendo, y exteriorizar mis intimidades ha perdido todo el brillo que alguna vez tuvo. De hecho, releyendo vieeeeeeeejos post no he podido dejar de sentir un poco de vergüenza con algunos. Reflexionando al respecto, no puedo concluir otra cosa que, la culpable de mi arrebato de pudor, típico de vieja polleruda, es ni más ni menos que la adultez!. Si señores, los años no pasan en vano, y aunque las series de animé sigan estando en mi lista de descargas, cosas como ahorrar para un departamento y el que tu mamá hable de nietos es sintomático de que ya ha pasado harta agua bajo el puente.<span id="more-3"></span></p>
<p style="text-align: justify;">Y qué hace uno cuando quiere dar borrón y cuenta nueva a un blog?; obvio, cambia de tecnología y esgrime problemas de incompatibilidad para hacer desaparecer toda la mugre <img src='http://www.totex.cl/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> . Está bien, nada “desaparece” de la internerds, pero al menos no es tan visible. Así que, adiós <a href="http://www.joomla.org" target="_blank">Joomla</a> y bienvenido <a href="http://www.wordpress.org" target="_blank">WordPress</a>, lo que me quita de encima “el cacho” que es armar un mecanismo decente de tags y comentarios en Joomla (nunca he logrado entender por qué los desarrolladores de joomla no hacen un “buen” pack de plugins que permitan llevar un blog, caso de uso taaaaaaaan común). En la misma línea, he llegado a la conclusión de que mis intereses no tienen nada que ver con compilar el kernel, así que “good bye <a href="http://www.gentoo.org" target="_blank">Gentoo</a>” y “holi <a href="http://www.ubuntu.com" target="_blank">Ubuntu</a>” (si he de leer manuales extensos, serán de algo relacionado a mis áreas de interés, no de mi sistema operativo, que se supone hace mi vida más fácil).</p>
<p style="text-align: justify;">Bueno, y ahora que soy un hombre maduro, sensato, para qué un blog?. Varias razones. Primero, por nostalgia, ya que este sitio ha sido un lugar de expresión durante años para mi. Además, todo computín que se precie debe tener su cubil digital, donde poner un par de howtos y reflexiones filosóficas acerca de tecnología. También, porque es bueno ser un hombre consciente de su espacio tiempo, crítico de la sociedad en que vive, por lo tanto, <del datetime="2010-04-14T23:19:17+00:00">envalentonado por el anonimato a medias que brinda la interneds, he de usar este medio digital para tirar mierda con ventilador impúnemente</del> espero de vez en cuando aportar con un chamullo constructivo.</p>
<p style="text-align: justify;">Hasta el próximo año, cuando postee alguna otra cosa <img src='http://www.totex.cl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p style="text-align: justify;">PD: Igual &#8220;importaré&#8221; uno que otro post de los viejos, algún dia, cuando tenga tiempo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.totex.cl/2010/04/14/cha-chaaan/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
