如何设置运行Java中ant脚本的lib目录?
在Ant构建脚本中,我使用以下行设置xslt处理器:如何设置运行Java中ant脚本的lib目录?,java,ant,saxon,Java,Ant,Saxon,在Ant构建脚本中,我使用以下行设置xslt处理器: <xslt> <factory> <attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true" /> <attribute name="http://saxon.sf.net/feature/version-warning" value="fal
<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>
程序返回以下xslt错误:TransformerFactory无法识别属性“”。位于com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.setAttribute(未知源)。此错误与中的类似
我尝试了几个选项来设置包含saxon的lib目录(如ant.lib.directory),但没有任何效果。从java(或force noclasspath)设置lib目录的正确方法是什么?您是否尝试过将“factory”元素的“name”属性设置为“net.sf.saxon.TransformerFactoryImpl”?是的,我尝试过。当使用1.8.1之后的ant版本时,它起作用。然而,因为我无法控制调用的构建文件,所以我不得不使用Ant1.7。此处忽略了factory元素的name属性上的TransformerFactory。为Saxon设置类路径并在Java代码中添加系统变量使处理器保持在Saxon状态:System.setProperty(“javax.xml.transform.TransformerFactory”、“net.sf.Saxon.TransformerFactoryImpl”);TransformerFactory tfactory=TransformerFactory.newInstance();不幸的是,在这个地区有很长的蚁虫历史。我怀疑他们没有一套好的测试用例,但那只是猜测。
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);
}