In my Ant build script I set my xslt processor with the following lines:
<xslt>
<factory>
<attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true" />
<attribute name="http://saxon.sf.net/feature/version-warning" value="false" />
</factory>
<classpath>
<fileset dir="${param}/lib">
<include name="saxon9.jar" />
</fileset>
</classpath>
</xslt>
When ANT runs from the command line, like this
"C:\Programs\jre\bin\java.exe" -classpath "C:\ant\lib\ant-launcher.jar" "-Dant.home=C:\ant" org.apache.tools.ant.launch.Launcher Install -Dparam "C:\dir" basedir "C:\dir2\bin" -emacs -f "C:\dir2\build.xml"
The build completes successful. However when I call the script from within a java program like this:
File buildFile = new File(dir2 + "/build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.setUserProperty("ant.library.dir", "C:/dir2/lib");
p.setUserProperty("param", "C:/dir");
p.setBasedir("C:/dir2/bin");
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setEmacsMode(true);
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.initProperties();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget("Install");
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
The program returns the following xslt error: TransformerFactory does not recognise attribute 'http://saxon.sf.net/feature/xinclude-aware'. at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.setAttribute(Unknown Source). This error is similar as in How to execute XSLT 2.0 with ant?.
I tried several options to set the lib directory containing saxon (like with ant.lib.directory), but this doesn't have any effect. What is the correct way to set the lib directory from java (or force noclasspath)?