Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying Package Name When Using Maven to Generate Java from WSDL

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.

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?

like image 300
crdzoba Avatar asked Mar 21 '12 18:03

crdzoba


People also ask

How to Generate Java objects from WSDL?

You can use the JAX-WS tool, wsimport, to process a WSDL file and generate portable Java artifacts that are used to create a web service. The portable Java artifacts created using the wsimport tool are: Service endpoint interface (SEI) Service class.

What is Cxf codegen plugin?

CXF includes a Maven plugin which can generate java artifacts from WSDL. Here is a simple example: < plugin > < groupId >org.apache.cxf</ groupId > < artifactId >cxf-codegen-plugin</ artifactId >


2 Answers

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>

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

like image 63
aliasmrchips Avatar answered Sep 30 '22 20:09

aliasmrchips


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>
like image 26
rresino Avatar answered Sep 30 '22 19:09

rresino