英文:
Maven generatePackage for a wsdl generating classes from schema definition
问题
我正在使用Java14与SpringBoot。
我需要基于wsdl生成一些Java类。虽然生成了这些类,但它将所有生成的类都放在一个扁平的结构中,而不是放在wsdl中指定的包中。
如果有人能给予一些建议,我会非常感谢。
更多细节:
POM(您可以看到生成的包是com.travellinck.client.approval
)
<build>
<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.13.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.travellinck.client.approval</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>
</plugins>
</build>
WSDL
<!-- 由JAX-WS RI发布,网址为http://jax-ws.dev.java.net。 RI的版本是JAX-WS RI 2.2.5-b05。 -->
<!-- 由JAX-WS RI生成,网址为http://jax-ws.dev.java.net。 RI的版本是JAX-WS RI 2.2.5-b05。 -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.travellinck.com/client/approval/service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.travellinck.com/client/approval/service" name="ApprovalService">
<!-- 更多内容,略去 -->
</definitions>
这将在com.travellinck.client.approval
包中生成模型类。
这是不正确的,我希望它的生成方式如下(这是从另一个使用Java7的应用程序生成的相同wsdl的模型类):
如您所见,这些类不是处于一个扁平的结构中,而是按照wsdl定义放置在其各自的包中:
例如:
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/contact" schemaLocation="http://localhost:8088/approval?xsd=4"/>
</xsd:schema>
这好像是忽略了/contact
。
(注意:我只提供了代码部分的翻译,不包括对问题的回答。)
英文:
I am using Java14 with SpringBoot.
I need to generate some Java classes based on a wsdl. It is generating, however, it puts all the generated classes in a flat structure and not in the packages specified in the wsdl.
If anyone can give some advise, I would appreciate it.
More details:
POM (you can see that the generated package is com.travellinck.client.approval
)
<build>
<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.13.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.travellinck.client.approval</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>
</plugins>
</build>
WSDL
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 . -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 . -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.travellinck.com/client/approval/service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.travellinck.com/client/approval/service" name="ApprovalService">
<types>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/service" schemaLocation="http://localhost:8088/approval?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation/strategy" schemaLocation="http://localhost:8088/approval?xsd=2"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation" schemaLocation="http://localhost:8088/approval?xsd=3"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/contact" schemaLocation="http://localhost:8088/approval?xsd=4"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval" schemaLocation="http://localhost:8088/approval?xsd=5"/>
</xsd:schema>
</types>
<message name="submitRequestForApproval">
<part xmlns:ns1="http://www.travellinck.com/client/approval" name="approvalRequest" element="ns1:approvalRequest"/>
</message>
<message name="submitRequestForApprovalResponse">
<part xmlns:ns2="http://www.travellinck.com/client/approval" name="approvalResponse" element="ns2:approvalResponse"/>
</message>
<message name="UnsupportedBusinessRequest">
<part name="fault" element="tns:unsupportedBusinessRequest"/>
</message>
<message name="UnsupportedSupportingDocument">
<part name="fault" element="tns:unsupportedSupportingDocument"/>
</message>
<message name="getApprovalState">
<part xmlns:ns3="http://www.travellinck.com/client/approval" name="getApprovalStateRequest" element="ns3:getApprovalStateRequest"/>
</message>
<message name="getApprovalStateResponse">
<part xmlns:ns4="http://www.travellinck.com/client/approval" name="getApprovalStateResponse" element="ns4:getApprovalStateResponse"/>
</message>
<message name="UnknownApprovalRequest">
<part name="fault" element="tns:unknownApprovalRequest"/>
</message>
<message name="withdrawRequestForApproval">
<part xmlns:ns5="http://www.travellinck.com/client/approval" name="withdrawApprovalRequest" element="ns5:withdrawApprovalRequest"/>
</message>
<message name="withdrawRequestForApprovalResponse">
<part xmlns:ns6="http://www.travellinck.com/client/approval" name="withdrawApprovalResponse" element="ns6:withdrawApprovalResponse"/>
</message>
<message name="InvalidRequest">
<part name="fault" element="tns:invalidRequest"/>
</message>
<message name="RequestNoLongerInProgress">
<part name="fault" element="tns:requestNoLongerInProgress"/>
</message>
<portType name="Approval">
<operation name="submitRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalRequest" message="tns:submitRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalResponse" message="tns:submitRequestForApprovalResponse"/>
<fault message="tns:UnsupportedBusinessRequest" name="UnsupportedBusinessRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedBusinessRequest"/>
<fault message="tns:UnsupportedSupportingDocument" name="UnsupportedSupportingDocument" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedSupportingDocument"/>
</operation>
<operation name="getApprovalState">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateRequest" message="tns:getApprovalState"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateResponse" message="tns:getApprovalStateResponse"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalState/Fault/UnknownApprovalRequest"/>
</operation>
<operation name="withdrawRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalRequest" message="tns:withdrawRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalResponse" message="tns:withdrawRequestForApprovalResponse"/>
<fault message="tns:InvalidRequest" name="InvalidRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/InvalidRequest"/>
<fault message="tns:RequestNoLongerInProgress" name="RequestNoLongerInProgress" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/RequestNoLongerInProgress"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/UnknownApprovalRequest"/>
</operation>
</portType>
<binding name="ApprovalPortBinding" type="tns:Approval">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="submitRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnsupportedBusinessRequest">
<soap:fault name="UnsupportedBusinessRequest" use="literal"/>
</fault>
<fault name="UnsupportedSupportingDocument">
<soap:fault name="UnsupportedSupportingDocument" use="literal"/>
</fault>
</operation>
<operation name="getApprovalState">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
<operation name="withdrawRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="InvalidRequest">
<soap:fault name="InvalidRequest" use="literal"/>
</fault>
<fault name="RequestNoLongerInProgress">
<soap:fault name="RequestNoLongerInProgress" use="literal"/>
</fault>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
</binding>
<service name="ApprovalService">
<port name="ApprovalPort" binding="tns:ApprovalPortBinding">
<soap:address location="http://localhost:8088/approval"/>
</port>
</service>
</definitions>
This generates the model classes in the com.travellinck.client.approval
package.
This is incorrect, I would expect it to rather generate them as follows (This was taken from another application using Java7 that generated the model classes from the same wsdl):
As you can see, these classes are not in a flat structure, but rather in their packages according to the wsdl definition:
e.g.
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/contact" schemaLocation="http://localhost:8088/approval?xsd=4"/>
</xsd:schema>
It's as if it is ignoring the /contact
.
答案1
得分: 2
我通过使用apache.cxf来修复了这个问题。
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.7</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/approval.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
英文:
I fixed this by rather using apache.cxf
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.7</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/approval.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论