Maven 通过 wsdl 生成从模式定义生成类的 generatePackage

huangapple go评论147阅读模式
英文:

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)

	&lt;build&gt;
		&lt;plugins&gt;
&lt;!--			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt; --&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.jvnet.jaxb2.maven2&lt;/groupId&gt;
				&lt;artifactId&gt;maven-jaxb2-plugin&lt;/artifactId&gt;
				&lt;version&gt;0.13.2&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;goals&gt;
							&lt;goal&gt;generate&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
				&lt;configuration&gt;
					&lt;generatePackage&gt;com.travellinck.client.approval&lt;/generatePackage&gt;
					&lt;generateDirectory&gt;${project.basedir}/src/main/java&lt;/generateDirectory&gt;
					&lt;schemaDirectory&gt;${project.basedir}/src/main/resources/wsdl&lt;/schemaDirectory&gt;
					&lt;schemaIncludes&gt;
						&lt;include&gt;*.wsdl&lt;/include&gt;
					&lt;/schemaIncludes&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

WSDL

&lt;!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI&#39;s version is JAX-WS RI 2.2.5-b05 .  --&gt;
&lt;!--  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI&#39;s version is JAX-WS RI 2.2.5-b05 .  --&gt;
&lt;definitions xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot; xmlns:wsp=&quot;http://www.w3.org/ns/ws-policy&quot; xmlns:wsp1_2=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot; xmlns:wsam=&quot;http://www.w3.org/2007/05/addressing/metadata&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://www.travellinck.com/client/approval/service&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; targetNamespace=&quot;http://www.travellinck.com/client/approval/service&quot; name=&quot;ApprovalService&quot;&gt;
&lt;types&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval/service&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=1&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval/evaluation/strategy&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=2&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval/evaluation&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=3&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval/contact&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=4&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=5&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;/types&gt;
&lt;message name=&quot;submitRequestForApproval&quot;&gt;
&lt;part xmlns:ns1=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;approvalRequest&quot; element=&quot;ns1:approvalRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;submitRequestForApprovalResponse&quot;&gt;
&lt;part xmlns:ns2=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;approvalResponse&quot; element=&quot;ns2:approvalResponse&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;UnsupportedBusinessRequest&quot;&gt;
&lt;part name=&quot;fault&quot; element=&quot;tns:unsupportedBusinessRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;UnsupportedSupportingDocument&quot;&gt;
&lt;part name=&quot;fault&quot; element=&quot;tns:unsupportedSupportingDocument&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;getApprovalState&quot;&gt;
&lt;part xmlns:ns3=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;getApprovalStateRequest&quot; element=&quot;ns3:getApprovalStateRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;getApprovalStateResponse&quot;&gt;
&lt;part xmlns:ns4=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;getApprovalStateResponse&quot; element=&quot;ns4:getApprovalStateResponse&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;UnknownApprovalRequest&quot;&gt;
&lt;part name=&quot;fault&quot; element=&quot;tns:unknownApprovalRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;withdrawRequestForApproval&quot;&gt;
&lt;part xmlns:ns5=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;withdrawApprovalRequest&quot; element=&quot;ns5:withdrawApprovalRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;withdrawRequestForApprovalResponse&quot;&gt;
&lt;part xmlns:ns6=&quot;http://www.travellinck.com/client/approval&quot; name=&quot;withdrawApprovalResponse&quot; element=&quot;ns6:withdrawApprovalResponse&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;InvalidRequest&quot;&gt;
&lt;part name=&quot;fault&quot; element=&quot;tns:invalidRequest&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;RequestNoLongerInProgress&quot;&gt;
&lt;part name=&quot;fault&quot; element=&quot;tns:requestNoLongerInProgress&quot;/&gt;
&lt;/message&gt;
&lt;portType name=&quot;Approval&quot;&gt;
&lt;operation name=&quot;submitRequestForApproval&quot;&gt;
&lt;input wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalRequest&quot; message=&quot;tns:submitRequestForApproval&quot;/&gt;
&lt;output wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalResponse&quot; message=&quot;tns:submitRequestForApprovalResponse&quot;/&gt;
&lt;fault message=&quot;tns:UnsupportedBusinessRequest&quot; name=&quot;UnsupportedBusinessRequest&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedBusinessRequest&quot;/&gt;
&lt;fault message=&quot;tns:UnsupportedSupportingDocument&quot; name=&quot;UnsupportedSupportingDocument&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedSupportingDocument&quot;/&gt;
&lt;/operation&gt;
&lt;operation name=&quot;getApprovalState&quot;&gt;
&lt;input wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/getApprovalStateRequest&quot; message=&quot;tns:getApprovalState&quot;/&gt;
&lt;output wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/getApprovalStateResponse&quot; message=&quot;tns:getApprovalStateResponse&quot;/&gt;
&lt;fault message=&quot;tns:UnknownApprovalRequest&quot; name=&quot;UnknownApprovalRequest&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/getApprovalState/Fault/UnknownApprovalRequest&quot;/&gt;
&lt;/operation&gt;
&lt;operation name=&quot;withdrawRequestForApproval&quot;&gt;
&lt;input wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalRequest&quot; message=&quot;tns:withdrawRequestForApproval&quot;/&gt;
&lt;output wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalResponse&quot; message=&quot;tns:withdrawRequestForApprovalResponse&quot;/&gt;
&lt;fault message=&quot;tns:InvalidRequest&quot; name=&quot;InvalidRequest&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/InvalidRequest&quot;/&gt;
&lt;fault message=&quot;tns:RequestNoLongerInProgress&quot; name=&quot;RequestNoLongerInProgress&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/RequestNoLongerInProgress&quot;/&gt;
&lt;fault message=&quot;tns:UnknownApprovalRequest&quot; name=&quot;UnknownApprovalRequest&quot; wsam:Action=&quot;http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/UnknownApprovalRequest&quot;/&gt;
&lt;/operation&gt;
&lt;/portType&gt;
&lt;binding name=&quot;ApprovalPortBinding&quot; type=&quot;tns:Approval&quot;&gt;
&lt;soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot;/&gt;
&lt;operation name=&quot;submitRequestForApproval&quot;&gt;
&lt;soap:operation soapAction=&quot;&quot;/&gt;
&lt;input&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/input&gt;
&lt;output&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/output&gt;
&lt;fault name=&quot;UnsupportedBusinessRequest&quot;&gt;
&lt;soap:fault name=&quot;UnsupportedBusinessRequest&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;fault name=&quot;UnsupportedSupportingDocument&quot;&gt;
&lt;soap:fault name=&quot;UnsupportedSupportingDocument&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;/operation&gt;
&lt;operation name=&quot;getApprovalState&quot;&gt;
&lt;soap:operation soapAction=&quot;&quot;/&gt;
&lt;input&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/input&gt;
&lt;output&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/output&gt;
&lt;fault name=&quot;UnknownApprovalRequest&quot;&gt;
&lt;soap:fault name=&quot;UnknownApprovalRequest&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;/operation&gt;
&lt;operation name=&quot;withdrawRequestForApproval&quot;&gt;
&lt;soap:operation soapAction=&quot;&quot;/&gt;
&lt;input&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/input&gt;
&lt;output&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/output&gt;
&lt;fault name=&quot;InvalidRequest&quot;&gt;
&lt;soap:fault name=&quot;InvalidRequest&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;fault name=&quot;RequestNoLongerInProgress&quot;&gt;
&lt;soap:fault name=&quot;RequestNoLongerInProgress&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;fault name=&quot;UnknownApprovalRequest&quot;&gt;
&lt;soap:fault name=&quot;UnknownApprovalRequest&quot; use=&quot;literal&quot;/&gt;
&lt;/fault&gt;
&lt;/operation&gt;
&lt;/binding&gt;
&lt;service name=&quot;ApprovalService&quot;&gt;
&lt;port name=&quot;ApprovalPort&quot; binding=&quot;tns:ApprovalPortBinding&quot;&gt;
&lt;soap:address location=&quot;http://localhost:8088/approval&quot;/&gt;
&lt;/port&gt;
&lt;/service&gt;
&lt;/definitions&gt;

This generates the model classes in the com.travellinck.client.approval package.

Maven 通过 wsdl 生成从模式定义生成类的 generatePackage

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

Maven 通过 wsdl 生成从模式定义生成类的 generatePackage

As you can see, these classes are not in a flat structure, but rather in their packages according to the wsdl definition:

e.g.

    &lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://www.travellinck.com/client/approval/contact&quot; schemaLocation=&quot;http://localhost:8088/approval?xsd=4&quot;/&gt;
&lt;/xsd:schema&gt;

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

		&lt;plugin&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
&lt;version&gt;3.3.7&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;generate-sources&lt;/id&gt;
&lt;phase&gt;generate-sources&lt;/phase&gt;
&lt;configuration&gt;
&lt;sourceRoot&gt;${project.basedir}/src/main/java&lt;/sourceRoot&gt;
&lt;wsdlOptions&gt;
&lt;wsdlOption&gt;
&lt;wsdl&gt;${project.basedir}/src/main/resources/wsdl/approval.wsdl&lt;/wsdl&gt;
&lt;/wsdlOption&gt;
&lt;/wsdlOptions&gt;
&lt;/configuration&gt;
&lt;goals&gt;
&lt;goal&gt;wsdl2java&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年6月29日 18:26:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/62636121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定