Unable to compile and create .avro file from .avsc using Maven - 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

Related

Dependency is missed in output after maven-assembly-plugin executed

I have a problem using maven-assembly-plugin.
I want to get during package phase a directory with all project dependencies.
But I have a transitive dependency with compile scope which is missed from
assembly output directory.
The missed jar is batik-js-1.7.jar. Here is a dependency tree for this jar
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # sbercap-dependencies ---
[INFO] ru.spi2.test:sbercap-dependencies:jar:1.0-SNAPSHOT
[INFO] \- org.apache.xmlgraphics:batik-transcoder:jar:1.7:compile
...
[INFO] +- org.apache.xmlgraphics:batik-bridge:jar:1.7:compile
[INFO] | +- org.apache.xmlgraphics:batik-anim:jar:1.7:compile
[INFO] | +- org.apache.xmlgraphics:batik-css:jar:1.7:compile
[INFO] | +- org.apache.xmlgraphics:batik-ext:jar:1.7:compile
[INFO] | +- org.apache.xmlgraphics:batik-parser:jar:1.7:compile
[INFO] | +- org.apache.xmlgraphics:batik-script:jar:1.7:compile
[INFO] | | \- org.apache.xmlgraphics:batik-js:jar:1.7:compile
...
When assembly plugin is finished, others dependencies (batik-anim-1.7.jar,
batik-css-1.7.jar) are added to output directory successfully. The batik-js-1.7.jar
is missed (screenshot attached).
On the other side, if I try to copy all dependencies using maven-dependency-plugin,
the batik-js-1.7.jar is successfully added to the folder (screenshot
attached).
Here is my dependencies and build blocks from pom.xml
<dependencies>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/dependency-libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly-descriptor.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
The assembly descriptor is
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>assembly</id>
<formats>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
</dependencySet>
</dependencySets>
</assembly>
Could you explain me, am I doing something wrong? Why this library is missed
from assembly output?
I tried to find any similar problem in google but there were another problems -
dependency from test scope or missed dependency in pom.xml. Dependency set
useTransitiveDependencies property is true by default, so I don't really know
why I get this result of assembly plugin.
My maven version:
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T22:49:05+03:00)
Maven home: C:\soft\apache-maven-3.5.3\bin\..
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_131\jre
Default locale: ru_RU, platform encoding: Cp1251
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
maven-assembly-plugin version is 3.1.0
Could you help me, please?
Thanks.
There is a problem with adding transitive dependency using maven-assembly-plugin if this dependency was declared in circular dependency.
https://issues.apache.org/jira/projects/MASSEMBLY/issues/MASSEMBLY-782
org.apache.xmlgraphics:batik-...:1.7 has circular dependency between batik-bridge and batik-script.
You can choose several options to solve this problem.
Update to newer version of batik-... library which doesn't have any circular dependencies.
If you can't use previous option, you can configure pom.xml - exclude circular dependencies and extract them to have this dependencies as non-transitive.
<dependencies>
<dependency>
<groupId>internal-module-groupId</groupId>
<artifactId>internal-module-artifactId</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-bridge</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-script</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-script</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-bridge</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
Thanks to Thorsten Heit from maven users mailing list for the help.

Integration Test with failsafe

