How to generate SOAP stubs in Java? - java

It's the first I am working with SOAP interface.
I have WSDL that I suppose to generate stub classes from.
I use axistools-maven-plugin but not all classes were generated. For instance, ConnectWithToken wasn't present into generated stubs.
My pom.xml plugins section:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>${axis.version}</version>
<configuration>
<urls>
<url>https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL</url>
</urls>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<subPackageByFileName>true</subPackageByFileName>
<verbose>true</verbose>
<allElements>true</allElements>
<indentSize>4</indentSize>
</configuration>
</plugin>
</plugins>
Is it the way for me to generate all classes specified into wsdl using above plugin?

My solution was to change SOAP class generator provider. QA helped a lot but I had to adopt solution based on the jaxws-maven-plugin plugin documentation and project.
pom.xml dependencies section:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
pom.xml build section:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>generate-source-by-wsdl</id>
<goals>
<goal>wsimport</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
<wsdlUrls>
<wsdlUrl>https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL</wsdlUrl>
</wsdlUrls>
<sourceDestDir>src/main/java</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Related

Proper Lifecycle Order For Annotation Processing In Maven

I'm currently working on a java project where I need to generate and compile JPA metamodel classes as part of the build. I did some research and found an answer here: Generate the JPA metamodel files using maven-processor-plugin - What is a convenient way for re-generation? that seems like a reasonable solution. The problem is, my project also contains some groovy classes that need to be compiled alongside the java. If I enable the maven-processor-plugin, the maven build will fail as soon as it encounters a java class that depends on a groovy class. Looking at the console output, I can see that maven-processor-plugin is running before the groovy compiler, so those groovy classes have not had a chance to be compiled.
Does anyone know if there is a good way to handle this? Is there some way to break the compilation process up into stages so that I can control what gets processed when?
Here is a snippet of my pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showWarnings>false</showWarnings>
<compilerId>groovy-eclipse-compiler</compilerId>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>3.6.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>3.0.7-02</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5-jdk8</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.13.Final</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/../src/main/generated-sources/java/jpametamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After a good bit of trial and error I finally found a solution that seems to work. maven-processor-plugin can use include/exclude filters to limit the scope of the files it looks at. I added an includes filter that restricts the processing to my domain classes. Now when I build it can process my annotated classes without getting hung up on the groovy files.
My final result ended up looking like this:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5-jdk8</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<includes>
<include>com/tura/product/domain/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.13.Final</version>
</dependency>
</dependencies>
</plugin>

Maven wsdl import. How to use the generated files?

i have a problem and I'm not able to solve or understand the hole workflow behind this process.
I use eclipse with maven.
This is my simple test pom.xml
...
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<xdebug>true</xdebug>
<verbose>true</verbose>
<keep>true</keep>
<packageName>abc.model</packageName>
<sourceDestDir>${project.build.directory}/generated-sources/wsimport/</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/wsimport/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
The jaxws-maven-plugin generate the files in the sourceDestDir. The build-helper-maven-plugin add the files during the maven install process the to the correct folder and also into the resulting jar file. So far so good.
But I'm not able to use the generated files/classes in eclipse. So in eclipse maven does not recognize the files as source or does not but this in the source path. Did I make an mistake or did I miss something?
Thanks for your help.
Update:
I observer a strange behavior. Same test project same pom file. If I import this existing Maven Project in eclipse it works like expected. I can directly use the generated files as source.
But if I delete this source folder, I'm still not able to restore this with maven.

How to ignore a particular goal defined inside pom.xml?

I am defining a goal inside my pom.xml. There is a condition when I want the goal not to be executed. My pom.xml is:
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<wsdlFile>src/main/resources/myWsdl.wsdl</wsdlFile>
<databindingName>xmlbeans</databindingName>
<unpackClasses>true</unpackClasses>
<packageName>com.example.client</packageName>
<flattenFiles>true</flattenFiles>
<outputDirectory>src/main/java</outputDirectory>
<action>
<ignore/>
</action>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
I tried using tag but it didnt work.
How can I make my pom.xml to skip this particular goal?
(I can't comment yet so I'm posting this as an answer)
As khmarbaise said, you should try using profiles for this.
Take a look at a similar question here.
You can use a profile like this:
<profiles>
<profile>
<id>my-profile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<wsdlFile>src/main/resources/myWsdl.wsdl</wsdlFile>
<databindingName>xmlbeans</databindingName>
<unpackClasses>true</unpackClasses>
<packageName>com.example.client</packageName>
<flattenFiles>true</flattenFiles>
<outputDirectory>src/main/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This can be activated in relationship with maven like this:
mvn -Pmy-profile clean package
If you don't specify the -Pmy-profile the execution of the plugin will not executed.

No JAXB Classes Generated from xsd using Maven Plugin

am not able see any of jaxb classes generated from my xsd using jaxb2-maven-plugin
<bulid>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/xsd</schemaDirectory>
<sourceGenerationDirectory>target/sources</sourceGenerationDirectory>
<classGenerationDirectory>target/classes</classGenerationDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</bulid>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
</dependency>
and i ran my pom by giving
clean install generate:generate is that a correct way ? please suggest a way to generate jaxb classes
i even tried to run by mvn generate-sources nothing is getting generated
This has worked for me at some point in time; you can work from there:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<removeOldOutput>false</removeOldOutput>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<includeBindings>
<includeBinding>*.xjb</includeBinding>
</includeBindings>
</configuration>
</plugin>
The plugin is bound to the generate-sources phase.
Cheers,
i just changed my goal to xjc and mvn jaxb2:xjc it worked i was able to get the jxb classes generated

Customize package for QueryDSL output

I am creating QueryDSL objects for MongoDB using Maven, here's the build xml,
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/java</outputDirectory>
<!-- This processor uses the Spring MongoDB annotations for processing -->
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
</configuration>
</plugin>
</plugins>
</build>
But its generating the query class QDomain for Domain in the same package as Domain.
Can the plugin be customized to put Query classes in a separate package?
You can use the querydsl.packageSuffix APT option to add a suffix to your generated package. Just add the following block inside configuration
<options>
<querydsl.packageSuffix>.query</querydsl.packageSuffix>
</options>

Categories