使用maven调用ant任务“xslt”时构建失败

时间:2011-07-30 09:31:16

标签: maven-2 ant maven maven-3

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以确保它可以找到它。它终于奏效了。咦!解决它需要花费数小时的时间。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

为撒克逊添加依赖:

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