Issue
I am working on a project with separate sub modules for backend and frontend and some other sub modules too. Currently, both these modules have their own copies of wsdl files and generate java files using maven plugin.
I want a single copy of the wsdl files so want to create a maven submodule with these wsdl files. I want the frontend and bakcend modules to use the wsdl files from that submodules to generate java files. Currently, I have the following in my pom file to generate java source files when using wsdl from the same module.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.4.4</version>
<executions>
<execution>
<id>wsdl1</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/ABC.wsdl</wsdl>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>com.xxxx.yyy.zzzzz.abc</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin
How can I do this?
Solution
I could do it in 2 ways. And both of these work fine. For both the approaches, I first created another sub module and moved all the wsdl files there.
- Use maven-resources-plugin to first copy the wsdl files to each of the services and ui module. And no other change was required in my pom.xml files
<plugin> <artifactId>maven-resources-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId> <version>3.2.0</version> <executions> <execution> <id>copy-wsdl</id> <phase>generate-sources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.basedir}/src/main/resources/wsdl</outputDirectory> <overwrite>true</overwrite> <resources> <resource> <directory>../common/src/main/resources/wsdl</directory> <includes> <include>*.wsdl</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
- Another way is to just refer the wsdl file from the common location while generating the java code
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>3.4.4</version> <executions> <execution> <id>wsdl1</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${project.build.directory}/generated-sources</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>../common/src/main/resources/wsdl/ABC.wsdl</wsdl> <extraargs> <extraarg>-p</extraarg> <extraarg>com.xxxx.yyy.zzzzz.abc</extraarg> <extraarg>-verbose</extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin>
Answered By - user2101
Answer Checked By - David Marino (JavaFixing Volunteer)