Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ant-Task: Specifying classpath internally in the build script leads to Failed to parse error #78

Closed
nkutsche opened this issue Jun 12, 2019 · 7 comments
Assignees

Comments

@nkutsche
Copy link
Contributor

Hi,

In the documentation about declaring the ant task there is this paragraph:

For this Ant Task to be available you need to include the ph-schematron-ant-task "JAR with dependencies" in your classpath. Alternatively you can use the classpath attribute to reference a classpath that is defined internally in the build script.

At least in my case the "Alternative" does not work.

My ant script:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="ph-schematron test" default="db.common.validation.schematron">
    
    <taskdef name="schematron" classname="com.helger.schematron.ant.Schematron" classpath="lib1.0/ph-schematron-ant-task-5.1.0-jar-with-dependencies.jar"/>
    

    <target name="db.common.validation.schematron">
        <schematron schematronFile="test.sch" expectSuccess="true" failonerror="true">
            <file file="test.xml"/>
        </schematron>
    </target>

</project>

If I just call cls && ant -f build.xml I get this log:

Buildfile: C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\build.xml

db.common.validation.schematron:
[schematron] [main] WARN com.helger.xml.transform.LoggingTransformErrorListener - [warn] Transformation warning (javax.xml.transform.TransformerConfigurationException: jar:file:/C:/Users/Nico/Desktop/tests/ant/schematron/ph-schematron-usage/lib1.0/ph-schematron-ant-task-5.1.0-jar-with-dependencies.jar!/schematron/20100710-xslt2/iso_schematron_skeleton_for_saxon.xsl: line 580: Attribut "version" au▀erhalb des Elements.)
[schematron] [main] WARN com.helger.xml.transform.LoggingTransformErrorListener - [warn] Transformation warning (javax.xml.transform.TransformerConfigurationException: jar:file:/C:/Users/Nico/Desktop/tests/ant/schematron/ph-schematron-usage/lib1.0/ph-schematron-ant-task-5.1.0-jar-with-dependencies.jar!/schematron/20100710-xslt2/iso_schematron_skeleton_for_saxon.xsl: line 604: Attribut "version" au▀erhalb des Elements.)
[schematron] [main] WARN com.helger.xml.transform.LoggingTransformErrorListener - [warn] Transformation warning (javax.xml.transform.TransformerConfigurationException: jar:file:/C:/Users/Nico/Desktop/tests/ant/schematron/ph-schematron-usage/lib1.0/ph-schematron-ant-task-5.1.0-jar-with-dependencies.jar!/schematron/20100710-xslt2/iso_schematron_skeleton_for_saxon.xsl: line 623: Attribut "version" au▀erhalb des Elements.)
[schematron] [main] ERROR com.helger.xml.transform.XMLTransformerFactory - Failed to parse javax.xml.transform.dom.DOMSource@47dd778
[schematron] javax.xml.transform.TransformerConfigurationException: Fehler beim Pr³fen des Typs des Ausdrucks "funcall(document-uri, [AbsoluteLocationPath(null)])".
[schematron]    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:988)
[schematron]    at com.helger.xml.transform.XMLTransformerFactory.newTemplates(XMLTransformerFactory.java:300)
[schematron]    at com.helger.schematron.xslt.SchematronProviderXSLTFromSCH.<init>(SchematronProviderXSLTFromSCH.java:195)
[schematron]    at com.helger.schematron.xslt.SchematronResourceSCHCache.createSchematronXSLTProvider(SchematronResourceSCHCache.java:69)
[schematron]    at com.helger.schematron.xslt.SchematronResourceSCHCache.getSchematronXSLTProvider(SchematronResourceSCHCache.java:145)
[schematron]    at com.helger.schematron.xslt.SchematronResourceSCH.getXSLTProvider(SchematronResourceSCH.java:92)
[schematron]    at com.helger.schematron.xslt.AbstractSchematronXSLTBasedResource.isValidSchematron(AbstractSchematronXSLTBasedResource.java:188)
[schematron]    at com.helger.schematron.ant.Schematron.execute(Schematron.java:752)
[schematron]    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
[schematron]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[schematron]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[schematron]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[schematron]    at java.lang.reflect.Method.invoke(Method.java:498)
[schematron]    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
[schematron]    at org.apache.tools.ant.Task.perform(Task.java:350)
[schematron]    at org.apache.tools.ant.Target.execute(Target.java:449)
[schematron]    at org.apache.tools.ant.Target.performTasks(Target.java:470)
[schematron]    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1391)
[schematron]    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[schematron]    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[schematron]    at org.apache.tools.ant.Project.executeTargets(Project.java:1254)
[schematron]    at org.apache.tools.ant.Main.runBuild(Main.java:830)
[schematron]    at org.apache.tools.ant.Main.startAnt(Main.java:223)
[schematron]    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
[schematron]    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
[schematron] Caused by: Fehler beim Pr³fen des Typs des Ausdrucks "funcall(document-uri, [AbsoluteLocationPath(null)])".
[...]
[schematron] [main] WARN com.helger.schematron.xslt.SchematronResourceSCHCache - The Schematron resource 'C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\test.sch' is invalid!

