How to generate classes from wsdl using Maven and wsimport? - maven

When I attempt to run "mvn generate-sources" this is my output :
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gensourcesfromwsdl 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.104s
[INFO] Finished at: Tue Aug 20 15:41:10 BST 2013
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------
I do not receive any errors but there are no java classes generated from the wsdl file.
Here is my pom.xml file that I'm running the plugin against :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gensourcesfromwsdl</groupId>
<artifactId>gensourcesfromwsdl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlLocation>http://mysite/firstwsdl.asmx?wsdl</wsdlLocation>
<packageName>com</packageName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
What am I doing wrong ? The package com exists in the project 'gensourcesfromwsdl' and the wsdl location is valid.
When I run wsimport via the command line : >wsimport -keep -verbose http://mysite/firstwsdl.asmx?wsdl the class is generated.

To generate classes from WSDL, all you need is build-helper-maven-plugin and jaxws-maven-plugin in your pom.xml
Make sure you have placed wsdl under folder src/main/resources/wsdl and corresponding schema in src/main/resources/schema, run command "mvn generate-sources" from Project root directory.
C:/Project root directory > mvn generate-sources
generated java classes can be located under folder
target/generated/src/main/java/com/raps/code/generate/ws.
pom.xml snippet
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>${project.build.directory}/generated/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<configuration>
<wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
<packageName>com.raps.code.generate.ws</packageName>
<keep>true</keep>
<sourceDestDir>${project.build.directory}/generated/src/main/java</sourceDestDir>
</configuration>
<executions>
<execution>
<id>myImport</id>
<goals><goal>wsimport</goal></goals>
</execution>
</executions>
</plugin>

Here is an example of how to generate classes from wsdl with jaxws maven plugin from a url or from a file location (from wsdl file location is commented).
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<!-- usage of jax-ws maven plugin-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- using wsdl from an url -->
<wsdlUrls>
<wsdlUrl>
http://myWSDLurl?wsdl
</wsdlUrl>
</wsdlUrls>
<!-- or using wsdls file directory -->
<!-- <wsdlDirectory>src/wsdl</wsdlDirectory> -->
<!-- which wsdl file -->
<!-- <wsdlFiles> -->
<!-- <wsdlFile>myWSDL.wsdl</wsdlFile> -->
<!--</wsdlFiles> -->
<!-- Keep generated files -->
<keep>true</keep>
<!-- Package name -->
<packageName>com.organization.name</packageName>
<!-- generated source files destination-->
<sourceDestDir>target/generatedclasses</sourceDestDir>
</configuration>
</plugin>
</plugins>
</build>

Even though this is bit late response, may be helpful for someone. Look like you have used pluginManagement. If you use pluginManagement
, it will not pick the plug-in execution.
It should be under
<build>
<plugins>
<plugin>

Try to wrap wsdlLocation in wsdlUrls
<wsdlUrls>
<wsdlLocation>http://url</wsdlLocation>
</wsdlUrls>

I see some people prefer to generate sources into the target via jaxws-maven-plugin AND make this classes visible in source via build-helper-maven-plugin. As an argument for this structure
the version management system (svn/etc.) would always notice changed
sources
With git it is not true. So you can just configure jaxws-maven-plugin to put them into your sources, but not under the target folder. Next time you build your project, git will not mark these generated files as changed. Here is the simple solution with only one plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-fluent-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>som.path.generated</packageName>
<xjcArgs>
<xjcArg>-Xfluent-api</xjcArg>
</xjcArgs>
<verbose>true</verbose>
<keep>true</keep> <!--used by default-->
<sourceDestDir>${project.build.sourceDirectory}</sourceDestDir>
<wsdlDirectory>src/main/resources/META-INF/wsdl</wsdlDirectory>
<wsdlLocation>META-INF/wsdl/soap.wsdl</wsdlLocation>
</configuration>
</execution>
</executions>
</plugin>
Additionally (just to note) in this example SOAP classes are generated with Fluent API, so you can create them like:
A a = new A()
.withField1(value1)
.withField2(value2);

The key here is keep option of wsimport. And it is configured using element in
About keep from the wsimport documentation :
-keep keep generated files

