使用 Maven 调用 ant 任务时构建失败"xslt"



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%jrelib背书。我下载了xalan-j_2_7_0。然后运行cmd
environment check以确保它可以找到它。它终于成功了。哈!我花了好几个小时才解决。

使用XML Maven Plugin。这实际上支持Saxon开箱即用。

刚刚遇到了这个问题,下面是我解决它的方法。

为saxon添加依赖:

<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>

相关内容

  • 没有找到相关文章

最新更新