【问题标题】:build failed when using maven call ant tasks "xslt"使用 maven 调用 ant 任务“xslt”时构建失败
【发布时间】:2011-10-16 11:21:12
【问题描述】:

pom.xml的这一部分

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>                 
                    <executions>
                        <execution>

                            <id>validate</id>
                            <phase>validate</phase>
                            <configuration>
                                <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                                <tasks>
                                    <property name="generated.target" value="${basedir}/target/generated" />
                                    <property name="generated.src.test" value="${generated.target}/src/main/java" />
                                    <property name="generated.resources.test" value="${generated.target}/src/main/resources" />
                                    <property name="generated.wsdl.test" value="${generated.resources.test}/" />
                                    <property name="test.resources.dir" location="${basedir}/src/main/resources" />

                                    <mkdir  dir="${generated.resources.test}/wsdl/type_test" />
                                    <xslt classpath="C://saxonhe9-3-0-5j/saxon9he.jar"  style="${test.resources.dir}/wsdl/type_test/type_test_ID_xsd.xsl" in="${test.resources.dir}/wsdl/type_test/type_test.xsd" out="${generated.resources.test}/wsdl/type_test/type_test_1.xsd">
                                          <param name="groupID" expression="1" />
                                    </xslt>

...

这是错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:
run (validate) on project cxf-testutils: An Ant BuildException has occured: java
.lang.NoClassDefFoundError: org/apache/xml/serializer/ExtendedContentHandler: or
g.apache.xml.serializer.ExtendedContentHandler -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-antrun-plugin:1.6:run (validate) on project cxf-te
stutils: An Ant BuildException has occured: java.lang.NoClassDefFoundError: org/
apache/xml/serializer/ExtendedContentHandler
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)

我尝试在 xslt 标记中添加 classpath="C://saxonhe9-3-0-5j/saxon9he.jar"。 但它仍然抛出这个异常。我试过 Maven 2.2.0 和 Maven 3.0.3.JDK 1.6.0 都失败了。这个pom实际上来自apache cxf源代码。谁能解决?

更新

我尝试了很多解决方法。但这一个终于奏效了。 不要更改 xslt 标记中的任何内容。只需将您的 xalan jar 文件放入 %JAVA-HOME%\jre\lib\endorsed。我下载 xalan-j_2_7_0。并运行 cmd
java org.apache.xalan.xslt.EnvironmentCheck 以确保它可以找到它。它终于奏效了。哼!我花了几个小时来解决它。

【问题讨论】:

    标签: maven-2 ant maven maven-3


    【解决方案1】:

    使用XML Maven Plugin。这对 Saxon 的支持几乎是开箱即用的。

    【讨论】:

    • 看来使用 apache Xalan 会带来一些 jar 冲突问题,这真的很烦人。不管怎样,还是需要的。
    • 貌似xml maven插件和ant xslt有点不一样。
    • 它能达到目的吗?如果您认为自己发现了错误,请提交!
    • 不是错误...这些问题实际上列在 Xalan 的常见问题解答中。
    • 请注意。maven-antrun-plugin 似乎只支持 1.6 版。这可能是它不支持 ant 中的某些新功能的原因。
    【解决方案2】:

    刚刚遇到这个问题,这就是我为解决它所做的。

    为撒克逊添加依赖:

    <dependency>
        <groupId>net.sf.saxon</groupId>
        <artifactId>Saxon-HE</artifactId>
        <version>9.4</version>
    </dependency>
    

    为 saxon 添加类路径:

    <xslt in="in.xml" out="out.html" style="style.xsl">
      <classpath location="${net.sf.saxon:Saxon-HE:jar}" />
      <factory name="net.sf.saxon.TransformerFactoryImpl"/>
    </xslt>
    

    【讨论】:

      猜你喜欢
      • 2011-02-09
      • 1970-01-01
      • 2019-10-14
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      相关资源
      最近更新 更多