My project structure is:
Project_Name
|-src/main/java
|-src/test/java
|-default package
|-MyIT.java
|-steps
|-MySteps.java
|-pom.xml
MyIT.java:
#RunWith(SerenityRunner.class)
public class MyIT {
#Steps
MySteps mySteps;
#BeforeClass
public static void setUp() {
RestAssured.baseURI="https://restcountries.com/";
System.out.println("1");
}
#Test
#Title("Check \"Republic Of India\"")
public void verify_that_given_string_found_in_the_response() {
mySteps.whenIOpenURLForIndia();
mySteps.thenRepublicOfIndiaFoundInResponse();
}
}
MySteps.java:
public class MySteps {
#Step("When I Open the URL for India")
public void whenIOpenURLForIndia() {
SerenityRest.given().relaxedHTTPSValidation().basePath("v2/name/{country}").pathParam("country", "INDIA").when().get();
}
#Step("Then \"Republic of India\" found in the response")
public void thenRepublicOfIndiaFoundInResponse() {
SerenityRest.lastResponse().then().body("[1].altSpellings",hasItem("Republic of India"));
}
}
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>org.restcountries</groupId>
<artifactId>Serenity_RestAssured_Assignment1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Serenity_RestAssured_Assignment1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-rest-assured -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Now when I run it using:
mvn clean verify
its output is:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< org.restcountries:Serenity_RestAssured_Assignment1 >---------
[INFO] Building Serenity_RestAssured_Assignment1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Serenity_RestAssured_Assignment1 ---
[INFO] Deleting C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # Serenity_RestAssured_Assignment1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # Serenity_RestAssured_Assignment1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) # Serenity_RestAssured_Assignment1 ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # Serenity_RestAssured_Assignment1 ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar:
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\Serenity_RestAssured_Assignment1-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.305 s
[INFO] Finished at: 2022-06-24T04:14:55+05:30
It shows “tests are skipped” and “jar will be empty”.
My question is why mvn verify is not running MyIT.java test despite that naming convention is proper for integration test(maven failsafe plugin). Maven surefire plugin is skipping the tests but maven failsafe plugin should identify the MyIT.java test.
EDIT: mvn clean test-compile failsafe:integration-test is able to run the MyIT.java test successfully but mvn clean test-compile failsafe:verify does not.
The issue is simply because you have defined the maven-failsafe-plugin in pluginManagement only.
The usual way is to define the version in pluginManagement while the binding has to be done in build area.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also recommend to upgrade your used plugins which means define newer versions of all used plugin in pluginManagement.
Furthermore you should not define a configuration for maven-surefire-plugin:
<configuration>
<skip>true</skip>
</configuration>
Related
I am trying to keep up with the new changes in Java, one step a time.
I am updating my old libraries with module-info.java files.
I have a very simple project named "api-clone" dependent on "gwt-user".
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>com.tugalsan</groupId>
<artifactId>api-clone</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>**/*.gwt.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
With the module-info.java below:
open module com.tugalsan.api.clone {
requires gwt.user;
}
When netbeans runs compile, it builds successfully:
cd C:\me\codes\GWT\api\api-clone; "JAVA_HOME=C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.2.8-hotspot" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install"
Scanning for projects...
-----------------------< com.tugalsan:api-clone >-----------------------
Building api-clone 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- maven-clean-plugin:2.5:clean (default-clean) # api-clone ---
Deleting C:\me\codes\GWT\api\api-clone\target
--- maven-resources-plugin:2.6:resources (default-resources) # api-clone ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 4 resources
Copying 0 resource
--- maven-compiler-plugin:3.10.1:compile (default-compile) # api-clone ---
Required filename-based automodules detected: [gwt-user-2.9.0.jar]. Please don't publish this project to a public artifact repository!
Changes detected - recompiling the module!
Compiling 3 source files to C:\me\codes\GWT\api\api-clone\target\classes
--- maven-resources-plugin:2.6:testResources (default-testResources) # api-clone ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\me\codes\GWT\api\api-clone\src\test\resources
--- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) # api-clone ---
Changes detected - recompiling the module!
--- maven-surefire-plugin:2.12.4:test (default-test) # api-clone ---
--- maven-jar-plugin:2.4:jar (default-jar) # api-clone ---
Building jar: C:\me\codes\GWT\api\api-clone\target\api-clone-1.0-SNAPSHOT.jar
--- maven-install-plugin:2.4:install (default-install) # api-clone ---
Installing C:\me\codes\GWT\api\api-clone\target\api-clone-1.0-SNAPSHOT.jar to C:\Users\tugal\.m2\repository\com\tugalsan\api-clone\1.0-SNAPSHOT\api-clone-1.0-SNAPSHOT.jar
Installing C:\me\codes\GWT\api\api-clone\pom.xml to C:\Users\tugal\.m2\repository\com\tugalsan\api-clone\1.0-SNAPSHOT\api-clone-1.0-SNAPSHOT.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.315 s
Finished at: 2022-04-28T19:32:22+03:00
------------------------------------------------------------------------
However, when I look at the module-info.java file, Netbeans show error:
Is it because "gwt.user" is not a module-ized project?
How to handle that kind of projects, when ones projects are dependent on them?
As #skomisa answered, the problem I am facing in "module-info.java"
can be solved in "pom.xml" by adding exclusion on dependecy tag.
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
USEFUL VIDEO: https://www.youtube.com/watch?v=xKmv24_2Asw&t=2094s
example code: at github
I want to get cucumber report, but it nothing generates.
I get this error during running via mvn clean install.
I cant to resolve this issue.
I'm new in automation...
/* During run as Maven Clean Install I get mentioned below error:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< MobWebAutomation:MobWebAutomation >------------------
[INFO] Building MobWebAutomation 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # MobWebAutomation ---
[INFO] Deleting C:\Users\Rauf.mirzoyev\eclipse-workspace_Appium\MobWebAutomation\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # MobWebAutomation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # MobWebAutomation ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # MobWebAutomation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # MobWebAutomation ---
[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 4 source files to C:\Users\Rauf.mirzoyev\eclipse-workspace_Appium\MobWebAutomation\target\test-classes
[ERROR] /C:/Users/Rauf.mirzoyev/eclipse-workspace_Appium/MobWebAutomation/src/test/java/stepDefinitions/RegistrationWithValidCredentials.java:[116,55] unmappable character (0x8F) for encoding windows-1252
[ERROR] /C:/Users/Rauf.mirzoyev/eclipse-workspace_Appium/MobWebAutomation/src/test/java/stepDefinitions/RegistrationWithValidCredentials.java:[116,61] unmappable character (0x8F) for encoding windows-1252
[ERROR] /C:/Users/Rauf.mirzoyev/eclipse-workspace_Appium/MobWebAutomation/src/test/java/stepDefinitions/RegistrationWithValidCredentials.java:[116,64] unmappable character (0x8F) for encoding windows-1252
[INFO]
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) # MobWebAutomation ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # MobWebAutomation ---
[INFO] Building jar: C:\Users\Rauf.mirzoyev\eclipse-workspace_Appium\MobWebAutomation\target\MobWebAutomation-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-cucumber-reporting:5.0.0:generate (execution) # MobWebAutomation ---
[INFO] About to generate Cucumber report.
Dec 29, 2021 10:31:50 AM net.masterthought.cucumber.ReportBuilder generateErrorPage
INFO: Unexpected error
net.masterthought.cucumber.ValidationException: None report file was added!
at net.masterthought.cucumber.ReportParser.parseJsonFiles(ReportParser.java:62)
at net.masterthought.cucumber.ReportBuilder.generateReports(ReportBuilder.java:88)
at net.masterthought.cucumber.CucumberReportGeneratorMojo.execute(CucumberReportGeneratorMojo.java:209)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.525 s
[INFO] Finished at: 2021-12-29T10:31:51+04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.masterthought:maven-cucumber-reporting:5.0.0:generate (execution) on project MobWebAutomation: Error Found: BUILD FAILED - Check Report For Details -> [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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the
following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
*/
/*My pom 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MobWebAutomation</groupId>
<artifactId>MobWebAutomation</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<includes>
<exclude>**/*Runner.java</exclude>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>MobWebAutomation</projectName>
<outputDirectory>${project.build.directory}/cucumber-reports</outputDirectory>
<enableFlashCharts>true</enableFlashCharts>
<buildNumber>42</buildNumber>
<parallelTesting>false</parallelTesting>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
<jsonFiles>
<jsonFile>**/*.json</jsonFile>
</jsonFiles>
<testFailureIgnore>true</testFailureIgnore>
<buildSuccessOnTestFailure>true</buildSuccessOnTestFailure>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
}
**Runner class**
{ package runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = { "src/test/java/features/registration.feature" },
glue = { "stepDefinitions",
"utility" }, monochrome = true, plugin = { "pretty",
"json:target/cucumber-reports/AutomationReport.json",
"json:target/cucumber-reports/cucumber.runtime.formatter.JSONFormatter"
},
dryRun = false)//, tags = "#correct or #incorrect")
public class RunTest {
}
Thank you to all, and especially to Raghav Pal, and his YouTube channel.
After all steps, it was needed to perform "clean verify". After this operation, the report has been successfully generated.
Updated 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MobWebAutomation</groupId>
<artifactId>MobWebAutomation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> /* 1.8 it's your JDK version */
<maven.compiler.target>1.8</maven.compiler.target>/* 1.8 it's your JDK version */
</properties>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>YOUR_PROJECT_Name</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
RUNNER CLASS:
package runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = { "src/test/java/features/registration.feature" },
glue = { "stepDefinitions", "utility" },
monochrome = true,
plugin = {
"pretty",
"json:target/Cucumber.json"
},
dryRun = false
)
public class RunTest {
//
}
After you need to clean your project -> run via mvn clear verify. That's all.
Source: YouTube video - Selenium Cucumber Java BDD Framework 12 | How To Create HTML Reports
Following Configuration helped me to resolve the issue
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>qaclickacademy</groupId>
<artifactId>RestAPIFramework</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>RestAPIFramework</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.3.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<outputDirectory>${project.build.directory}/advanced-reports</outputDirectory>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.5.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>7.5.0</version>
</dependency>
</dependencies>
</project>
TestRunner Class
#RunWith(Cucumber.class)
#CucumberOptions(features="src/test/java/features", glue= {"stepDefinations"},
monochrome = true,
plugin = {"pretty",
"json:target/cucumber-reports/reports.json",
"json:target/cucumber-reports/cucumber.runtime.formatter.JSONFormatter"})
public class TestRunner {
}
I am able to execute my selenium scripts locally in Eclipse as Maven Project.
I am unable to execute the scripts in Jenkins from Ubuntu.
I have successfully configured jenkins and Build is successful. But scripts are not getting executed.
I am using local workspace.
Can someone please help me to find a solution?
My pom.xml as follows:
<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>ExpertusONE_4.5</groupId>
<artifactId>ExpertusONE_4.5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ExpertusONE_4.5</name>
<description>ExpertusONE_4.5</description>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<includes>
<include>CreateOrganization.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8.0_222</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
My console Output in Jenkins as follows:
Console Output
Started by user unknown or anonymous
Running as SYSTEM
Building in workspace /home/nivedab/ExpertusONE_4.5
Parsing POMs
Established TCP socket on 38039
[ExpertusONE_4.5] $ /usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/opt/maven/boot/plexus-classworlds-2.6.0.jar:/opt/maven/conf/logging jenkins.maven3.agent.Maven35Main /opt/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-3.33.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 38039
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f /home/nivedab/ExpertusONE_4.5/pom.xml process-test-classes
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< ExpertusONE_4.5:ExpertusONE_4.5 >-------------------
[INFO] Building ExpertusONE_4.5 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # ExpertusONE_4.5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 218 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # ExpertusONE_4.5 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # ExpertusONE_4.5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/nivedab/ExpertusONE_4.5/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # ExpertusONE_4.5 ---
[INFO] No sources to compile
Notifying upstream projects of job completion
Join notifier requires a CauseAction
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.744 s
[INFO] Finished at: 2019-11-05T14:26:37+05:30
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /home/nivedab/ExpertusONE_4.5/pom.xml to ExpertusONE_4.5/ExpertusONE_4.5/0.0.1-SNAPSHOT/ExpertusONE_4.5-0.0.1-SNAPSHOT.pom
channel stopped
Notifying upstream projects of job completion.
My Jenkins job configuration:
jenkins job configuration
I guess your problem is the plugins version.I am using two plugins maven-surefire-plugin & maven-compiler-plugin with mention version. When I am used other version it does not work for me. You can give a try
<?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>VRS_NEW</groupId>
<artifactId>Regression_New</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>vrsautomation</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<forkCount>1</forkCount>
<useFile>false</useFile>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<forkMode>once</forkMode>
<suiteXmlFiles>
<suiteXmlFile>testing.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
This is my 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>com.paper</groupId>
<artifactId>with</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>with</name>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- Applicatif -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<!-- <scope>test</scope> -->
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-extras</artifactId>
<version>1.3.10</version>
</dependency>
<!-- FIN Applicatif -->
<!-- JSP TLD -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-taglib</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-el</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-tiles</artifactId>
<version>1.3.10</version>
</dependency>
<!-- FIN JSP TLD -->
<!-- Birt -->
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.3.0</version>
<exclusions>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>org.eclipse.birt.runtime</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- FIN Birt -->
<!-- Divers -->
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.novell.ldap</groupId>
<artifactId>jldap</artifactId>
<version>2009-10-07</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
<!-- FIN Divers -->
<!-- Profiles -->
<properties>
<majorVersion>2</majorVersion>
<minorVersion>50.3-0</minorVersion>
<applicationShortname>Lyreco</applicationShortname>
<applicationLongname>Lyreco</applicationLongname>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profileVersion>DEV</profileVersion>
<webXmlfolder>dev</webXmlfolder>
<mode>- Developpements</mode>
</properties>
</profile>
<profile>
<id>preprod</id>
<properties>
<profileVersion>PREPROD</profileVersion>
<webXmlfolder>preprod</webXmlfolder>
<mode>- Pre-Production</mode>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileVersion>PROD</profileVersion>
<webXmlfolder>prod</webXmlfolder>
</properties>
</profile>
</profiles>
<!-- FIN Profiles -->
<build>
<finalName>${applicationShortname}_${majorVersion}_${minorVersion}_${profileVersion}</finalName>
<plugins>
<!-- ANT Plugin DEBUT -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<move
file="${project.build.directory}/classes/log4j.${webXmlfolder}.properties"
tofile="${project.build.directory}/classes/log4j.properties"
overwrite="true" />
<move
file="${project.build.directory}/classes/hibernate.cfg.${webXmlfolder}.xml"
tofile="${project.build.directory}/classes/hibernate.cfg.xml"
overwrite="true" />
<move
file="${project.build.directory}/classes/com/paper/with/properties/enumerations.${webXmlfolder}.properties"
tofile="${project.build.directory}/classes/com/paper/with/properties/enumerations.properties"
overwrite="true" />
<move
file="${project.build.directory}/classes/com/paper/with/properties/MessageResources.${webXmlfolder}.properties"
tofile="${project.build.directory}/classes/com/paper/with/properties/MessageResources.properties"
overwrite="true" />
<move
file="${project.build.directory}/classes/com/paper/with/properties/Parametres.${webXmlfolder}.properties"
tofile="${project.build.directory}/classes/com/paper/with/properties/Parametres.properties"
overwrite="true" />
<delete>
<fileset dir="${project.build.directory}/classes/"
includes="**/hibernate.cfg.*.xml" />
<fileset dir="${project.build.directory}/classes/"
includes="**/log4j.*.properties" />
<fileset
dir="${project.build.directory}/classes/com/paper/with/properties/"
includes="**/enumerations.*.properties" />
<fileset
dir="${project.build.directory}/classes/com/paper/with/properties/"
includes="**/MessageResources.*.properties" />
<fileset
dir="${project.build.directory}/classes/com/paper/with/properties/"
includes="**/Parametres.*.properties" />
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ANT Plugin FIN -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Maven Replacer Plugin DEBUT -->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${project.build.directory}/${applicationShortname}_${majorVersion}_${minorVersion}_${profileVersion}/WEB-INF/web.xml</file>
<replacements>
<replacement>
<token>#majorVersion#</token>
<value>${majorVersion}</value>
</replacement>
<replacement>
<token>#minorVersion#</token>
<value>${minorVersion}</value>
</replacement>
<replacement>
<token>#mode#</token>
<value>${mode}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<!-- Maven Replacer Plugin FIN -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<archive>
<manifestEntries>
<Specification-Title>J2EE Servlet</Specification-Title>
<Specification-Version>2.5</Specification-Version>
<Specification-Vendor>Sun Microsystems</Specification-Vendor>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Built-By>me</Built-By>
<Implementation-URL>${project.url}</Implementation-URL>
</manifestEntries>
</archive>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My output console:
D:\workspace\with>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building with 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for milyn:flute:jar:1.3 is missing, no dependency information available
[WARNING] The artifact com.lowagie:itext:jar:4.2.2 has been relocated to com.itextpdf:itextpdf:jar:5.5.6
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # with ---
[INFO] Deleting D:\workspace\with\target
[INFO]
[INFO] --- maven-dependency-plugin:2.6:copy (default) # with ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # with ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 63 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # with ---
[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 1629 source files to D:\workspace\with\target\classes
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/authentification/AuthentificationManager.java:[8,16] sun.
misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/presentation/acompte/RapprochementFormInitializer.java:[8
1,38] com.sun.corba.se.spi.extension.ZeroPortPolicy is internal proprietary API and may be removed in a future release
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/presentation/retrocession/AffichageRetrocessionPrestation
DispatchAction.java:[76,53] com.sun.corba.se.impl.protocol.giopmsgheaders.Message is internal proprietary API and may be
removed in a future release
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/service/importation/article/ImportationQuantiteArticle.ja
va:[16,26] sun.misc.resources.Messages is internal proprietary API and may be removed in a future release
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/authentification/AuthentificationManager.java:[156,29] su
n.misc.BASE64Encoder is internal proprietary API and may be removed in a future release
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/presentation/declaration/saisieCARealise/RechercheCAReali
seDispatchAction.java: Some input files use or override a deprecated API.
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/presentation/declaration/saisieCARealise/RechercheCAReali
seDispatchAction.java: Recompile with -Xlint:deprecation for details.
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/persistence/hibernate/dao/HibernateDAO.java: Some input f
iles use unchecked or unsafe operations.
[WARNING] /D:/workspace/with/src/main/java/com/paper/with/persistence/hibernate/dao/HibernateDAO.java: Recompile wi
th -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # with ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\with\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # with ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # with ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (default) # with ---
[INFO] Executing tasks
main:
[move] Moving 1 file to D:\workspace\with\target\classes
[move] Moving 1 file to D:\workspace\with\target\classes
[move] Moving 1 file to D:\workspace\with\target\classes\com\paper\with\properties
[move] Moving 1 file to D:\workspace\with\target\classes\com\paper\with\properties
[move] Moving 1 file to D:\workspace\with\target\classes\com\paper\with\properties
[INFO] Executed tasks
[INFO]
[INFO] --- maven-war-plugin:2.2:war (package-war) # with ---
[INFO] Packaging webapp
[INFO] Assembling webapp [with] in [D:\workspace\with\target\Lyreco_2_50.3-0_DEV]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\workspace\with\src\main\webapp]
[INFO] Webapp assembled in [16254 msecs]
[INFO] Building war: D:\workspace\with\target\Lyreco_2_50.3-0_DEV.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- replacer:1.5.2:replace (default) # with ---
[INFO] Replacement run on 1 file.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # with ---
[INFO] Installing D:\workspace\with\target\Lyreco_2_50.3-0_DEV.war to C:\Users\me\.m2\repository\com\paper
\with\1.0\with-1.0.war
[INFO] Installing D:\workspace\with\pom.xml to C:\Users\me\.m2\repository\com\paper\with\1.0\with-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 41.632 s
[INFO] Finished at: 2016-03-24T11:54:10+01:00
[INFO] Final Memory: 50M/765M
[INFO] ------------------------------------------------------------------------
My problem is I have modify my web.xml. Everything appears to be working, except that the modification takes place AFTER the war file is built.
This is normal: the maven-war-plugin has a default default-war execution that is executed before all other plugins bound to the package phase. A direct solution would be to bind maven-replacer-plugin to the prepare-package phase with <phase>prepare-package</phase> in its configuration.
But I'll emphasize that you're doing it wrong™.
In Maven terms, what you want here is to filter the web.xml. The maven-war-plugin already supports that by configuring it with
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
Filtering means replacing at build-time a placeholder by a value. In this case, we want to replace #majorVersion#, #minorVersion# and #mode#.
So create a file src/main/filters/filter.properties for example, with the content
majorVersion=2
minorVersion=50.3-0
mode=- Mode
Then you can configure the maven-war-plugin with the following:
<configuration>
<filters>
<filter>src/main/filters/filter.properties</filter>
</filters>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<webResources>
<resource>
<directory>/path/to/other/files/to/filter</directory>
<includes>
<include>MessageResources.properties</include>
</includes>
<filtering>true</filtering>
<targetPath>[...]</targetPath>
</resource>
</webResources>
</configuration>
This will replace every occurence of ${majorVersion}, ${minorVersion} and ${mode} in the web.xml with the values defined in the properties file. Note that this also adds a webResource to enable filtering on another resources embedded in the WAR, and the resource will be placed under the specified targetPath.
I noted that, in your current POM, the value of mode depends on the profile. In this case, you can create 4 filters file:
src/main/filters/filter.properties will contain the common properties to filter
src/main/filters/filter-dev.properties will contain the dev profile specific property
src/main/filters/filter-preprod.properties will contain the preprod profile specific property
src/main/filters/filter-prod.properties will contain the prod profile specific property
Then, in your <profile> section, you can add:
<profile>
<id>[...]</id>
<!-- rest of configuration untouched -->
<properties>
<filterFile>src/main/filters/filter-[...].properties</filterFile>
</properties>
</profile>
and finally define the maven-war-plugin with
<configuration>
<filters>
<filter>src/main/filters/filter.properties</filter>
<filter>${filterFile}</filter>
</filters>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
You should bind the replacer-plugin to the prepare-package phase, because lifecycle plugins always go first in a specific phase.
I am trying to learn about jax-ws and created a simple Bottom-Up HelloWorld webservice in order to train myself:
import org.jboss.annotation.ejb.LocalBinding;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
#WebService(serviceName = "HelloWorldWebServiceExperiment",
portName = "HelloWorldPort",
name = "HelloWorld")
#SOAPBinding(style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#Stateless
#Remote
#LocalBinding(jndiBinding = "training.webservice.HelloWorldWebServiceRemote/local")
public class HelloWorldWebServiceBean {
private static final String HELLO_WORLD = "Hello World";
#WebMethod
public String helloWorld() {
return HELLO_WORLD;
}
}
When I deploy this webservice I can access the wsdl, so that seems to work fine.
Then I tried to generate a webservice client. And to do so I needed to create stubs, which I tried to create with the maven plugin jaxws-maven-plugin. Here is my 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>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<wsdlPath>${project.build.directory}</wsdlPath>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<targetPath>WEB-INF</targetPath>
<directory>src/main/webapp/WEB-INF</directory>
<includes>
<include>web.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>genwsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<genWsdl>true</genWsdl>
<sei>training.webservice.HelloWorldWebServiceBean</sei>
</configuration>
</execution>
<execution>
<id>consumeWsdlForStubs</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>HelloWorldWebServiceExperiment.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<destDir>target/classes</destDir>
<sourceDestDir>target/stubs</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-wsclient-jars</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/stubs</classesDirectory>
<classifier>wsclient</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JAX-WS Annotations -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0-MR1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossws-spi</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb3x</artifactId>
<version>4.2.2</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-annotations-ejb3</artifactId>
<version>4.2.2.GA</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-jaxws</artifactId>
<version>4.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
The Build with maven will generate the follwoing output and a .jar file with generated .java files:
> mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - training.webservice:HelloWorldWebServiceExperiment:war:1.0-SNAPSHOT
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory ---/HelloWorldWebServiceExperiment/target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to ---/HelloWorldWebServiceExperiment/target/classes
[INFO] [compiler:compile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [jaxws:wsgen {execution: genwsdl}]
[INFO] [jaxws:wsimport {execution: consumeWsdlForStubs}]
[INFO] Processing: ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl
[INFO] jaxws:wsimport args: [-s, ---/ /HelloWorldWebServiceExperiment/target/jaxws/wsimport/java, -d, ---/HelloWorldWebServiceExperiment/target/classes, -verbose, -Xnocompile, ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl]
parsing WSDL...
generating code...
training/webservice/HelloWorld.java
training/webservice/HelloWorldResponse.java
training/webservice/HelloWorldWebServiceExperiment.java
training/webservice/HelloWorld_Type.java
training/webservice/ObjectFactory.java
training/webservice/package-info.java
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory ---/HelloWorldWebServiceExperiment/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[HelloWorldWebServiceExperiment] in [---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp webResources[---/HelloWorldWebServiceExperiment/src/main/webapp/WEB-INF] to[---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Copying webapp resources[---/HelloWorldWebServiceExperiment/src/main/webapp]
[INFO] Webapp assembled in[33 msecs]
[INFO] Building war: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] [jar:jar {execution: package-wsclient-jars}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 25 09:31:20 CEST 2015
[INFO] Final Memory: 32M/487M
[INFO] ------------------------------------------------------------------------
EDIT (for precision): When I try use the stub archive in another project to create a webclient, (i do this with intellij idea), idea automatically finds the file from my maven repository and suggests it to me, generating the following dependency:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT-wsclient</version>
</dependency>
however none of the genereated .java files can actually be imported and used in code! E.g. idea fails on usage or import
import training.webservice.HelloWorld;
private training.webservice.HelloWorld helloWorld;
with the error message "Cannot resolve symbol 'HelloWorld'"
What am I doing wrong? Is this connected to the fact that my stub only contains .java files, but no .class files? Obviously the plugin jaxws-maven-plugin runs wsimport with the -xnocompile flag, but I haven't been able to figure out how to configure maven not to do that, none of the options keep, destDir or sourceDestDir have had any effect on that! Or is this completely irrelevant, as the project importing the stubs should be able to compile them itself and the problem is somewhere else? Any help would be greatly appreciated!
I found a temporary work arround:
I generate a client stub .jar file manually. As my company still works with Java 1.5, I had to install metro in order to use wsimport (I chose version 1.6.2) and then I could call:
wsimport target/generated-sources/wsdl/HelloWorldWebServiceExperiment.wsdl -d target/generated-sources/wsdl/ -keep
afterwards I had .java and .class files which I could manually package into a .jar file, then I moved that .jar into the ressource folder of my webservice client project and manually added the dependency into my pom.xml:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/client.jar</systemPath>
</dependency>
I would prefer an automatic build and deploy from maven, and I am now sure that the problem must lie within my maven setup, however I have still no clue how to do it any better. At least I can continue working on the webservice client for now, and revisit the issue at a later point again!