Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Problem with XOM 122b3

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Paul King <king AT>
  • To: xom-interest AT
  • Subject: Re: [XOM-interest] Problem with XOM 122b3
  • Date: Thu, 04 Jun 2009 20:08:29 +1000

Elliotte Harold wrote:
On Thu, May 28, 2009 at 2:36 PM, Alex Blewitt <alex.blewitt AT> wrote:

That's interesting; it's not usually the case that people ship tests in
their man Jar/bundle. But that aside, this is actually a pretty big problem
for OSGi. There's a number of ways of handling it:

I'm not shipping tests. I'm shipping a utility class for making tests.

* Make the OSGi import ;resolution:=optional. This will allow the OSGi
bundle to be used when JUnit isn't present. If it is available, it will wire
itself up and you'll be able to use XOMTestCase. If it's not present, the
bundle will still start, but you'll not be able to use the XOMTestCase. This
is the direct equivalent of what you have at the moment outside the OSGi
space. I use this myself for unit tests inside a bundle that I don't want to
ship with the main bundle but still want to be able to compile/run them
locally in my IDE.

So if you call it you get a NoClassDefFoundError? Sounds a bit scary to me.

I ran up XOM with Groovy and after making some changes it now seems to work.
The changes were mostly the same as what David suggested but not quite - I
wish I had come back and read his email before playing today. After the
changes, everything seems to work. I followed the steps in this tutorial:

but I added XOM as a required dependency to the groovy 1.6 provider. Relevant
line in build.gradle was:

then built it using gradle as per the instructions on the page.

I manually tweaked the Manifest along lines similar to what David has
previously described in an earlier email:

* add missing ,
* add missing :
* I made junit optional as this seemed to make the most sense
(seems crazy to mandate junit for normal users who are not using
XOMTestCase and optional will mean that it is wired up if junit
is there - though the real solution would be to split XOMTestCase
out into a separate nu.xom.test bundle and mandate junit for that)
* for some reason, using the eclipse osgi runner I also had to put
version numbers on the Export-Package metadata but perhaps I was
doing something wrong - don't claim to be an expert on all aspects
of OSGi and didn't want to invest any more time

So, here is what I ended up using in the Manifest:

Export-Package: nu.xom;version=1.2.2.b3,nu.xom.canonical;version=1.2.2
Import-Package: javax.xml.transform.sax,javax.xml.transform,

After that, you start the bundles as per the instructions in the
tutorial and you have a console. Type this into the console:

import nu.xom.*
def root = new Element('greeting')
def document = new Document(root)
root.appendChild('Hello, from XOM') document.toXML()

Make sure you have Groovy 1.6 selected. Hit 'Evaluate'.
You should see this in the Results pane:

<?xml version="1.0"?>
<greeting>Hello, from XOM</greeting>

Just a short note on the version number issue for exports.
Prior to adding in the version info on the exports, the osgi
console was reporting this:

Exported packages
nu.xom; version="0.0.0"[exported]
nu.xom.canonical; version="0.0.0"[exported]
nu.xom.converters; version="0.0.0"[exported]
nu.xom.xinclude; version="0.0.0"[exported]
nu.xom.xslt; version="0.0.0"[exported]

and when attempting to start the bundle that required these
packages it said:

org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing
Constraint: Import-Package: nu.xom; version="1.2.2.b3"

after adding version numbers in, the console debug/status info was:

Exported packages
nu.xom; version="1.2.2.b3"[exported]
nu.xom.canonical; version="1.2.2.b3"[exported]
nu.xom.converters; version="1.2.2.b3"[exported]
nu.xom.xinclude; version="1.2.2.b3"[exported]
nu.xom.xslt; version="1.2.2.b3"[exported]

and resolution was successful.

Cheers, Paul.
P.S. If you want to try this at home, I couldn't get it to work with
Gradle 0.6.1 so reverted to 0.5.2 and it seemed happy.

  • Re: [XOM-interest] Problem with XOM 122b3, Paul King, 06/04/2009

Archive powered by MHonArc 2.6.24.

Top of Page