使用Maven从WSDL生成Java时指定包名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9810422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:58:18  来源:igfitidea点击:

Specifying Package Name When Using Maven to Generate Java from WSDL

javamavensoapwsdlcxf-codegen-plugin

提问by crdzoba

I am using a maven script to generate the Java code I need to communicate with a WCF service. I have gotten communication working and am ready to integrate my maven script, and the code it generates, with the rest of the java code from the project.

我正在使用 maven 脚本生成与 WCF 服务通信所需的 Java 代码。我已经开始进行通信,并准备将我的 maven 脚本及其生成的代码与项目中的其余 java 代码集成。

However, I can't get maven to generate the code with the correct package name I want. From what I've read online I should be using the tag, and I've seen two possible places where this goes. I've included the segment of the script I think these need to go in, and both of them there. However, these tags affect nothing and the code generates just as it did without them

但是,我无法让 maven 使用我想要的正确包名生成代码。从我在网上阅读的内容来看,我应该使用该标签,并且我已经看到了两个可能的地方。我已经包含了我认为这些需要进入的脚本部分,并且它们都在那里。但是,这些标签没有任何影响,代码生成就像没有它们一样

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <configuration>
                        <packageName>com.name.server.cxf</packageName>                      
                    <sourceRoot>src/com/server/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>src/com/server/cxf/code-generation/service.xml</wsdl>
                                <bindingFiles>
                                    <bindingFile>src/com/server/cxf/code-generation/javabindings.xml</bindingFile>
                                </bindingFiles> 
                                <extraargs>
                                    <extraarg>-validate</extraarg>
                                    <extraarg>-client</extraarg>
                                    <extraarg>-verbose</extraarg>
                                    <extraarg>-xjc-verbose</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                        <verbose />
                    </configuration>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                    <configuration>
                        <packageName>com.name.server.cxf</packageName>      
                    </configuration>
                </execution>
            </executions>
        </plugin>

Perhaps I am using the wrong tag, or perhaps it is in the wrong place?

也许我使用了错误的标签,或者它在错误的地方?

采纳答案by aliasmrchips

Add <extraarg>-p</extraarg><extraarg>com.name.server.cxf</extraarg>to your <extraargs>section inside the <wsdlOption>tag. The following (slightly different version) works for me.

添加<extraarg>-p</extraarg><extraarg>com.name.server.cxf</extraarg>到您<extraargs><wsdlOption>标签内的部分。以下(略有不同的版本)对我有用。

       <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>src/com/server/cxf/code-generation/service.xml</wsdl>
                                <bindingFiles>
                                    <bindingFile>src/com/server/cxf/code-generation/javabindings.xml</bindingFile>
                                </bindingFiles>
                                <extraargs>
                                    <extraarg>-validate</extraarg>
                                    <extraarg>-client</extraarg>
                                    <extraarg>-verbose</extraarg>
                                    <extraarg>-xjc-verbose</extraarg>
                                    <extraarg>-p</extraarg>
                                    <extraarg>com.name.server.cxf</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Alternatively, create a file service-optionsin src/com/server/cxf/code-generation/with the content -p com.name.server.cxf

或者,创建一个文件service-optionssrc/com/server/cxf/code-generation/与内容-p com.name.server.cxf

回答by rresino

This works very well for me:

这对我来说非常有效:

<wsdlOption>
                                <wsdl>src/main/resources/wsdl/my_wsdl.wsdl</wsdl>
                                <extraargs>
                                    <extraarg>-p</extraarg>
                                    <extraarg>http://services.demo.es/=com.my.package.demo1</extraarg>
                                    <extraarg>-p</extraarg>
                                    <extraarg>http://tempuri.org/=com.my.package.demo2</extraarg>
                                    <extraarg>-exsh</extraarg>
                                    <extraarg>true</extraarg>
                                    <extraarg>-client</extraarg>
                                    <extraarg>-wsdlLocation</extraarg>
                                    <extraarg></extraarg>
                                </extraargs>
                            </wsdlOption>

回答by V.R.Manivannan

The above solution with

上述解决方案与

<extraarg>-p</extraarg>
<extraarg>com.name.server.cxf</extraarg>

Is changing package name of generated source under one single package ,because of which ObjectFactory classes are getting override.I need like package structure as it as based on wsld. Along with addition package.

example java classes are generated as com.service.name.mypackage.a,com.service.name.mypackage.b,com.service.name.mypackage.c

正在更改单个包下生成的源的包名,因为哪些 ObjectFactory 类正在被覆盖。我需要像基于 wsld 的包结构。随着附加包。

示例 java 类生成为 com.service.name.mypackage.a,com.service.name.mypackage.b,com.service.name.mypackage.c