Pops
Pops

Reputation: 30868

Set one third-party JAR's classpath to include another one with Ant

How can I set the classpath of one third-party JAR to include a second third-party JAR in Ant?

I need this to run the vanilla Using Schematron with ANT example from this site. (I'm 99% sure you don't need to know what Schematron is to answer this question.) The example's instructions are in a short PDF linked near the top of the page. I copy-pasted the contents of all the files directly from the PDF into Eclipse.

I then downloaded ant-schematron-2010-04-14.jar from the above site, and got saxon9he.jar from the SAXON SourceForge page. I also changed the buildfile to match. With line numbers and without comments, it looks like this:

09 <project name="schematron-ant-sample" default="validate">
14     <taskdef name="schematron"
15              classname="com.schematron.ant.SchematronTask"
16              classpath="lib/ant-schematron-2010-04-14.jar; lib/saxon9he.jar" />
22     <target name="validate" description="Test with a Fileset">
23         <schematron schema="sch/sample.sch" failonerror="false">
24             <fileset dir="xml" includes="*.xml" />
25         </schematron>
26     </target>
27 </project>

When I ran the buildfile, I got the following error:

validate:

BUILD FAILED
C:\Users\gdawes\Documents\workspace\SchematronAntExample\build.xml:23: /
javax.xml.transform.TransformerFactoryConfigurationError: Provider /
net.sf.saxon.TransformerFactoryImpl not found

Total time: 265 milliseconds

A similar error occurs if the SAXON JAR isn't listed in schematron's classpath. I've confirmed that TransformerFactoryImpl is present in the SAXON JAR, but I can't figure out how to get the Schematron code to recognize it. How should I set up the classpath? (Or, if I'm wrong and this isn't a classpath issue, how do I get the build to succeed?)

Upvotes: 3

Views: 748

Answers (2)

Christopher Peisert
Christopher Peisert

Reputation: 24194

The classpath in the <taskdef> should only contain: lib/ant-schematron-2010-04-14.jar, similar to the example provided in Using Schematron for Ant by example.

<?xml version="1.0" encoding="UTF-8"?>
<project name="schematron-ant-sample" default="validate">
  <taskdef name="schematron"
      classname="com.schematron.ant.SchematronTask"
      classpath="lib/ant-schematron-2010-04-14.jar" />
  <target name="validate" description="Test with a Fileset">
    <schematron schema="sch/sample.sch" failonerror="false">
      <fileset dir="xml" includes="*.xml" />
    </schematron>
  </target>
</project>

In addition to correcting the <taskdef>, placing the saxon9he.jar in the Ant library folder makes net.sf.saxon.TransformerFactoryImpl available and resolves the error (tested on Ubuntu Linux with Ant 1.8.2).

Upvotes: 2

davidfmatheson
davidfmatheson

Reputation: 3567

If I remember correctly, the classpath on a taskdef is just the classpath used to look up the class that you're trying to load, it is not the classpath that the task actually runs with. Try adding the required jars to the User Entries section of the Classpath tab of the Ant build configuration in Eclipse.

Upvotes: 1

Related Questions