Thursday, October 6, 2011

Curso de Tecnología Java (Java Technology Course)

Java en Castellano
Aquí les brindo un modesto curso de la Tecnología Java, casi el 100% del contenido esta en español.

Espero que lo disfruten.

Wednesday, October 5, 2011

The apt keys, importing keys in batch mode

Sometimes a fresh Ubuntu or Debian install is mandatory or commanded, but we forget to export all GPG apt keys before the wipe. Once we made the installation we start to add our previously sources lists entries (hope you don't forget to save them first). In my case I use several entries many referencing some useful PPAs on Launchpad, this an excerpt:

deb natty-proposed main restricted universe multiverse
deb natty-security main restricted universe multiverse
deb natty-updates main restricted universe multiverse
deb natty main restricted universe multiverse

deb natty partner
deb natty-backports partner

deb natty main

deb natty main
deb-src natty main

deb natty main 
deb natty main
deb natty main

deb natty main
deb-src natty main

deb natty-cdh3 contrib
deb-src natty-cdh3 contrib

deb natty main
When we run then apt-get update in our fresh install we end with this annoying warning message:

W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used.GPG error: ... Release: The following signatures were invalid: BADSIG 40976EAF437D05B5 Ubuntu Archive Automatic Signing Key <>

W: Failed to fetch ... 
W: Some index files failed to download, they have been ignored, or old ones used instead.

To avoid these warnings you shall to explicit import the public keys (40976EAF437D05B5) via Synaptic Package Manager or apt-key command.

In my case, I keep a file (~/Sandbox/aptkeys/aptkeys) with a list of keys on my profile, one per line. Then, when a /etc/apt/sources.list archive get modified and the command apt-get update emits this kind of warning message, I append this key (40976EAF437D05B5) to the end of the file  ~/Sandbox/aptkeys/aptkeys using a text editor or cat command. Here is an excerpt of my aptkeys file:

The I use this script to make a batch import of all my approved keys:

$  cat ~/Sandbox/aptkeys/aptkeys  | importaptkeys

Hope that it will be useful for you.

Tuesday, October 4, 2011

Various Java VM on my Debian / Ubuntu. What can I do?

The situation
Many of us prefer Sun JVM (Oracle now) for historical or non-historical reasons. Many of us also prefer Debian, Ubuntu and/or even Red Hat. But when we go and install LibreOffice (for example), via apt-get other powerful player arrives: openjdk. I don't want to discuss which JVM implementation is the most "appropriate" for us, you or them. There is a fact, many JVM can and should coexists pacifically.

But the question persists
- After installing various Java-dependant packages on my GNU/Linux OS preferred distribution, and I issue the javac command, which JVM compiler is invoked? 
- How can I set my preferred Java implementation per command basis?

The solution
The Debian alternatives system is devoted to solve the problem of choosing the default preferred implementation of various kinds of programs: text editors, mail agents, JVM, etc.

The options are settled via update-alternatives in a terminal and there is also a graphical version called galternatives.

The Example
This script sets various' Sun JVM (Oracle now) commands as the default alternatives for: java packaging, java VM, java compiler, javadoc, etc. It runs update-alternatives command several times, one per java command.

Composing XML is easy

Sometimes we want to "modularize" some XML archive in some independent parts for a matter of clearness and manageability of simple documents instead of huge ones, lets say XHTML pages, XSLT, XSD, etc.

Many people don't know how to compose, in a generic manner, multiple XML (a no XML also) documents into a big one. It's easier to do, and the answer is XInclude.  Many XInclude examples reflect what I said: Its easy to use!

XInclude It's not a new invention at all, but surprisingly a bunch colleagues of mine don't know about its existence.

Lets stop talking. I going to show you how you can freely merge varios XML (or text) documents into a more complex XML document with XInclude during a XSLT transformation. The example is very straightforward:

- input file: demoxi.html

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="" xmlns:xi="">
  <head>Some title</head>
    <p><xi:include href="license.txt" parse="text"/></p>

- XSLT transformation: identity.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
  <xi:include href="copy_template.xml" parse="xml" />


- a text file to include: license.txt

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation Version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of

See GNU General Public License <>.
- a XML file to include in the XSLT: copy_template.xml

<xsl:template match="*" xmlns:xsl="">
    <xsl:element name="{fn:name(.)}" namespace="{fn:namespace-uri(.)}">
        <!-- copy attributes -->
        <xsl:for-each select="@*">
            <xsl:attribute name="{fn:node-name(.)}" select="." />
        <xsl:apply-templates select="child::node()" />

What's next?

Call an XSLT processor like Saxon in a XInclude aware manner.

$ exec java \
    -classpath saxon.jar \
    -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration \
    net.sf.saxon.Transform \
    -xi:on \

    -s:demoxi.html \

I provide this script to make things more easy. Enjoy it!


Tiny: Extract all dependencies from Maven's POM recursively

A friend recently ask me: how can I extract all artifact dependencies from multiple POM files recursively into a single POM file?

Here is a simple answer using bash, libxml-xpath-perl and tidy.

What users can add?
- more XML processing instead of concatenating.
- extract properties values of non hardcoded dependencies.
- ensure uniqueness of dependencies.