问题
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:
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>
来源:https://stackoverflow.com/questions/62636121/maven-generatepackage-for-a-wsdl-generating-classes-from-schema-definition