Project

Profile

Help

Saxon-EE license and OSGI environment

Added by Allen Bagwell over 9 years ago

We've been attempting to deploy Saxon-EE into an OSGI container without success.

I've followed advice here using the bnd tool to include OSGI manifest headers in the Saxon-EE (v9.6.0.4) jar: http://sourceforge.net/p/saxon/mailman/message/29737564/

This appears to work well given that now Apache Karaf detects up and recognizes Saxon-EE properly.

I have also used instructions from this post to set the location of the license file with the FeatureKeys.LICENSE_FILE_LOCATION parameter via an environment variable when I set up configuration in my class constructor: http://saxon-xslt-and-xquery-processor.13853.n7.nabble.com/SAXON-EE-on-Servicemix-td8807.html

The weird thing is that I needed the LICENSE_FILE_LOCATION because I got this error without it:

Caused by: net.sf.saxon.trans.LicenseException: License file saxon-license.lic not found. Tried in file:/C:/Users/Allen/Documents/jboss-fuse/deploy/saxon-license.lic, and classpath. A license is needed to use schema processing
 at com.saxonica.config.EnterpriseConfiguration.checkLicensedFeature(EnterpriseConfiguration.java:263)

The twist is that I tried to fix this by copying the saxon-license.lic into the in C:/Users/Allen/Documents/jboss-fuse/deploy/ but it still throws exactly the same error. Is it a known issue that sometimes the jar file can't find the license file even through it's in the same directory? I can't imagine why simply changing the manifest headers causes this error to occur, but strange things happen in the world of OSGI sometimes.


Replies (2)

RE: Saxon-EE license and OSGI environment - Added by Michael Kay over 9 years ago

Is it a known issue that sometimes the jar file can't find the license file even through it's in the same directory?

Answer: yes. The logic Saxon uses is this:

            CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
            if (codeSource != null) {
                URL sourceLoc = codeSource.getLocation();
                if (sourceLoc != null) {
                    URL licenseLoc = new URL(sourceLoc, LICENSE_FILE_NAME);

and to be honest, it works in some environments and not in others, and I don't really understand enough about protection domains and the like to know the details. I know that it's related to code signing, so it wouldn't surprise me if changing the manifest headers upsets things too.

Let us know how you get on with OSGi. It's been on our "TODO" list for years, but I've never seen a clear explanation of what we need to do to enable it, what exactly we can achieve once it's done, and how we test that we have got it right when we have done so.

RE: Saxon-EE license and OSGI environment - Added by Allen Bagwell over 9 years ago

I did manage to get it running as an OSGi bundle in Karaf. (Karaf by the way is a standalone OSGi container but is used in both ServiceMix and JBoss Fuse, so applies there as well.) Normally Karaf will genereate OSGi metadata when you drop a jar file in, but in this case the metadata for Saxon-EE needed guidance, so we used the bnd tool. This properties file when fed to bnd.jar at least works even if it's not entirely locked down:

version=9.6.0.4
Bundle-Name: Saxon-EE
Bundle-SymbolicName: saxon-ee
Bundle-Version: ${version}
Import-Package: com.ibm.icu.*;resolution:=optional,org.dom4j.*;resolution:=optional,nu.xom;resolution:=optional,org.apache.axiom.*;resolution:=optional,org.apache.xml.resolver.*;resolution:=optional,org.jdom.*;resolution:=optional,org.jdom2.*;resolution:=optional,*
Export-Package: *;version=${version}
DynamicImport-Package: *

With the headers this adds in the Saxon-EE jar manifest, Karaf happily lists it as an active OSGi package "Saxon-EE (9.6.0.4)" when dropped into the deploy directory.

It still requires the use of FeatureKeys.LICENSE_FILE_LOCATION and FeatureKeys.GENERATE_BYTE_CODE set to false otherwise it will complain. Again, I'm not sure why.

That aside, Saxon needs an OSGi-friendly dynamic class loading strategy because it's impossible to generate manifest entries for classes only known at runtime.

Lacking this I had to set the Dynamic Import Package to "*" because without it I'd get class not found errors when reading in my XSLT files that were calling Java methods via reflection in my own code and a few other third-party libraries. This sort of defeats the purpose of OSGi and is usually a method of last resort to get things to work. However I did a little digging and came up with this page:

http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html

which might have some recommendations useful for making Saxon more OSGi-friendly after looking at your dynamic class loading strategy described here:

https://saxonica.plan.io/issues/18

    (1-2/2)

    Please register to reply