Feeds:
Posts
Comments

Situation: I have a Docbook project that builds in Publican. However the same book also needs to be able to be built by a different team using Maven and jDocbook. How do I make this happen.

1 – You’ll need a Maven POM (pom.xml)

Publican 1.0 currently no longer includes POM creation. The previous generation of Publican, ie 0.45 and earlier, would produce a Maven POM (pom.xml) with the command make pom. Either generate one with a pre-1.0 version of Publican or make a copy of a pre-existing one.

2 – Add the jboss.org Maven repository configuration to the POM
The POM produced by Publican lacks the repository configuration to actually make it work.

EDIT: Apparantly this is because users were being instructed to add this configuration to their ~/.m2/settings.xml.  In my opinion this is counter to the design of Maven.  Projects should be self contained and not rely on local configuration.

The missing sections are:

<repositories>
    <repository>
        <id>repository.jboss.org</id>
        <name>JBoss Repository</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>repository.jboss.org</id>
        <name>JBoss Repository</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

These are the repositories that contain the jDocBook Maven plugins as well as the default JBoss style plugins. Just add this XML to the POM within the scope of the <project> tag, e.g. just before the <build> element.

3 – Make sure the POM matches the book.
If you didn’t use Publican to generate a new POM and are reusing a POM from another project then the <properties> section will probably not match your book and will need to be edited.

<properties>
     <translation>en-US</translation>
     <docname>A_User_Guide</docname>
     <bookname>A User Guide</bookname>
</properties>

<docname> needs to have the same value as the file name (minus the .xml) of the starting XML file of your book, i.e. the one containing the <book> or <article> element.

<bookname> is only used in the <name> element of the <project> … and nothing in this POM makes use of it, so it doesn’t really matter what you put here. I’d set this to whatever the title of the book is.

4 – Add entity declarations to the top of each of your XML files.

Publican enforces some good habits, like having all your entities declared in one file. However entities actually need to be declared in every file that they are referenced from. Publican as a part of it’s “pre-build” process inserts the declarations into each file for you. jDocBook doesn’t do this however so you need to add a reference to your entities file (A_User_Guide.ent) in the header of every XML file that uses those entities. If you don’t do this, the entities will not populate in your book.

<?xml version='1.0'?>
<!DOCTYPE preface PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "A_User_Guide.ent">
%BOOK_ENTITIES;
]>

EDIT: The filename of your entities file is a relative path.  This means that if the entity file is not in the same directory as the XML file that you are editing then you must supply the relative path.  In the example above, if the XML file is in a sub-directory, and the entity file is in the parent directory then you would need to specify the file as “../A_User_Guide.ent”.

Note Publican is smart enough not to duplicate this during its own build process.

4 – Specify both role and language for <programlisting>

In Publican, to make use of language syntax highlighting in <programlisting>, you specify the attribute language with the value of the language that the <programlisting> contains. This is actually the correct behavior according to the Docbook specification.

<programlisting language="xml">

However the underlying highlighting library that jDocBook uses requires that the language be specified with the attribute role.

<programlisting role="XML">

You can simply specifying both attributes so it works in both systems.

<programlisting language="xml" role="XML">

Note that Publican 0.45 requires the value to be lowercase, and jDocBook requires it to be uppercase.

EDIT: For Publican 1.0, the capitalization of the language value needs to match the LANGUAGE column at http://search.cpan.org/~szabgab/Syntax-Highlight-Engine-Kate-0.06/lib/Syntax/Highlight/Engine/Kate.pm#PLUGINS.

That’s the easy stuff. Dealing with Publican’s Common Content is a little trickier. In many cases you can simply supply a Feedback.xml, Conventions.xml and Legal_Notice.xml to satisfy the fallbacks. But that isn’t really a good long term solution for a couple of reasons which I’ll deal with that another time.

Maven will build this book with the command mvn compile. The Publican supplied POM will build html, html-single and PDF versions of the book using the default JBoss documentation styles.

If you do not want to use the default JBoss documentation styles then you will need to create your own jDocBook style Maven plugin. This isn’t terribly difficult but is also a topic for another time.


The installation of Maven can trip some people up. The installation instructions are actually at the bottom of the download page which is not where I would look for them to be honest, I’d go straight for the documentation pages, which don’t seem to have this information. The instructions also assume a fair degree of familiarity with your OS and might be a little vague for a relative beginner.

Your operating system may include Maven by default, or provide installation packages. These are likely to work fine and will generally take care of all the steps mentioned here. Install them if you want. I personally like to try to keep Java applications separated from OS concerns, it just seems right to me to do it that way. Your milage may vary. You also might want to install another copy of a different version to that supplied by your OS vendor and keep the two seperate.

Here’s how to install Maven in your local user account on any unix OS (Linux, MacOS X, Solaris etc). This does not require root privileges. Doing this on a MS Windows operating system is basically the same, you just define the variables in a different place. I may followup with those details at a later date.

