maven wsdl2java configuration not working properly - maven

I am looking to execute wsdl2java via maven and have tried several different methods with no full success. The first way I was doing it:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.apache.axis.wsdl.WSDL2Java</mainClass>
<arguments>
<argument>-client</argument>
<argument>-o</argument>
<argument>gensrc</argument>
<argument>wsdl/JobAPIWebWrapped.wsdl</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
This version will create the exact structure that I am looking for due to the call to org.apache.axis.wsdl.WSDL2Java, but will not continue with any other maven plugins beyond that. It ends the log with executing main or something to that effect.
The other method I have tried:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>gensrc</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>wsdl/JobAPIWebWrapped.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with this execution is that it generates a lot more java files than the previous execution stated higher up. I have checked the compatibility of this larger fileset and found it will work fine, but would like to find a way to force it to execute with the same java class as the first example. This version will, however, complete and allow me to move on to the following plugins called by maven.
Third:
<plugin>
<groupId>org.apache.axis</groupId>
<artifactId>wsdl2java-maven-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<implementationClassName>org.apache.axis.wsdl.WSDL2Java</implementationClassName>
</configuration>
</execution>
</executions>
</plugin>
This version isn't even being recognized... wondering if I am calling the plugin incorrectly because it isn't even showing up anywhere with verbose logging.
I have been searching quite a bit and have yet to find a successful answer. I am very close to just writing a shell script to run the maven set-up by calling the first example then moving on. Any help is greatly appreciated. Thanks.

Instead of using the exec-maven-plugin invoking WSDL2Java, you should use axistools-maven-plugin. Your pom would look like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<wsdlFiles>
<wsdlFiles>wsdl/JobAPIWebWrapped.wsdl</wsdlFiles>
</wsdlFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
By the way, Apache Axis is quite old and broken. You should think about moving to Apache CXF which is more recent and more robust.

I gave in and ended up using the antrun plugin for maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<java classname="org.apache.axis.wsdl.WSDL2Java" fork="true">
<arg value="-client"/>
<arg value="-o"/>
<arg value="gensrc"/>
<arg value="wsdl/JobAPIWebWrapped.wsdl"/>
<classpath refid="maven.compile.classpath"/>
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Related

Is it possible to generate multiple HTML reports with different configuration after the same execution? jmeter-maven-plugin

I'm using jmeter's maven plugin and I would like to generate two different HTML reports from the same execution log. Is it even possible to do this using this plugin?
This is my pom.xml and I'm not sure how to create a second report with a different output folder and title for example.
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter.plugin.version}</version>
<executions>
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<propertiesUser>
<thread.number>${thread.number}</thread.number>
<rampup>${rampup}</rampup>
<jmeter.reportgenerator.report_title>CA Dashboard</jmeter.reportgenerator.report_title>
</propertiesUser>
<ignoreResultFailures>true</ignoreResultFailures>
<generateReports>true</generateReports>
</configuration>
</plugin>
</plugins>
</build>
Currently no, the report generation happens at the same time the test is run.
When the following issues have been fixed it may be an option:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/328
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/391
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/316

Mockserver maven plugin: init mockserver expectations from file

I'm using Mockserver maven plugin to mock some requests for integration tests.
My pom.xml looks like:
...
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationClass>com.mycompany.ExampleInitializationClass</initializationClass>
</configuration>
<executions>
<execution>
<id>run-mockserver</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-mockserver</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
Problem here is that I have to provide expectations using a class (com.mycompany.ExampleInitializationClass) and I want to provide expectations using a JSON file like described here:
http://www.mock-server.com/mock_server/initializing_expectations.html
I didn't find any way in the plugin configuration to initialize the Mockserver with the property:
-Dmockserver.initializationJsonPath
Is there any way to achieve that? Thanks in advance.
You just have to define initializationJson property specifying path to JSON file with expectations:
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationJson>expectations.json</initializationJson>
</configuration>
<executions>
...
</executions>
</plugin>
The catch here is that the file path is relative to testClasspath directory (e.g. ${project.basedir}/target/test-classes/), so you have to copy the expectation file there. You may use e.g. maven-antrun-plugin for this (as below) or
maven-resources-plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="your/expectations.json" todir="${project.basedir}/target/test-classes/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

Pad Number With Zeros in Maven