i was having the same issue while generating the classes from wsimport goal. Instead of using jaxws:wsimport goal in eclipse Maven Build i was using clean compile install that was not able to generate code from wsdl file. Thanks to above example.
Run jaxws:wsimport goal from Eclipse ide and it will work

Related

NetBeans 12.6, Spring Boot / Maven, Cisco AXL Schema - Background scanning of projects

Often related to Background scanning of projects people complain that this happens when NetBeans is started.
I have a Spring Boot 2.6.x with Maven 3.8.2 project, using Cisco AXL Schema 12.5.
With Apache CXF from this AXL Schema a lot of Java source code files are generated.
When I do a Clean and Build on my project afterwards immediatly the Background scanning of projects starts.
And it takes most of the times recently quite long.
I see for example that it scans also
netbeans-12.6/webcommon/jsstubs/corestubs.zip
Why should it scan this too when building my project?
But most of the time, although it shows 100% scanning done, it spends in the folder where the generated Java source code files are
<project folder>/target/generated/cxf
There are 2282 generated Java source code files.
I'm not sure if NetBeans hangs or really scans these files, it shows 100% scanning so it should be done.
Often it takes too long so I have to terminate NetBeans from the console. After a restart of NetBeans the Background scanning for projects starts and takes much shorter time, but this is annoying.
What can I do about it?
When I start NetBeans from console I do only ./netbeans. Is there a difference if starting NetBeans with sudo ./netbeans?
Here is how my project folder/file structure looks like, maybe I don't use correctly:
First of all I extracted the AXL Schema next to my src folder
<project folder>
-> schema
-> 12.5
AXLAPI.wsdl
AXLEnums.xsd
AXLSoap.xsd
-> src
-> main/...
-> test/...
In pom.xml I use
...
<build>
...
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.4.5</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/schema/12.5/AXLAPI.wsdl</wsdl>
<wsdlLocation>classpath:schema/12.5/AXLAPI.wsdl</wsdlLocation>
<extraargs></extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
...
<resources>
...
<resource>
<directory>./</directory>
<includes>
<include>schema/**</include>
</includes>
</resource>
<resource>
<directory>target/generated/cxf</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
...
</resources>
</build>
...
Maybe this pom.xml setup is not correct, and that's why the Background scanning for projects works wrongly.
When I look into the resulting war file after build, I see
WEB-INF
-> classes
-> com/cisco/axl/api/_12
-> schema/12.5
and there are artifacts which might not belong there.
For example in com/cisco/axl/api/_12 there are not only the class files but all related generated Java source code files (all 2282).
And perhap schema/12.5 shouldn't be in the war file too.
I tried this pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>cxf</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.4.5</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/CustomerService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</project>
(Latest cxf-codegen-plugin, no additional config, wsdl file from here, java ee dependencies)
Running mvn clean install ("Clean and Build Project"...takes less than 5 seconds with this wsdl), and gets us:
..this nice picture (resolution of generated sources! grouped by provider (cxf)...we could have more).
Conclusion
Netbeans is mature regarding "generated sources". (As long as they are in target/generated-sources/<provider>;).
With "generated projects" (maven/gradle e.g. openapi-plugin) on the other hand, I experienced (netbeans) issues...and had to externalize/"source control" the "generated stuff" (/project!).
Don'ts
build>resources>resource>directory>. This will(try to) package your project root (additionally) to target/classes!! (This may confuse any IDE.)
...>resource>directory>target, for similar reasons esp. in Netbeans.
Hints
When we want the schemas & definitons to reside in (packaged) class path, we place them within src/main/resources. Otherwise: outside.
We add <resources/> to our <build/>, only when we decided so/know what we do/don't create "circles" (with existing maven-defaults), notto "trick netbeans"! (this is out-dated;)
Update:
I updated same project with this wsdl (axl-demo/schema).
It generated 1647 classes.
Netbeans took a while to scan:
I increased memory:
{nb_home}/etc/netbeans.conf:
netbeans_default_options="-J-Xmx4g ..."
(thx to: How to assign more memory to Netbeans? , ...)
(Restarted netbeans,) drank coffee
But then (once scan was completed): Still "nice picture", we can import/declare/use the generated classes:
Some Tweaks
..Yoda added to the build:
moved cxf-execution to profile:
<profiles>
<profile>
<id>gen</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
...
to activate it (only) with mvn install -Pgen (or in netbeans (Project>Properties>Run>) Configuration(drop-down)).
applied this: How to protect auto-generated sources during clean package in maven? like:
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.build.directory}</directory>
<excludes>
<exclude>generated-sources/**</exclude>
<exclude>classes/com/cisco/**</exclude>
</excludes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
I don't agree with "recommended solution"! For "thousands of" classes that b/rarely change, who wants to clean & re-generate them "hundreds" times/day?
Which accelerates us from (mvn -Pgen clean install):
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 44.515 s
To "Project>Clean and Build" (mvn clean install):
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 4.494 s

Using build-helper-maven-plugin

I have the pom.xml below.
I'd like to pass a tag property to my build, using this command:
mvn clean package -Dtag=test
It should split this property into two others, my.group an my.version, and then use it in a URI to build an XLDeploy package, using the xldeploy-maven-plugin (https://docs.xebialabs.com/xldeploy-maven-plugin/6.0.x/).
My problem is that the regex-properties goal is actually doing the job, as I can see thanks to the maven-antrun-plugin:
[INFO] --- maven-antrun-plugin:1.1:run (default) # myArtifactId ---
[INFO] Executing tasks
[echo] Displaying value of 'my.group' property
[echo] [my.group] group/test
[echo] Displaying value of 'my.version' property
[echo] [my.version] test
But the command grep fileUri target\deployit-working-dir\deployit-manifest.xml show that the vars in Uri does not get replaced:
grep fileUri target\deployit-working-dir\deployit-manifest.xml
<fileUri>http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-1.0.zip</fileUri>
The POM is the following file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>1.0</version>
<packaging>dar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>regex-properties</id>
<goals>
<goal>regex-properties</goal>
</goals>
<configuration>
<regexPropertySettings>
<regexPropertySetting>
<name>my.group</name>
<value>group/${tag}</value>
<regex>(asm-[0-9]+)-([0-9]+.[0-9]+)-([0-9]+)$</regex>
<replacement>$1</replacement>
<failIfNoMatch>false</failIfNoMatch>
</regexPropertySetting>
<regexPropertySetting>
<name>my.version</name>
<value>${tag}</value>
<regex>(asm-[0-9]+)-([0-9]+.[0-9]+)-([0-9]+)$</regex>
<replacement>$1-SNAPSHOT</replacement>
<failIfNoMatch>false</failIfNoMatch>
</regexPropertySetting>
</regexPropertySettings>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Displaying value of 'my.group' property</echo>
<echo>[my.group] ${my.group}</echo>
<echo>Displaying value of 'my.version' property</echo>
<echo>[my.version] ${my.version}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.xebialabs.xldeploy</groupId>
<artifactId>xldeploy-maven-plugin</artifactId>
<version>6.0.0</version>
<extensions>true</extensions>
<configuration>
<deployables>
<file.Folder name="file">
<scanPlaceholders>false</scanPlaceholders>
<fileUri>http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-${project.version}.zip</fileUri>
</file.Folder>
</deployables>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm not quite sure if the build-helper-maven-plugin wrong, or anywhere else in my POM, or if it's simply lack of replacing properties in the xldeploy-maven-plugin...
Thanks for the help ;)
I checked the source of xldeploy-maven-plugin-6.0.1, and it seems it is the limitation of the current implementation.
The problem is that GenerateDeploymentPackageMojo does not rely on maven to do the substitution of the properties. Instead, it uses a custom AbstractConfigurationConverter named DeployitCIConverter (which delegates to MavenDeployableConverter) to convert the <deployables> node to a list of MavenDeployable)
This boils down to:
you have the access to effective POM
you don't have access to properties defined dynamically via build helper plugin
Of course the properties defined dynamically can be acessed in any mojo:
if you use a parameter
if you evaluate them manually via expression evaluator (check: get mojo parameters in maven plugin)
For the antrun plugin, it uses ExpressionEvaluator explicitely in the echo task.
Informative article:
Properties resolution in Maven and its implications on Antrun plugin
Ideas to fix the problem:
do your group and version parsing in external script and pass the values to mvn command.
create a cutom mojo extending GenerateDeploymentPackageMojo and preprocess deployables in the execute method (not that hard as it sounds).

How does maven decide when to use the target folder for classpath

I have a question regarding how maven calculates the classpath during building. Specifically, what controls when the "target/classes" is used and when the "jar" from a repository (local/remote) is used.
I have a project on version 1.0.0-SNAPSHOT where the artifacts have NOT been installed/deployed so there is no "jar" in some repository (remote or local) to resolve them. I want to run "generate-sources" WITHOUT installing locally (no 'mvn install' run).
The structure looks like this:
parent-prj
parent-prj/sub-prj
parent-prj/gen-src-prj <--- This depends on 'sub-prj'
When I run "mvn -am -pl parent-prj/gen-src-prj generate-sources" in order to just generate some java files, it does not work:
[ERROR] Failed to execute goal on project gen-src-prj: Could
not resolve dependencies for project
mygrp:gen-src-prj:jar:1.0.0-SNAPSHOT:
Could not find artifact
mygrp:sub-prj:jar:1.0.0-SNAPSHOT -> [Help 1]
Using debug output and adding "dependency:build-classpath" I can confirm that maven ignores the presence of "sub-prj" in the reactor and looks for a "jar" somewhere which it can't find. Yet the project is printed in the reactor summary:
[INFO] Reactor Summary:
[INFO]
[INFO] parent-prj ..................................... SUCCESS [ 0.625 s]
[INFO] sub-prj ........................................ SUCCESS [ 0.018 s]
[INFO] gen-src-prj .................................... FAILURE [ 0.040 s]
The interesting thing I noticed is that running the compile goal works fine! This uses sub-prj/target/classes (as shown by dependency:build-classpath) and has no trouble generating the sources and even compiling them: "mvn -am -pl parent-prj/gen-src-prj compile"
So here are the points I want to understand:
Why does the compile goal work but the generate-sources doesn't work?
At what point does maven decide to use the output folder of previous projects on the reactor classpath instead of looking for a jar?
Is there a way for generate-sources to run directly as I want it EVEN WITHOUT having its dependencies resolved?
Regarding (3) my generation tool is a utility invoked by:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
The tool reads some XML in src/main/resources and generates Java files and does NOT need anything in its class-path (so there is no need for maven to resolve it).
Also note that I would be interested to understand (1) and (2) even if a solution for (3) is provided.
EDIT: Per comment request, adding full example
parent-prj/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sub-prj</module>
<module>gen-src-prj</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.9</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
parent-prj/sub-prj/pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>sub-prj</artifactId>
</project>
parent-prj/gen-src-prj/pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>gen-src-prj</artifactId>
<dependencies>
<dependency>
<groupId>mygrp</groupId>
<artifactId>sub-prj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>uk.co.real_logic.sbe.SbeTool</mainClass>
<systemProperties>
<systemProperty>
<key>sbe.output.dir</key>
<value>${project.build.directory}/generated-sources/java</value>
</systemProperty>
<systemProperty>
<key>sbe.validation.warnings.fatal</key>
<value>true</value>
</systemProperty>
</systemProperties>
<arguments>
<argument>${project.build.resources[0].directory}/Examples.xml</argument>
</arguments>
<workingDirectory>${project.build.directory}/generated-sources/java</workingDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>uk.co.real-logic</groupId>
<artifactId>sbe-tool</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
EDIT: Armed with the knowledge from the answers I have come up with this workaround that allows one to achieve the desired behaviour. I list the dependencies in a profile that is active by default, then use another profile to run generate-sources with no dependencies active, like follows:
parent-prj/gen-src-prj/pom.xml
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>mygrp</groupId>
<artifactId>sub-prj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>excludeDependency</id>
<dependencies>
</dependencies>
</profile>
</profiles>
To generate sources with above, use: mvn -PexcludeDependency generate-sources
Maven can reference only output generated in current Session (during currently executing shell command). It uses the most "mature" place to look for the "output":
If compile is run - the classes end up in the target/classes dir, thus other modules can reference that
If package is run - then target/*.jar is created and this jar file ends up in the classpath instead
If install is run - then jar file ends up in the local repository - which is what ends up on the classpath
So there are 3 factors that impede your task:
maven-exec-plugin requires dependency resolution (as pointed out by #mondaka)
Your module1 references module2
generate-sources is run before the compilation. Thus module2 is not yet prepared to be used as a dependency.
So if you want to do it your way - you'll have to run at least compile phase each time you use anything from the Default Lifecycle. Or you could write your own plugin that doesn't require dependency resolution.
This problem is related to an open maven bug:
https://issues.apache.org/jira/browse/MNG-3283
The issue says: "The problem only occurs when a plugin binds itself to the
generate-sources phase and has #requiresDependencyResolution".
I have checked that exec-maven-plugin Mojo have indeed requiresDependencyResolution = ResolutionScope.TEST. You can see that on https://github.com/mojohaus/exec-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java
Then, your only option is to use compile or process-classes phases. This is a Major open bug from 2007...

Jmeter Maven 2.1.0- Error in NonGUIDriver java.lang.IllegalArgumentException

This question was attempted to be answered here in this post:
Jmeter- Error in NonGUIDriver java.lang.IllegalArgumentException
but the solution didn't work, was wondering if anyone else had another solution or can clarify the solution...
I'm trying to run Jmeter Maven plugin (version 2.1.0) to run my Jmeter script which was written in version 3.1 of Jmeter. I followed all of the instructions mentioned here https://github.com/jmeter-maven-plugin/jmeter-maven-plugin to create the pom.xml file.
when i execute the following maven command:
mvn clean verify -Denv=prod -Djmx.filename={the_name_of_my_jmx_file}
i get the following 2 errors:
1
[INFO] Invalid value detected for <postTestPauseInSeconds>. Setting pause to 0...
2
[INFO] Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from: {path to my jmx file} missing class com.thoughtworks.xstream.converters.ConversionException:
[INFO] ---- Debugging information ----
[INFO] cause-exception : com.thoughtworks.xstream.converters.ConversionException
[INFO] cause-message :
[INFO] first-jmeter-class : org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67)
[INFO] class : org.apache.jmeter.save.ScriptWrapper
[INFO] required-type : org.apache.jorphan.collections.ListedHashTree
[INFO] converter-type : org.apache.jmeter.save.ScriptWrapperConverter
[INFO] path : /jmeterTestPlan/hashTree/hashTree/hashTree/hashTree[2]/kg.apc.jmeter.reporters.LoadosophiaUploader
[INFO] line number : 2051
[INFO] version : 3.1 r1770033
the pom.xml file i'm using is here:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.company.testframework</groupId>
<artifactId>test-project-performance</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Performance test script for project</name>
<properties>
<jmeter.version>3.1</jmeter.version>
<jmeter.maven.plugin>2.1.0</jmeter.maven.plugin>
<!-- <jmeter.maven.plugin>1.10.1</jmeter.maven.plugin> -->
<jmeter.plugins.standard>1.1.3</jmeter.plugins.standard>
<jmeter.plugins.extras>1.3.1</jmeter.plugins.extras>
<!-- <jmeter.plugins.extras>1.4.0</jmeter.plugins.extras> -->
<env>prod</env>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/test/resources/conf/${env}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter.maven.plugin}</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<jmeterVersion>${jmeter.version}</jmeterVersion>
<resultsFileFormat>xml</resultsFileFormat>
<testResultsTimestamp>false</testResultsTimestamp>
<suppressJMeterOutput>false</suppressJMeterOutput>
<ignoreResultFailures>false</ignoreResultFailures>
<overrideRootLogLevel>INFO</overrideRootLogLevel>
<downloadExtensionDependencies>false</downloadExtensionDependencies>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins:pom:1.3.1</artifact>
</jmeterExtensions>
<propertiesUser>
<environment>${env}</environment>
<jtl_file_name>${jmx.filename}.jtl</jtl_file_name>
<project_build_directory>${project.build.directory}</project_build_directory>
<!-- Project Specific Properties -->
<main_threads>${main.threads}</main_threads>
<rampup_seconds>${rampup.seconds}</rampup_seconds>
<duration_seconds>${duration.seconds}</duration_seconds>
<host_url>${host.url}</host_url>
<user_name>${user.name}</user_name>
<user_password>${user.password}</user_password>
<offer_id>${offer.id}</offer_id>
</propertiesUser>
<propertiesJMeter>
<jmeter.save.saveservice.autoflush>true</jmeter.save.saveservice.autoflush>
<jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
<jmeter.save.saveservice.assertion_results_failure_message>false</jmeter.save.saveservice.assertion_results_failure_message>
<jmeter.save.saveservice.data_type>true</jmeter.save.saveservice.data_type>
<jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
<jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
<jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
<jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
<jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>
<jmeter.save.saveservice.assertions>true</jmeter.save.saveservice.assertions>
<jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
<jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
<jmeter.save.saveservice.url>true</jmeter.save.saveservice.url>
<jmeter.save.saveservice.thread_counts>false</jmeter.save.saveservice.thread_counts>
<jmeter.save.saveservice.sample_count>false</jmeter.save.saveservice.sample_count>
<jmeter.save.saveservice.timestamp_format>ms</jmeter.save.saveservice.timestamp_format>
<jmeter.save.saveservice.timestamp_format>yyyy/MM/dd HH:mm:ss.SSS</jmeter.save.saveservice.timestamp_format>
<httpclient4.retrycount>3</httpclient4.retrycount>
<httpsampler.await_termination_timeout>60</httpsampler.await_termination_timeout>
<http.socket.timeout>20000</http.socket.timeout>
</propertiesJMeter>
<testFilesIncluded>
<jMeterTestFile>${jmx.filename}.jmx</jMeterTestFile>
</testFilesIncluded>
</configuration>
<dependencies>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-standard</artifactId>
<version>${jmeter.plugins.standard}</version>
</dependency>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-extras-libs</artifactId>
<version>${jmeter.plugins.extras}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
According to Adding additional libraries to the classpath
You can add any additional Java libraries to JMeter's lib/ext directory by using the configuration element. This uses the Eclipse Aether libraries to perform dependency resolution.
So it should be enough to do the following:
<configuration>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins:pom:1.3.1</artifact>
</jmeterExtensions>
</configuration>
Your manual dependency adding via dependencies section is not required, moreover you specified version 1.1.3 in dependencies and version 1.3.1 in jmeterExtensions
Finally, your uploader won't work as it has been superseded with the BM.Sense Uploader therefore I would recommend switching to plugin version 1.4.0.

Unable to compile and create .avro file from .avsc using Maven

I'm new to Maven and have been looking at tutorials and web for documentation on how to build a .avro from a schema file .avsc. Based on the documentation that on the apache.maven.org site. I have to add the following
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.5</version>
</dependency>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.7.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I've added the same into my POM.xml file. I have 2 schema files (.avsc) and following is my directory structure with contents
ProjectDir
src
main
java
avrò
abc.avsc
resources
test
pom.xml
My POM.xml is
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.training</groupId>
<artifactId>TestAvro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestAvro</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.basedir>/Users/vsank2/TestAvro</project.basedir>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-compiler</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.7.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugin</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I executed the following
mvn clean generate-sources and I get the following output
INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestAvro 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # TestAvro ---
[INFO] Deleting /Users/vsank2/TestAvro/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.514s
[INFO] Finished at: Mon Dec 23 16:08:51 PST 2013
[INFO] Final Memory: 2M/81M
[INFO] ------------------------------------------------------------------------
Appreciate any help in this regard. thank you
After a lot of research I found that the problem was completely with my .avsc JSON problem. The "namespace" was totally wrong. As soon as I fixed it. The maven avro plugin created the java class from the schema.
First of it is not the JSON issue. Issue occurred due to addition of tag in t he pom.xml
Points to note :
defines the settings for plugins that will be inherited by child modules in your build. This tag is not required until it is parent POM.
i.e tag is used to manage plugin in child modules.
So no need to add the tag in pom.xml.
If there is any error "Plugin execution not covered by lifecycle configuration" then it is because of the older avro version try to look for latest version it will resolve the issue.
for anyone else that has has the issue.
Also if your configuration is being ignored then moving the configuration block under the plugin section works. It worked for me on the version 1.11.0. I found the fix in this stackoverflow.
Apache Avro maven plugin seems to be ignoring config
Also this github repo is very useful for testing out making a avro file in to java file. there is no custom configuration in it though which you can add yourself.
https://github.com/alexholmes/avro-maven
Also I found this command very useful for debugging f directories do not exist when it is producing the files. It tells you the exact problem.
mvn -X avro:schema

Resources