1 – Java must be installed.
Maven is a pure Java application and requires at least Java 1.5. See
http://shinysparkly.wordpress.com/2009/10/28/local-java/ for help installing Java.

2 – Download Maven.
Go to http://maven.apache.org, click on Download under Get Maven on the left-hand side of the page towards the top. There are a few different versions listed on the downloads page, the most recent at the top. At time of writing the most recent was 2.2.1. There are compiled and source distributions in several flavors of archive format. For general ease of use I recommend the compiled version in zip format, i.e. apache-maven-2.2.1-bin.zip. Click on the link and it takes you to an apache.org mirror server selection page, pick the first one and the file will start downloading. If there is an error and try one of the other mirrors. Download and save the zip file to your home directory.

3 – Installing Maven
Unzip the zip file. It will create a apache-maven-2.2.1 directory. You can move this directory somewhere else if you wish. On MacOS X I recommend moving it into your ~/Library directory. You can also rename this directory, although I recommend not to, it’s not a bad name as directories go. The following instructions assume that you do not renamed this directory and leave it in your home directory.

4 – Setup your Environment
This step is generally where people get unglued. You need to add two environment variables and append the bin directory from your new Maven install. You can do this by editing your ~/.bash_profile.

You need to add a variable called M2_HOME and give it the value of the directory path to your new Maven installation:

export M2_HOME=/home/username/apache-maven-2.2.1

Then add a M2 variable and point it to the bin directory of the install:

export M2=$M2_HOME/bin

Note how we reuse the M2_HOME variable here. This is handy in case you have to move or otherwise change the Maven directory you only have to update it here once, and not twice.

Then you need to add the M2 directory to the start of your path. Something like:

export PATH=$M2:$PATH

By including M2 at the beginning of your path it ensures that this version of Maven will be the one that is found, even if there other versions installed on your operating system. This is handy if your operating system already has a version of Maven installed that you don’t want to use but can’t remove or don’t want to remove (MacOS X I am looking at you).

You can force the changes to take effect within a single terminal session with the following command but it is recommended to logout and back in again.

[localhost]$ source ~/.bash_profile

And that’s it.

5 – Verify the Changes

To verify that the changes have been correctly done, open a terminal and run the following commands:

echo $M2_HOME
This should display the directory where you installed Maven

[localhost]$ echo $M2_HOME
/home/username/apache-maven-2.2.1

echo $M2
This should should the bin directory of your Maven install.

[localhost]$ echo $M2
/home/username/apache-maven-2.2.1/bin

echo $PATH
This should display the comma separated list of directories where the shell will search for commands. It should have the bin directory of your Maven install at the beginning.

[localhost]$ echo $PATH
/home/username/apache-maven-2.2.1/bin:/home/username/jdk1.6.0_16/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin

which mvn
This should display the complete path to the Maven executable, mvn, which should be in the bin directory of your Maven install.

[localhost]$ which mvn
/home/username/apache-maven-2.2.1/bin/mvn

mvn –version
This should display the version from Maven, and related Java and operating system information.

[localhost]$ echo mvn –version
Maven version: 2.2.1
Java version: 1.6.0_16
OS name: “mac os x” version: “10.6.1″ arch: “x86_64″ Family: “mac”

And that’s it. There are no plugins or repositories to configure. That’s the beauty of Maven. All of that stuff can and should be configured in the POM (pom.xml) file for the project that requires it, and Maven takes care of retrieving and installing the plugins that it needs when it needs them.

There are a few cases where you would want to add some local configuration. This would generally go in your ~/.m2_conf/settings.xml. This is useful for configuration items that are specific to you or that you need to secure and not distribute. An example of this might be username and password configuration for a plugin used to access secured resources, such as uploading builds to a server.


By default you can’t install the Virtual Box Guest Additions on a Fedora 11 guest. This means no shared folders, no dynamic resolution changing on resize, terrible video performance and no mouse pointer integration.

To install the guest additions you need a few extra packages to be installed:

yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel

If you have more than one kernel installed, remove the old ones or the installer will become confused and not work.

To get a list of the installed kernel packages:

[localhost home]$ rpm -qa | grep -i kernel
kernel-2.6.30.8-64.fc11.i586
kernel-2.6.29.4-167.fc11.i586
kernel-headers-2.6.30.8-64.fc11.i586
kernel-headers-2.6.29.4-167.fc11.i586
kernel-devel-2.6.30.8-64.fc11.i586
kerneloops-0.12-5.fc11.i586
kernel-firmware-2.6.30.8-64.fc11.noarch

Kernel updates do not replace the existing kernel, they add a new one. This is in case there is a problem you can still boot from the earlier kernel. Unless you need the old kernel for some reason then it is safe to remove the old packages:

yum remove kernel-2.6.29.4-167.fc11.i586 kernel-headers-2.6.29.4-167.fc11.i586

Now go to the Virtual Box Devices menu, and select Install Guest Additions…

