The default Java implementation of JAXB is selected in my classpath

I wrote a Java application that uses JAXB for XSL transformations. I included saxon9.jar in my classpath to use XSLT 2.0 instead of XSLT 1.0 on the command line.

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

I have included the code in my XSL to report on 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> 

Reported.

 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, which is part of the JVM.

How can I use Saxon, which I indicated?


Following actions:

Thus, none of these methods worked (except for placing the Saxon jar in the approved catalog), but all of them should have worked. It seems the combination of my use of "-jar myApp.jar" and the desire for 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 it does ...

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

... interesting, I don’t even need to specify a factory, and I get the saxon version ...

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

+6
java classpath xml xslt jaxb
source share
5 answers

Have you tried placing your jar in an approved directory?

If you do not want the effect to be global, use the following command:

 -Djava.endorsed.dirs=my_dir 

on the command line.

+2
source share

Check javadoc for TransformerFactory.newInstance () for all possible ways to customize factory.

  • System property
  • Library /jaxp.properties
  • Services configuration file (may be in the saxon JAR, / META-INF / services / javax.xml.transform.TransformerFactory)
+2
source share

The last example you posted (without / -Djavax ...) works because the META-INF / services directory contains a file called

java.xml.transform.TransformerFactory

with content

net.sf.saxon.TransformerFactoryImpl

Reason for use

 java -cp lib/saxon9.jar;myjar.jar 

works and

 java -cp lib/saxon9.jar -jar myjar.jar 

doesn't mean that using the -jar option tells java (w) .exe to ignore the rest of the command line and pull everything (the included classpath) from the jar manifest file. If you put saxon9.jar in your jar manifest class path, it should work.

 Manifest-Version: 1.0 Main-Class: net.my.MainClass Class-Path: lib/saxon9.jar 
+2
source share

This system property should set the TransformerFactory replacement:

 java -Djavax.xml.transform.TransformerFactory=com.foobar.AcmeTransformer MyApp 

I believe the factory class you want is net.sf.saxon.TransformerFactoryImpl

+1
source share

What about

 java -Xbootclasspath:lib/saxon9.jar -classpath . -jar myApp.jar 
0
source share

All Articles