Java的默认JAXB实现是在我的类路径上选择的

dac*_*cot 6 java xml xslt jaxb classpath

我编写了一个利用JAXB进行XSL转换的java应用程序.我在我的类路径中包含了saxon9.jar,因此我可以在命令行上使用XSLT 2.0而不是XSLT 1.0.

java -classpath ./lib/saxon9.jar:./ -jar myApp.jar
Run Code Online (Sandbox Code Playgroud)

我在XSL中包含了代码来报告使用的XSLT.

<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>
Run Code Online (Sandbox Code Playgroud)

它报道.

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

这是JVM的默认实现.

如何使用我指定的Saxon?


跟进:

所以这些方法都不起作用(除了将撒克逊jar放在背书目录中),但它们都应该有效.看来我使用"-jar myApp.jar"和想要替代XSLT实现的组合是不兼容的.换一种说法...

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

......不起作用,但这确实......

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

...有趣的是,我甚至不必指定工厂,我得到了撒克逊版本......

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

kgi*_*kis 2

您是否尝试过将 jar 放在认可的目录中?

如果您不希望效果是全局的,请使用以下选项:

-Djava.endorsed.dirs=my_dir
Run Code Online (Sandbox Code Playgroud)

在命令行中。