How to load data into data base using dbunit in Maven - maven

Below is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/test</url>
<username>usernamet</username>
<password>password</password>
<dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dataTypeFactoryName>
<metadataHandlerName>org.dbunit.ext.mysql.MySqlMetadataHandler</metadataHandlerName>
<encoding>utf-8</encoding>
<src>target/dbunit/export.xml</src><!--compare 和 operation 要用到它 -->
<type>CLEAN_INSERT</type><!--operation 要用到它-->
</configuration>
<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>operation</goal>
</goals>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>operation</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
I run mvn dbunit:operation on command line.
Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app
[INFO] task-segment: [dbunit:operation]
[INFO] ------------------------------------------------------------------------
[INFO] [dbunit:operation {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Feb 10 23:02:41 PST 2011
[INFO] Final Memory: 6M/81M
It says build successful. But there is no data in the database.

Found the answer here
If your data file is in flat format (FlatXmlDataSet), adding flat will perform the update.
For example:
This doesn't work:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
...
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>operation</goal>
</goals>
<configuration>
<type>CLEAN_INSERT</type>
<src>src/main/resources/opc1.xml</src>
</configuration>
</execution>
</executions>
</plugin>
But this works (at least it did for me):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dbunit-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<dependencies>
<dependency>
<groupId>com.sybase</groupId>
<artifactId>jConnect</artifactId>
...
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>operation</goal>
</goals>
<configuration>
<format>flat</format>
<type>CLEAN_INSERT</type>
<src>src/main/resources/opc1.xml</src>
</configuration>
</execution>
</executions>
</plugin>

Create the database(schema) in respective user.
You should have the proper perperties files in XML form in the project.
Go to the project for and type the command e.g.
c:>project_name>mvn dbunit:operation. This will add all the properties

Related

Maven deploying twice

I am having an issue where my artifact is deploying twice when I run
mvn deploy
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-file) # 1.0 ---
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip (334 MB at 8.1 MB/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.pom
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.pom (423 B at 795 B/s)
Downloading from ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml
Downloaded from ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml (310 B at 1.5 kB/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/maven-metadata.xml (336 B at 614 B/s)
Uploading to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip
Uploaded to ProductSuite: http://abc.123:8081/nexus/repository/ProductSuite/Dev/Release/webUI/1.0/https/1.0-https.zip (334 MB at 7.2 MB/s)
After looking up some fixes for this I came across a potential fix:
I would simply have to added the following to the maven-assembly-plugin
<attach>false</attach>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:04 min
[INFO] Finished at: 2021-01-05T16:10:44-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project 11.8: The packaging for this project did not assign a file to the build artifact -> [Help 1]
[ERROR]
Below is what I'm currently working with. It works without the attach configuration but fails with it in there.
Any help is greatly appreciated. Thanks!
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Dev.Release.productA</groupId>
<artifactId>11.8</artifactId>
<version>https</version>
<url>https://maven.apache.org</url>
<properties>
<COMPANYRepositoryUrl>http://abc.123:8081/nexus</COMPANYRepositoryUrl>
<product>productA</product>
</properties>
<distributionManagement>
<repository>
<id>PROD</id>
<url>${PRODRepositoryUrl}/repository/PROD/</url>
</repository>
</distributionManagement>
<!--
| Where to deploy our built artifacts.
+ -->
<build>
<!--
| Define versions of plugins to ensure stable builds.
+
-->
<plugins>
<!--
| Standard maven plugins.
| Note: enforcer plugin is used (initialize) to ensure all plugins are versioned
| Or use $ mvn enforcer:enforce" to check
| Note: to check on the latest version of plugins available do:
| $ mvn versions:display-plugin-updates
+ -->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<!-- disable standard deploy -->
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
<repositoryId>TEST</repositoryId>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<url>${COMPANYRepositoryUrl}/repository/TEST/</url>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>C:\PATH\to\webui.exe</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
I had to add a section to the default execution of the maven-install-plugin. I can run mvn deploy without duplicate uploads which saves a minute in deployment time. (I also updated some of the plugins to newer versions)
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
<configuration>
<file>${basedir}/target/${project.artifactId}-${project.version}.zip</file>
</configuration>
</execution>
</executions>
</plugin>

How to profile JavaFX maven project in NetBeans

When I try to profile JavaFX project in Netbeans 8.2 I get following build error:
cd C:\Users\David\Documents\NetBeansProjects\FxClock; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_101" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dexec.args.merged=true -Dexec.args=\"-agentpath:\\\"C:/Program Files/NetBeans 8.2/profiler/lib/deployed/jdk16/windows-amd64/profilerinterface.dll\\\"=\\\"C:\\Program Files\\NetBeans 8.2\\profiler\\lib\\\",5140,10 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\\Users\\David\\AppData\\Local\\NetBeans\\Cache\\8.2\\mavencachedirs\\521057086\\org-netbeans-modules-profiler -createjar -nocss2bin -appclass com.upce.fxclock.MainApp -srcdir C:\\Users\\David\\Documents\\NetBeansProjects\\FxClock\\target/classes -outdir C:\\Users\\David\\Documents\\NetBeansProjects\\FxClock\\target -outfile FxClock-1.0-SNAPSHOT.jar\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_101\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Default 'profile' action exec.args merged with maven-exec-plugin arguments declared in pom.xml.
Scanning for projects...
------------------------------------------------------------------------
Building FxClock 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-resources-plugin:2.5:resources (default-resources) # FxClock ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 5 resources
--- maven-compiler-plugin:3.1:compile (default-compile) # FxClock ---
Nothing to compile - all classes are up to date
--- exec-maven-plugin:1.2.1:exec (default-cli) # FxClock ---
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -createjar
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.158s
Finished at: Sun May 14 23:35:56 CEST 2017
Final Memory: 7M/155M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project FxClock: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
when I open the nbactions.xml, the profile action is not set, so it uses default one which fails to build.
nbactions.xml:
<actions>
<action>
<actionName>run</actionName>
<goals>
<goal>clean</goal>
<goal>package</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<runfx.args>-jar "${project.build.directory}/${project.build.finalName}.jar"</runfx.args>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>clean</goal>
<goal>package</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<runfx.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Dglass.disableGrab=true -jar "${project.build.directory}/${project.build.finalName}.jar"</runfx.args>
<jpda.listen>true</jpda.listen>
</properties>
</action>
</actions>
Is there a way to setup profiling with that <runfx.args> tag.
Here is pom.xml, I only changed the <target> & <source> to 1.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.upce</groupId>
<artifactId>FxClock</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FxClock</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.upce.fxclock.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<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>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.9</version>
</dependency>
</dependencies>
</project>
Workaround: Use external profiling
In NetBeans:
Run project normaly
Profile -> Attach to external process
Press Attach
Select the running java process to profile
This might not work when you need to profile startup of the application

Maven runs profile executions only after the build executions

Given a following maven pom.xml development profile
<profiles>
<profile>
<id>development</id>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<id>01-liquibase.dropAll</id>
<phase>process-resources</phase>
<configuration>
[...skip...]
</configuration>
<goals>
<goal>dropAll</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
and main section of pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<includes>package/pm/entity/**/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
<persistenceXmlFile>${project.parent.basedir}/forms-webapp/src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
</configuration>
<executions>
<execution>
<id>02-enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<id>03-liquibase.update</id>
<phase>process-resources</phase>
<configuration>
[...skipped...]
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<!-- for tests -->
<execution>
<id>04-liquibase-test.dropAll</id>
<phase>process-test-resources</phase>
<configuration>
[...skipped...]
</configuration>
<goals>
<goal>dropAll</goal>
</goals>
</execution>
<execution>
<id>05-liquibase-test.update</id>
<phase>process-test-resources</phase>
<configuration>
[...skipped...]
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I expect that executions will run in the following order:
....
01-liquibase.dropAll
03-liquibase.update
....
But in build log I see:
[INFO] --- liquibase-maven-plugin:3.0.4:update (03-liquibase.update) # forms-entity ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: src/main/resources/liquibase.properties
[INFO] 'classpath' in properties file is not being used by this task.
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql://localhost/pman_trunk
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO]
[INFO] --- liquibase-maven-plugin:3.0.4:dropAll (01-liquibase.dropAll) # forms-entity ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: src/main/resources/liquibase.properties
[INFO] 'classpath' in properties file is not being used by this task.
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql://localhost/pman_trunk
[INFO] ------------------------------------------------------------------------
Is there any way to fix this wrong execution order?
The executions for id 01-liquibase.dropAll and 03-liquibase.update are executing on the same phase.
You could always move the execution with id 01-liquibase.dropAll to an earlier phase such as generate-resources
<id>01-liquibase.dropAll</id>
<phase>process-resources</phase>
See the Default Lifecycle section in Maven Lifecycle Reference.

Maven Spring Selenium Integration Tests - Running Tomcat before Selenium

I'm learning how to run Selenium Integration Tests in Maven. I've configured Selenium and the Tomcat Maven Plugin using Cargo.
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>SeleniumTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>SeleniumTest</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-struts</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>SeleniumTest</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/main/java/test/integrationTests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
<suiteXmlFiles>
<suiteXmlFile>src/main/java/test/integrationTests/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</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>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skipTests>true</skipTests>
</configuration>
</execution>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<wait>true</wait>
<container>
<containerId>tomcat7x</containerId>
<type>installed</type>
<home>D:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27</home>
</container>
<configuration>
<type>existing</type>
<home>D:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27</home>
</configuration>
<deployables>
<deployable>
<pingURL>http://localhost:8080/SeleniumTest</pingURL>
<pingTimeout>300000</pingTimeout>
</deployable>
</deployables>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>
</build>
</project>
These are the logs of Netbeans when I say Build:
------------------------------------------------------------------------
Building SeleniumTest 1.0-SNAPSHOT
------------------------------------------------------------------------
[dependency:copy]
[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 0 resource
[compiler:compile]
Nothing to compile - all classes are up to date
[resources:testResources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\src\test\resources
[compiler:testCompile]
Compiling 1 source file to C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\target\test-classes
[compiler:testCompile]
Compiling 1 source file to C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\target\test-classes
[surefire:test]
Tests are skipped.
[war:war]
Packaging webapp
Assembling webapp [SeleniumTest] in [C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\target\SeleniumTest-1.0-SNAPSHOT]
Processing war project
Copying webapp resources [C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\src\main\webapp]
Webapp assembled in [454 msecs]
Building war: C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\target\SeleniumTest-1.0-SNAPSHOT.war
[surefire:test]
Surefire report directory: C:\Users\Colenso\Documents\NetBeansProjects\SeleniumTest\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running test.integrationTests.SimpleTest
Configuring TestNG with: TestNG652Configurator
As you can see, It is only building the .war file and Neither starting my tomcat container nor deploying the .war file on it.
If I say Run in Netbeans, I can see Tomcat Starting up and my application running. However the Integration Tests are not done.
To run the integration tests you have to tell maven to run the integration-test phase. Either you run mvn integration-test or mvc install (install works because it came after integration-test in mavens phases)
#See Maven Build Lifecycle
BTW: you should have a look at maven-failsave-plugin. It is a test plugin like surefire but intended to run integration tests. - So you can have two plugins in you pom (surefire for unit tests and failsave for integration tests), so you do not need so much reconfiguration of surefire.

Maven exec plugin execution conundrum

Sample maven build file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-one</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation one"</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-two</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation two"</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
Sample maven output:
$ mvn install
/cygdrive/c/Program Files/Java/jdk1.5.0_20/bin/java -classpath C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/boot/classworlds-1.1.jar -Dclassworlds.conf=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1/bin/m2.conf -Dmaven.home=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1 org.codehaus.classworlds.Launcher "install"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - test:test:jar:1.0.0
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [exec:exec {execution: my-validation-one}]
[INFO] "My validation two"
[INFO] [exec:exec {execution: my-validation-two}]
[INFO] "My validation two"
[INFO] [resources:resources {execution: default-resources}]
<snip>
Shouldn't my-validation-one echo "My validation one" to the console? Why does it seem like maven is getting its wires crossed?
Thanks,
Steven
You should put the configuration specific to the execution within the execution block. Then it should work correctly.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-validation-two</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>echo</executable>
<arguments>
<argument>"My validation two"</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Also, if both the executions are bound to same phase and goal, you can combine then within executions block instead of declaring the plugin twice.

Resources