xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Paul King <king AT asert.com.au>
- To: xom-interest AT lists.ibiblio.org
- 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 gmail.com> 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:
http://hamletdarcy.blogspot.com/2008/12/beginners-guide-to-osgi-on-desktop.html
but I added XOM as a required dependency to the groovy 1.6 provider. Relevant
line in build.gradle was:
"Import-Package":
"org.sample.provider;version=\"1.0.0\",org.w3c.dom,org.osgi.framework;version=\"1.3.0\",nu.xom;version=\"1.2.2.b3\"",
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
.b3,nu.xom.converters;version=1.2.2.b3,nu.xom.xinclude;version=1.2.2.
b3,nu.xom.xslt;version=1.2.2.b3
Import-Package: javax.xml.transform.sax,javax.xml.transform,org.w3c.do
m,org.xml.sax,org.xml.sax.helpers,org.xml.sax.ext,org.apache.xerces.p
arsers;resolution:=optional;version="2.8.0",org.apache.xerces.impl;re
solution:=optional;version="2.8.0",org.apache.xerces.jaxp;resolution:
=optional;version="2.9.0",junit.framework;resolution:=optional;versio
n="3.8.1",com.sun.org.apache.xerces.internal.jaxp;resolution:=optiona
l,com.sun.org.apache.xerces.internal.parsers;resolution:=optional
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.