Is there a way to have maven pad a numeric value (ex: build number) within a POM? I've been googling the topic and haven't come up with anything yet.
My use case is as follows. The maven build process is provided a build number via Jenkins which needs to be included as part of the name of the WAR that is generated. So if I provide it 12 as the build number, then I want the WAR file name to be myWar##000012.war. The ##000012 part of the name is the version identifier used by Tomcat.
The simplest solution may be to embed a scripting language in your build. For example, with Groovy, if you have a buildNumber property:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals><goal>execute</goal></goals>
<configuration>
<source>
project.properties['nameSuffix'] = "##" + String.format("%06d", project.properties['buildNumber'].toLong());
</source>
</configuration>
</execution>
</executions>
</plugin>
Afterwards the nameSuffix property is available to define the final name.
Alternatively, as suggested in In Maven, how can I dynamically build a property value at runtime?, use build-helper:regex-property to transform the string.
Have you tried using the maven release plugin?
Based upon #Joe suggestion I looked into the build-helper-maven-plugin and was able to come up with the following which does what I need. I wasn't able to identify how to do it all in one step, so I'm doing it in 2. The first step pads the value on the left with zeros. The second step trims the numeric value so that it is only 7 digits long. Please note that ${build.env.version} is passed in as a parameter to the maven build process and that I have defaulted it to 0 in the POM file for when it isn't passed. If you don't provide a default value then the build fails even though failOnError on set to false.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>stage1--padNumber</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>build.env.version.padded</name>
<value>${build.env.version}</value>
<regex>^([\d]{0,})$</regex>
<replacement>000000$1</replacement>
<failIfNoMatch>false</failIfNoMatch>
<failOnError>false</failOnError>
</configuration>
</execution>
<execution>
<id>stage2--leftTrimToXcharacters</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>build.env.version.padded</name>
<value>${build.env.version.padded}</value>
<regex>^([\d]*)([\d]{7})$</regex>
<replacement>$2</replacement>
<failIfNoMatch>false</failIfNoMatch>
<failOnError>false</failOnError>
</configuration>
</execution>
</executions>
</plugin>
Based upon #jwmajors81 suggestion, I needed to pad the major version for a specific reason...
As we were already using the build-helper-maven-plugin, it is easy enough to get the major version by using the parse-version goal of the build helper. (we only needed 3 chars):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
<execution>
<id>stage1--padNumber</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>build.env.version.padded</name>
<value>${parsedVersion.majorVersion}</value>
<regex>^([\d]{0,})$</regex>
<replacement>00$1</replacement>
<failIfNoMatch>false</failIfNoMatch>
<failOnError>false</failOnError>
</configuration>
</execution>
<execution>
<id>stage2--leftTrimToXcharacters</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>build.env.version.padded</name>
<value>${build.env.version.padded}</value>
<regex>^([\d]*)([\d]{3})$</regex>
<replacement>$2</replacement>
<failIfNoMatch>false</failIfNoMatch>
<failOnError>false</failOnError>
</configuration>
</execution>
</executions>
</plugin>
Yet, in that particular case, if you also need to generate a buildNumber, buildnumber-maven-plugin may be the most straight solution:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<format>{0, number,000000}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>myWar##${buildNumber}</finalName>

how to execute multiple command prompt commands using maven in single pom.xml

I want to run multiple command prompt commands in maven using single pom.xml. How can I do that?
For ex: I have 2 commands to execute. I am executing the first command by using exec-maven-plugin.
Below is the portion of my pom.xml to execute the first command:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>load files</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<arguments>
<argument>wt.load.LoadFileSet</argument>
<argument>-file</argument>
<argument>${basedir}/fileSet.xml</argument>
<argument>-UNATTENDED</argument>
<argument>-NOSERVERSTOP</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
</configuration>
</plugin>
For this the build is success.
Is it possible to execute one more command just like above in the same pom.xml? I was not able to do that. So someone please help how to add it in pom.xml
The answer can be found in the FAQ.
The full answer is here: http://article.gmane.org/gmane.comp.java.maven-plugins.mojo.user/1307
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>id1</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd1</executable>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd2</executable>
</configuration>
</execution>
</executions>
</plugin>
Then you specify execution ids as:
mvn exec:exec#id2
But this syntax is possible starting from maven 3.3.1

Maven and Exec: forking a process?

I'm trying to use Maven to start an application prior to running some integration tests on it. I'm on Windows. My Maven plugin configuration looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-my-application</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>start_application.bat</executable>
<workingDirectory>./path/to/application</workingDirectory>
</configuration>
</execution>
<executions>
<plugin>
and my batch file looks like this:
start myApplication.exe
When run in isolation, the batch file spawns a separate window to run the application and immediately returns control.
However, when run from Maven, the build waits for the process in the separate window to finish before continuing. This somewhat defeats the point of the integration testing phase...
Any ideas how I can start a truly separate process in Maven to allow the build to continue alongside it?
For the record, a rather hackish solution is to use maven-antrun-plugin to call Ant, which is capable of spawning separate processes:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<target>
<exec executable="cmd"
dir="./path/to/application"
spawn="true">
<arg value="/c"/>
<arg value="start_application.bat"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Try this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-my-application</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>call</executable>
<arguments>
<argument>start_application.bat</argument>
</arguments>
<workingDirectory>./path/to/application</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>

Resources