为什么会出现以下异常“非静态 Java 函数的第一个参数"? [英] Why do I get the following exception 'first argument to the non-static Java function'?

查看:20
本文介绍了为什么会出现以下异常“非静态 Java 函数的第一个参数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此异常:

致命错误:'非静态 Java 函数 *** 的第一个参数不是有效的对象引用.'

FATAL ERROR: 'The first argument to the non-static Java function *** is not a valid object reference.'

当我尝试使用 xml-maven-plugin 转换 XML 文档时会发生这种情况.

This happens when I try to transform an XML document using the xml-maven-plugin.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>transform</goal>
           </goals>
        </execution>
    </executions>
    <configuration>
        <transformationSets>
            <transformationSet>
                <dir>target/generated/wsdl</dir>
                <stylesheet>src/test/resources/transform/my-transformation.xsl</stylesheet> 
                <includes>   
                    <include>**/*.xsd</include>
                </includes>
                <outputDir>target/generated/wsdl</outputDir>
            </transformationSet>
         </transformationSets>
    </configuration>
</plugin>

错误信息

 [INFO] --- xml-maven-plugin:1.0:transform (transform--xsd) @ my-pom ---
 Warning:  org.apache.xerces.parsers.SAXParser: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.
 Warning:  org.apache.xerces.parsers.SAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
 Warning:  org.apache.xerces.parsers.SAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
 ERROR:  'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.'
 FATAL ERROR:  'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.'

XSL 转换文件的内容

XSL Transformation file's content

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://mysite/mycreate" xmlns:xalan="http://xml.apache.org/xslt" xmlns:mytag="http://andreas/ps-transformations" version="2.0">
<xsl:strip-space elements="*"/> 
<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>

<xsl:variable name="myAnnotations" select="document('element-list.xml')"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="xs:element">     
    <xsl:param name="myValue" select="normalize-space(mytag:isTheRightElement(@class))"/>

    <xsl:choose>
        <xsl:when test="$myValue=''">
            <xsl:copy> 
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:when>
        <xsl:otherwise>
             <xsl:copy> 
                <xsl:apply-templates select="@*|node()"/>
                <xsl:element name="xs:annotation"> 
                    <xsl:element name="xs:documentation">
                        <xsl:value-of select="$elementValue"/>
                    </xsl:element>
                </xsl:element> 
            </xsl:copy>
        </xsl:otherwise>
      </xsl:choose>
</xsl:template> 

<xsl:function name="myTag:isTheRightElement">
    <xsl:param name="class"/>  
       <xsl:for-each select="$myAnnotations/elementList/element">
            <xsl:if test="lower-case(@class) = 'something'">
               <xsl:value-of select="text()"/>           
            </xsl:if>
         </xsl:for-each> 
    </xsl:function>    
</xsl:stylesheet>

推荐答案

我在尝试使用 XSLT 2.0 '样式表' 进行转换时收到此错误,但我使用的是 XSLT 1.0 解析器.

I get this error when trying to transform using an XSLT 2.0 'stylesheet', but I use an XSLT 1.0 parser.

就我而言,当我删除 saxon 的 maven 依赖项时会发生这种情况,这是一个 XSLT 2.0 解析器.Java 7 附带的 XSLT 解析器只能处理 XSLT 1.0.

In my case, this happens when I remove the maven dependency of saxon, which is an XSLT 2.0 parser. The XSLT parser that comes with Java 7 can handle only XSLT 1.0.

Maven 解决方案是保留撒克逊:

Maven solution is to keep the Saxon:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>transform</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <transformerFactory>net.sf.saxon.TransformerFactoryImpl</transformerFactory>
        <transformationSets>
            <transformationSet>
                <dir>src/main/resources/xml</dir>
                <stylesheet>src/main/resources/xslt/my-transformation.xsl</stylesheet>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <outputDir>target/generated/wsdl</outputDir>
            </transformationSet>
        </transformationSets>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>Saxon-HE</artifactId>
            <version>9.6.0-5</version>
        </dependency>
    </dependencies>
</plugin>

这篇关于为什么会出现以下异常“非静态 Java 函数的第一个参数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