使用Maven从WSDL生成Java时指定包名称 [英] Specifying Package Name When Using Maven to Generate Java from WSDL
问题描述
我正在使用maven脚本生成我需要与WCF服务通信的Java代码。我已经进行了沟通工作,并准备将我的maven脚本及其生成的代码与项目中的其余Java代码集成。
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用我想要的正确包名生成代码。从我在网上看到的,我应该使用标签,我已经看到了两个可能的地方。我已经包含了我认为需要进入的脚本部分,并且它们都存在。但是,这些标签不会产生任何影响,代码生成就像没有它们一样。
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
<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?
推荐答案
添加< extraarg> -p< / extraarg>< extraarg> com.name.server.cxf< / extraarg>
到< wsdlOption>
标记内的< extraargs>
部分。以下(略有不同的版本)适用于我。
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.
<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>
或者,创建一个文件 service-options
在 src / com / server / cxf / code-generation /
中,内容 -p com.name.server.cxf
Alternatively, create a file service-options
in src/com/server/cxf/code-generation/
with the content -p com.name.server.cxf
这篇关于使用Maven从WSDL生成Java时指定包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!