BUILD FAILED
C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\build.xml:18: Error in Schematron: [error] Transformation error (javax.xml.transform.TransformerException: Stylesheet konnte nicht kompiliert werden)

Total time: 1 second

For some reasons it tries to use the Xalan? (com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl)

If I call the same script with cls && ant -lib=lib1.0 -f build.xml it works:

db.common.validation.schematron:
[schematron] Successfully parsed Schematron file 'C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\test.sch'
[schematron] Validating XML file 'C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\test.xml' against Schematron rules from 'test.sch' expecting success
[schematron] [main] INFO com.helger.jaxb.JAXBContextCache - Creating JAXB context for package org.oclc.purl.dsdl.svrl using ClassLoader java.net.URLClassLoader@4dd8dc3

BUILD FAILED
C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\build.xml:18: 1 Schematron error for XML file 'C:\Users\Nico\Desktop\tests\ant\schematron\ph-schematron-usage\test.xml'

Total time: 3 seconds

This leads in my case to nasty nested ant calls in my ant build scripts, because we need a simple ant call on the commandline. It works with such workarounds, but the "Alternative" with the classpath attribute would make it really cool.

Background infos:

  • Ant version: Apache Ant(TM) version 1.10.6 compiled on May 2 2019
  • Java version: 1.8.0_211
  • System: Windows 10
@phax phax self-assigned this Jun 12, 2019
@phax
Copy link
Owner

phax commented Jun 12, 2019

Try something like

  <path id="phsch.path">
  	<fileset dir="../../../../target">
  		<include name="*-jar-with-dependencies.jar"/>
    </fileset>
  </path>
  <taskdef name="schematron" classname="com.helger.schematron.ant.Schematron" classpathref="phsch.path" />

I am not an ANT expert :(

@nkutsche
Copy link
Contributor Author

nkutsche commented Jun 12, 2019

I am not an ANT expert :(

Me neither. But anything I tried, didn't worked. With path/fileset, taskdef/@classpath, taskdef/classpath, etc. Every time the same result.

And something seems to work, because if I ommit the any classpath reference I get this (for sure):

taskdef class com.helger.schematron.ant.Schematron cannot be found

There is an open stackoverflow question about a very similar error message. Comment from Micheal Kay was:

Well you're definitely running Xalan rather than Saxon.

@phax
Copy link
Owner

phax commented Jun 12, 2019

I can reproduce the error. It seems like a problem with created "JAR with dependencies".
Maybe this is because ANT loads Xalan itself as the primary JAXP provider? I am investigating it

@phax
Copy link
Owner

phax commented Jun 13, 2019

The reasons seems to be that Thread.currentThead ().getContextClassLoader() is not returning the correct ANT class loader. When passing an explicit classloader to the TransformerFactory the ANTClassLoader is used.

phax added a commit that referenced this issue Jun 13, 2019
@phax
Copy link
Owner

phax commented Jun 13, 2019

This is fixed in the 5.2.0 release

@phax phax closed this as completed Jun 13, 2019
@nkutsche
Copy link
Contributor Author

It's a pleasure to work with such a well-maintained open source project! It works perfect.

@phax
Copy link
Owner

phax commented Jun 13, 2019

A star on the project is always appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants