ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ernst de Haan <er...@jollem.com>
Subject Passing classpath to <style/> task ?
Date Fri, 11 May 2001 11:12:28 GMT
Hi,

I'm using the `style' task to convert from XML to HTML using XSLT. Ant is
having trouble finding a suitable XSLT processor by itself, so I'll have to
adjust the class path, it seems.

I've temporarily modified my `init' target to print the built-in property
`java.class.path':

   bash-2.05$ ant init
   Buildfile: build.xml
 
   init:
        [echo] The class path is: :/usr/local/share/java/jakarta-ant-1.3/bin/../lib/ant.jar:/usr/local/share/java/jakarta-ant-1.3/bin/../lib/crimson.jar:/usr/local/share/java/jakarta-ant-1.3/bin/../lib/jaxp.jar:/usr/local/share/java/jakarta-ant-1.3/bin/../lib/optional.jar:/usr/local/linux-jdk1.3.0/lib/tools.jar

   BUILD SUCCESSFUL

First of all, the class path starts with a colon. That looks like a bug. My
CLASSPATH environment variable is empty, so it should not try to include it.

Now it looks like jaxp.jar is included in the class path. I checked if it
exists, and it does. Bit weird though, that the class path includes constructs
like "xxxxxxx/bin/../lib/ant.jar", why not make Ant detect "../" and make sure
it changes something like this to "xxxxxxx/lib/ant.jar" ? This would avoid any
differences between the handling of symlinks. When I used to work with Linux,
I found that some tools interpreted ".." as the higher directory based on the
structure of the symlink, while others interpreted it as the higher directory
based on the actual absolute path. So it may be wise to decide which approach
to take (symlink-based ofcourse) and replace the reference to .. as suggested.

But *if* jaxp is included in the class path, then why doesn't Ant use xslp?
When I try to execute my target that includes a <style/> task, it gives me an
error:

   [...]

   2html.classic:
       [style] Transforming into /usr/home/ernst/orion-primer/build
 
   BUILD FAILED
 
   /usr/home/ernst/orion-primer/build.xml:51:
   javax.xml.transform.TransformerFactoryConfigurationError:
   org.apache.xalan.processor.TransformerFactoryImpl
   --- Nested Exception ---
   javax.xml.transform.TransformerFactoryConfigurationError:
   org.apache.xalan.processor.TransformerFactoryImpl
           at javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:94)
           at org.apache.tools.ant.taskdefs.optional.TraXLiaison.<init>(TraXLiaison.java:87)
           at java.lang.Class.newInstance0(Native Method)
           at java.lang.Class.newInstance(Class.java:237)
           at org.apache.tools.ant.taskdefs.XSLTProcess.setProcessor(XSLTProcess.java:231)
           at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:137)
           at org.apache.tools.ant.Target.execute(Target.java:153)
           at org.apache.tools.ant.Project.runTarget(Project.java:898)
           at org.apache.tools.ant.Project.executeTarget(Project.java:536)
           at org.apache.tools.ant.Project.executeTargets(Project.java:510)
           at org.apache.tools.ant.Main.runBuild(Main.java:421)
           at org.apache.tools.ant.Main.main(Main.java:149)

This is the <style/> task ending at line 51:

   <style basedir= "${src.dir}/tutorial"
          destdir= "${build.dir}"
          style=   "${stylesheet.classic.path}"
          includes="${src.file}.xml" />

It seems Ant is trying to use the TraX processor, but fails to. Then why
doesn't it use the JAXP parser instead? The documentation for the style task
tells me that the style task will choose a processor based on a certain sort
order (trax, xslp, xalan) and based on which one(s) are available. It seems
TraX is not available, and still it tries to use them.

*But* if I change the <style/> task to use the "xslp" processor, then I get
another error message:

   /usr/home/ernst/orion-primer/build.xml:51: java.lang.NoClassDefFoundError: com/kvisco/xsl/XSLProcessor
   --- Nested Exception ---
   java.lang.NoClassDefFoundError: com/kvisco/xsl/XSLProcessor
           at org.apache.tools.ant.taskdefs.optional.XslpLiaison.<init>(XslpLiaison.java:75)
           at java.lang.Class.newInstance0(Native Method)
           at java.lang.Class.newInstance(Class.java:237)
           at org.apache.tools.ant.taskdefs.XSLTProcess.setProcessor(XSLTProcess.java:235)
           at java.lang.reflect.Method.invoke(Native Method)
           at org.apache.tools.ant.IntrospectionHelper$3.set(IntrospectionHelper.java:352)
           at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:227)
           at org.apache.tools.ant.ProjectHelper.configure(ProjectHelper.java:619)
           at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:134)
           at org.apache.tools.ant.Task.maybeConfigure(Task.java:220)
           at org.apache.tools.ant.Target.execute(Target.java:152)
           at org.apache.tools.ant.Project.runTarget(Project.java:898)
           at org.apache.tools.ant.Project.executeTarget(Project.java:536)
           at org.apache.tools.ant.Project.executeTargets(Project.java:510)
           at org.apache.tools.ant.Main.runBuild(Main.java:421)
           at org.apache.tools.ant.Main.main(Main.java:149)

So it seems that XSLP cannot be used although jaxp.jar is included in the
class path.

Now it seems I will have to change my class path so Ant will be able to find
the right classes. I've done this in the past, this build.xml file used to
work with a carefully configured CLASSPATH env var (just included all jar
files of Xalan-J, Xerces-J and a few other libraries), but I want my build.xml
file to be independent of env vars. I'm using a separate .properties file with
build settings.

Why not allow the user of the <style/> task to set the class path, similar to
the way the <java/> task allows this? This way I can use the properties from
the file with build settings.

My points/suggestions:

[1] Ant should detect if the CLASSPATH env var is empty and not use it if it
    is. I consider this a minor bug (non-critical).

[2] Detect references to the higher-level directory and replace them to use
    absolute paths. I consider this an esthetical improvement.

[3] Why does Ant try to use the TraX processor if it is not available?

[4] Document the use of the style task if it is really not usable
    `out-of-the-box'.

[5] Allow setting the class path for the <style/> task so a build.xml file
    does not have to depend on the CLASSPATH env var in order to find an XSLT
    processor.



Sincerely,

Ernst

 

-- 
Ernst de Haan
Java Architect
Jollem Information Technology

    "Come to me all who are weary and burdened
        and I will give you rest" -- Jesus Christ

Mime
View raw message