I am using a simple java application with unit and integration tests.
My goal is to run integration tests with maven & failsafe plugin.
I am having a problem running my integration tests.
short explenation: I get an error from "test-compile" phase at maven, which says "cannot find symbol".
project structure:
parent (pom.xml)
integration test module (test files with pom.xml)
webApp module (source files with pom.xml)
the error I am getting is becouse I am trying to instantiate an object from webApp module (inside some test - in integration tests module).
I also added dependency for webapp inside integration-test module pom.
details:
the integration test class:
import junit.framework.TestCase;
import org.junit.Test;
public class CalcsITCase extends TestCase {
#Test
public void emptyTest() throws Exception {
assertEquals(true,true);
}
#Test
public void playTest() throws Exception {
Band band = new Band(4);
assertEquals(true,true);
}
}
the class that being tested
import org.json.JSONObject;
import java.security.InvalidParameterException;
public class Band {
public int id;
public String name = "";
public String logo = "";
public String song = "";
public int votes = 0;
public Band(int members) {
System.out.println(members + " members in band");
}
....
The integration test pom.xml:
<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">
<parent>
<artifactId>app-all</artifactId>
<groupId>discover-demo-app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>integration-tests</artifactId>
<packaging>jar</packaging>
<name>integration-tests Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>discover-demo-app</groupId>
<artifactId>webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
<finalName>integration-tests</finalName>
</build>
<profiles>
<profile>
<id>it</id>
<build>
<plugins>
<!--added for integration tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>....</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>....</groupId>
<artifactId>....</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
the webApp pom.xml
<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>discover-demo-app</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Discover Demo App - Tribute to Progressive Music (Web App)</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<output>file</output>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>A</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- Minimal supported version is 2.4 -->
<version>2.13</version>
<configuration>
<skipTests>true</skipTests>
<properties>
<property>
<name>listener</name>
<value>...</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>it</id>
<build>
<plugins>
<!--added for integration tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>...</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
the error i am getting from maven (when running the following command inside integration test) is:
mvn verify -Dmaven.test.failure.ignore=true
[INFO] ------------------------------------------------------------------------
[INFO] Building integration-tests Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # integration-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\..\workspace\..\integration-tests\src\main\re
sources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # integration-tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # integration-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\..\workspace\..-demo-app\integration-tests\src\test\re
sources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) # integration-tests ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files to C:\Users\..\workspace\..e-demo-app\integration-tests\target\test-classes
[INFO] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/RestServle
tTest.java: C:\Users\..\workspace\..-demo-app\integration-tests\src\test\java\com\..\devops\demoapp\RestSe
rvletTest.java uses unchecked or unsafe operations.
[INFO] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/RestServle
tTest.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,9] cannot find symbol
symbol: class Band
location: class com....devops.demoapp.CalcsITCase
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,25] cannot find symbol
symbol: class Band
location: class com....devops.demoapp.CalcsITCase
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.676s
[INFO] Finished at: Tue Mar 01 11:45:17 IST 2016
[INFO] Final Memory: 16M/304M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile (default-testComp
ile) on project integration-tests: Compilation failure: Compilation failure:
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,9] cannot find symbol
[ERROR] symbol: class Band
[ERROR] location: class com....devops.demoapp.CalcsITCase
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,25] cannot find symbol
[ERROR] symbol: class Band
[ERROR] location: class com.(..).devops.demoapp.CalcsITCase
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Edit:
Additional Info:
The maven output states that we can't compile the "CalcsITCase.java" class because we doesn't know "Band.java" class..
integration-test module does compile in intellij, it doesn't compile in maven..
The webApp module compile in maven and in intellij successfully.
Also, the test class (CalcsITCase) and subject class (Band) are in the same package.. so it's not an import issue..
i would bet on a maven issue.. but after hours of googling and searching.. i could not found it..
You must import the Band class in your test class, i.e. add the following line to the list import statements in CalcsITCase:
import replace.with.correct.package.name.Band;
Obviously, you need to change the replace.with.correct.package.name with the package name of the Band class.

How to generate classes from wsdl using Maven and wsimport?

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

Maven test (webdriver/testng) looking for resources in non-existing folder. How can I tell it where to look for it?

I have created a selenium/webdriver testng test written in Java, using eclipse.
when I am in eclipse and I have currently selected the test case .class, I can run it and it opens up a browser and runs the test.
When I "mvn integration-test" it, an empty browser is opened and nothing happens. The error reads as follows
--- maven-resources-plugin:2.6:resources (default-resources) # functionalTests ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory c:\test2\functionalTests\src\main\resources
--- maven-compiler-plugin:2.5.1:compile (default-compile) # functionalTests ---
Nothing to compile - all classes are up to date
--- maven-resources-plugin:2.6:testResources (default-testResources) # functionalTests ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory c:\test2\functionalTests\src\test\resources
I really dont have such folder. I generated the maven project, using some archetype I found on the internet and I just replaced their class with mine.
Here is my folder structure:
src
-main
--java
---com
----pragmaticqa
-----tests
test
-java
--com
---pragmaticqa
----tests
and inside tests is where my test .class is located.
this is my pom.xml
<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>com.pragmaticqa.tests</groupId>
<artifactId>functionalTests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>functionalTests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.32.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xvfb</id>
<phase>pre-integration-test</phase>
<goals>
<goal>xvfb</goal>
</goals>
</execution>
<execution>
<id>selenium</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So my question is - how do I tell maven where to look for the test to run?
Add a surefire plugin like the one shown below. Instead of specify your test class name
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</plugin>

Ruby test with jenkins/maven/testLink

I am using Jenkins, maven and testLink plug-in to do automation test.
I would like to execute ruby test with Jenkins and hook theim in testLink.
Here is my pom.xml :
<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>
...
...
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codeartisans</groupId>
<artifactId>ruby-maven-plugin</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codeartisans</groupId>
<artifactId>ruby-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>exec-test</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<script>src/main/ruby/exec.rb</script>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is my configuration in jenkins :
test Execution --> Single build steps --> Invoke top-level maven targets :
-->goals : -X
clean
org.codeartisans:ruby-maven-plugin:0.1:exec
test
-DsuiteXmlFiles=suite.xml
and here the console output :
These will use the artifact files already in the core ClassRealm instead, to allow them to be included in PluginDescriptor.getArtifacts().
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] One or more required plugin parameters are invalid/missing for 'ruby:exec'
[0] Inside the definition for plugin 'ruby-maven-plugin' specify the following:
<configuration>
...
<script>VALUE</script>
</configuration>.
Could someone help me plz? I am new in maven, IC etc...

Resources