A cdrom device will mount, and (on GNOME anyway) a dialog will prompt you to automatically run the contents of the disc. Select No, the auto-run script that will run from the disc assumes that gksu is installed, it isn’t and doesn’t appear to be in the Fedora repository. However you can simply open a terminal, cd to the disc and run the installer yourself. You do need to do this as the root user.

[localhost home]$ su -
Password:
[localhost root]$ cd /media/VBOXADDITIONS_3.0.8_53138/
[localhost VBOXADDITIONS_3.0.8_53138]$ ./VBoxLinuxAdditions-x86.run
Verifying archive integrity… All good.
Uncompressing VirtualBox 3.0.8 Guest Additions for Linux installation……………………………………………………………………………………………………………………………………………………………………………………………………..
VirtualBox 3.0.8 Guest Additions installation
Building the VirtualBox Guest Additions kernel module…
Building the shared folder support kernel module…
Building the drm support kernel module…
Installing the VirtualBox Guest Additions…
Successfully installed the VirtualBox Guest Additions.
You must restart your guest system in order to complete the installation.
[localhost VBOXADDITIONS_3.0.8_53138]$

Upon reboot Virtual Box will report that the guest OS Supports mouse pointer integration. You will also find that resizing the Virtual Box window will cause the X11 screen resolution to change to match.

Unfortunately if a kernel update occurs, this will stop working & you will have to repeat these steps with the new kernel.

Almost every Maven or JBoss on Fedora problem which I’ve seen people stuck on in the past 6 months has actually been a messed up Java installation.

I suspect that this is probably being caused by multiple Java packages and the resulting confused configuration of alternatives, but I don’t know enough about alternatives to be really certain, let alone fix it.

What I advise to get people back to work quickly, is to set up a Java installation within their user account and setup their profile so the system java configuration is completely bypassed. And behold their problems magically go away. Or it is still broken and we now definitely know that it isn’t a Java issue.

This works on any Linux, not just Fedora, only affects your own user account and does not require root privileges.

1 – Download the JDK from sun.com
You can download Sun’s JDK from http://java.sun.com/javase/downloads/index.jsp

At time of writing the most recent version is JDK 6 Update 16. You don’t need to download one of the Bundles, they include additional developer tools.

The Linux version has two downloads, one named something like jdk-6u16-linux-i586.bin, and the other one jdk-6u16-linux-i586-rpm.bin. You want the first one, not the ‘rpm’ one.

Don’t worry about the Sun Download Manager, just click on the file link and it will being downloading immediately. Save this file in your home directory.

2 – Install the JDK
The .bin file is a “self-extracting archive”, an archive file with a script tacked onto the front. When run the script will unpack the archived contents.

Add execute permissions to the file, and then run it.

[localhost]$ chmod +x jdk-6u16-linux-i586.bin
[localhost]$ ./jdk-6u16-linux-i586.bin

Keep pressing spacebar to page through the license until you are prompted to agree with the license, type yes and press enter. The script will create a directory, jdk1.6.0_16, and unpack all the JDK files into it. Once this is complete it will prompt you to “press enter to continue” and the script is finished. The last thing the script does is open your browser with the JDK registration page. You can ignore this and close it.

This newly created directory contains all the files of the JDK. If you ran the installer in a place where you don’t want the JDK to live, like your desktop or downloads folder then you can simply move the JDK folder to where you want it to live in your home directory. You can also rename it if you wish. The rest of these instructions assume you haven’t renamed it and have put it in your home directory.

3 – Edit your .bashrc file
You need to make two changes to your ~/.bashrc file. You must add the JAVA_HOME variable, and you must add the path to the JDK binaries to the front of your existing PATH variable. Add the following two lines to the end of your .bashrc.

export JAVA_HOME=~/jdk1.6.0_16

export PATH=$JAVA_HOME/bin:$PATH

If there are other changes made to PATH in this file you need to include these new lines after those.

The bin directory in your Java installation contains all the executables including the virtual machine (java) and the compiler (javac). By appending this directory to the beginning your PATH variable it ensures that these files are found before the system ones.

You can force the changes to take effect within a single terminal session with the following command but it is recommended to logout and back in again.

[localhost]$ source ~/.bashrc

4 – Verify Changes

To verify that the changes have been correctly done, open a terminal and run the following commands:

echo $JAVA_HOME
This should display the directory when you put the JDK.

[localhost]$ echo $JAVA_HOME
/home/username/jdk1.6.0_16

echo $PATH
This should display the comma separated list of directories where the shell will search for commands. It should have the bin directory of your JDK install at the beginning.

[localhost]$ echo $PATH

/home/username/jdk1.6.0_16/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin

which java
This should display the complete path to the java binary of the JDK installation in your home directory.

[localhost]$ which java
/home/username/jdk1.6.0_16/bin/java

Now the JDK is installed locally and your user account is configured to use it.

If this doesn’t solve your problem (and it is set up correctly) …. then a misconfigured Java installation probably wasn’t the problem. :-)



Older Posts »