Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Maven从XSD文件生成源文件?_Maven_Soap_Wsdl_Soap Client_Maven Jaxb2 Plugin - Fatal编程技术网

无法使用Maven从XSD文件生成源文件?

无法使用Maven从XSD文件生成源文件?,maven,soap,wsdl,soap-client,maven-jaxb2-plugin,Maven,Soap,Wsdl,Soap Client,Maven Jaxb2 Plugin,我有这个。我需要从WSDL模式生成源代码文件。我尝试了许多不同的方法,但无法生成Java存根。在这篇文章中,我将尝试只概述我采取的最后一个也是最相关的方法。此外,我将指出我的怀疑可能是哪里的问题,我将发布我收到的控制台错误。还有到GitHub的链接(这是一个简单的Maven项目,在SpringTools套件中,只有一个starter类,没有任何设置,我使用的是Java1.8) 方法 我的第一次尝试是使用soapui工具,并从上面的链接使用该工具生成*.xsd文件。成功创建这些文件后,我将它们放在

我有这个。我需要从WSDL模式生成源代码文件。我尝试了许多不同的方法,但无法生成Java存根。在这篇文章中,我将尝试只概述我采取的最后一个也是最相关的方法。此外,我将指出我的怀疑可能是哪里的问题,我将发布我收到的控制台错误。还有到GitHub的链接(这是一个简单的Maven项目,在SpringTools套件中,只有一个starter类,没有任何设置,我使用的是Java1.8)

方法

我的第一次尝试是使用
soapui
工具,并从上面的链接使用该工具生成
*.xsd
文件。成功创建这些文件后,我将它们放在Maven项目的
src/main/resources/arvatoprod
文件夹中。然后,我在Maven项目中创建了以下
pom.xml
(省略了不相关的依赖项)

    <build>
        <finalName>Fleaty</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
             <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generatePackage>com.zesium.arvato</generatePackage>
                    <schemaDirectory>src/main/resources/arvatoprod</schemaDirectory>
                    <schemaIncludes>
                        <include>*.xsd</include>
                    </schemaIncludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
上面错误的第一部分:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/C:/Users/Miljan/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.0/jaxb-runtime-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
我不太确定这条信息应该告诉我什么。在任何情况下,我都尝试过删除位于
/C:/Users/Miljan/.m2/repository/org/glassfish/jaxb/jaxb runtime/
位置的文件夹
2.3.1
2.3.4
。每次我点击
Maven generate sources
,文件夹
2.3.0
就会重新出现。该文件夹的内容可以在下图中显示:

上述错误的第二部分

上面的消息还包含以下四行:

ERROR] Error while generating code.Location [ file:/C:/Users/Miljan/Desktop/CommitRevertGeneratedFromXsdWorkspaceArvoProd/Fleaty/src/main/resources/arvatoprod/AFSService_1.xsd{377,94}].
com.sun.istack.SAXParseException2; systemId: file:/C:/Users/Miljan/Desktop/CommitRevertGeneratedFromXsdWorkspaceArvoProd/Fleaty/src/main/resources/arvatoprod/AFSService_1.xsd; lineNumber: 377; columnNumber: 94; Two declarations cause a collision in the ObjectFactory class.

因此,
wsimport
工具(可能由
jax2b-maven插件
用于生成存根)无法构建这些Java类,因为存在某种命名错误。如果我是正确的,本质上这是编译错误,并且由于某种原因,
wsimport
工具(或插件)无法解决它

我并不懒惰,所以我打开了错误中引用的
xsd
文件,
AFSService_1.xsd
。这就是行
328
377
的外观:

328

  <xs:element minOccurs="0" name="AccountInfo" nillable="true" type="tns:AFSInvoiceAccountInfo"/>
我做了我的研究和人们正在做的事情,叫做
binding
()。从本质上讲,可以更改方法的命名、数据类型等。现在,我对
XSD
WSDL
s以及一般的
JAXB
体系结构不是非常熟悉。我确实知道基本术语(什么是
xml名称空间
xsd模式
,什么是
SAX
DOM
解析器,
XPath
XQuery
,我使用了所有这些)


我不确定的是我是否应该编写这些绑定,这是我要采取的最后一步,还是我只需要在我的机器/项目上配置一些东西来制作这些存根?

感谢您提供了问题的完整信息! 以下答案与此处给出的答案基本相同:

该问题主要是由于XJC在
AccountInfo
AFSInvoiceAccountInfo
方面存在问题(根据上面链接的答案)

因此,人们似乎需要手动识别它们:

您需要
src/main/resources
中的以下
bindings.xjb
文件(将由
maven-xjb2-plugin
自动找到):


波阿斯的接近在我看来是合法的。选择一个,我会帮你实现。我已经测试过这些方法,这就是我出错的原因…我的意思是,我对任何方法都很满意,只要它能生成这些.class文件:)我已经为此挣扎了几天了……似乎是两条错误消息的重复。这两条错误消息表明问题中提到的wsdl与您项目中的其他内容之间似乎存在冲突。@cooltea Hi cooltea:)非常感谢您的帮助,几个小时后,我将更新我的问题并将链接发布到GitHub。再次感谢。@Miljan感谢您再次提出这个问题:我能够复制这个问题,并且正在完成我的答案。简言之:
[ERROR] Error while generating code.Location [ file:/C:/Users/Miljan/Desktop/CommitRevertGeneratedFromXsdWorkspaceArvoProd/Fleaty/src/main/resources/arvatoprod/AFSService_1.xsd{328,106}].
com.sun.istack.SAXParseException2; systemId: file:/C:/Users/Miljan/Desktop/CommitRevertGeneratedFromXsdWorkspaceArvoProd/Fleaty/src/main/resources/arvatoprod/AFSService_1.xsd; lineNumber: 328; columnNumber: 106; (Related to above error) This is the other declaration.
  <xs:element minOccurs="0" name="AccountInfo" nillable="true" type="tns:AFSInvoiceAccountInfo"/>
  <xs:element name="AFSInvoiceAccountInfo" nillable="true" type="tns:AFSInvoiceAccountInfo"/>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               version="1.0">
    <jaxb:bindings schemaLocation="https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2">
        <jaxb:bindings node="//xs:element[@name='AFSInvoiceAccountInfo']">
            <jaxb:factoryMethod name="AFSInvoiceAccountInfo"/>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:element[@name='AccountInfo']">
            <jaxb:factoryMethod name="AccountInfo"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>
<project...>
    <!-- ... -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- ... -->
        </plugins>
    </build>
</project>