Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java's default JAXB implementation is chosen over my classpath

I've written a java application that utilizes JAXB for XSL transforms. I've included the saxon9.jar in my classpath so that I can use XSLT 2.0 rather than XSLT 1.0 on the command line.

java -classpath ./lib/saxon9.jar:./ -jar myApp.jar

I've included code in my XSL to report the XSLT used.

<xsl:comment><xsl:text >
</xsl:text>XSLT Version: <xsl:value-of select="system-property('xsl:version')" /> <xsl:text >
</xsl:text>XSLT Vendor: <xsl:value-of select="system-property('xsl:vendor')" /> <xsl:text >
</xsl:text>XSLT Vendor URL: <xsl:value-of select="system-property('xsl:vendor-url')" /> <xsl:text >
</xsl:text></xsl:comment>

It reports.

XSLT Version: 1.0
XSLT Vendor: Apache Software Foundation (Xalan XSLTC)
XSLT Vendor URL: http://xml.apache.org/xalan-j

This is the default implementation that is part of the JVM.

How do I get it to use the Saxon that I specified?


Follow up:

So none of these methods worked (except placing the saxon jar in the endorsed directory), but they all should have worked. It seems the combination of my using the "-jar myApp.jar" and wanting an alternative XSLT implementation were incompatible. In other words...

java -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl -classpath ./lib/saxon9.jar:./ -jar myApp.jar

...does not work, but this does...

java -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl -classpath ./lib/saxon9.jar:./myApp.jar org.dacracot.myApp

...interestingly, I don't even have to specify the factory and I get the saxon version...

java -classpath ./lib/saxon9.jar:./myApp.jar org.dacracot.myApp

like image 928
dacracot Avatar asked Feb 13 '09 20:02

dacracot


1 Answers

Check out the javadoc for TransformerFactory.newInstance() for all the possible ways to configure the factory.

  1. System Property
  2. lib/jaxp.properties
  3. Services config file (may be in the saxon JAR, /META-INF/services/javax.xml.transform.TransformerFactory)
like image 115
nbeyer Avatar answered Oct 16 '22 12:10

nbeyer