23

Imagine this scenario.

I have a wsdl file with namespace a/b/c and it imports another wsdl whose namespace is m/n/o. Unfortunately, both of them have same ComplexTypes XYZ defined in them. Now, when I use cxf-codegen-plugin to generate Java code and use custom package name "com.qsrs.uvw", only one class is retained in the final code that is generated. Can someone help me out here?

Gopal
  • 1,292
  • 3
  • 19
  • 41

2 Answers2

61

If you want to generate package depending on the namespace here is the solution:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>2.6.0</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>yourWsdl.wsld</wsdl>
                        <extraargs>
                            <extraarg>-client</extraarg>
                            <extraarg>-verbose</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>http://your.namespace/services/=your.package</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>http://your.namespace2/services2/=your.package2</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This <extraarg>http://your.namespace2/services2/=your.package2</extraarg> will map your namespace with the package you want.

Betlista
  • 10,327
  • 13
  • 69
  • 110
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143
  • 3
    thanks for the response. Can you please let me know if it is possible to specify a prefix to all the packages that are generated? – Gopal Sep 27 '12 at 06:44
  • What do you mean prefix for packages? – Paulius Matulionis Sep 27 '12 at 07:52
  • @Paulius..Imagine I allow JibX to respect schema, I want all the package generated to be under a root package jibx.x.y.z. The actual problem is I have a cxf-code-gen plugin generating code using same schema. So effectively I have two classes with same package structure and name. Hence, I want to place all the classes generated by jibx under a different root. – Gopal Sep 27 '12 at 08:00
  • 2
    best solution. almost worried there when it didn't work but it was because of the `/` before the `=`. The pattern is `namespace=desired_package` – cosmincalistru Feb 20 '15 at 18:22
0

You can use the packagenames configuration, too:

<wsdlOption>
    <wsdl>yourWsdl.wsld</wsdl>
    <extraargs>
        <extraarg>-client</extraarg>
        <extraarg>-verbose</extraarg>
    </extraargs>
    <packagenames>
        <packagename>http://your.namespace/services/=your.package</packagename>
        <packagename>http://your.namespace2/services2/=your.package2</packagename>
    </packagenames>
</wsdlOption>

I use the version 3.5.5 of cxf-codegen-plugin

RoBeaToZ
  • 1,113
  • 10
  • 18