Trying to run a pack of selenium tests written in java using Jenkins - selenium

After reading nearly all the posts that it suggests under "Questions with similar titles" (I will continue reading after sending this post) and reading
centripetal.ca/blog/2011/02/07/getting-started-with-selenium-and-jenkins/
oliverpolden.com/content/setting-automated-selenium-testing-jenkinshudson
and some other posts (I note these two because I think they may be useful to someone) I haven't found an answer to what I need. And now I get to that:
I'm working in a company that uses Jenkins for CI and maven. They have three types of tests ran for the sotware: junit, cactus and selenium. Jenkins has a job to run junit tests. Now they've decided to run the other two types of tests (Cactus and Selenium) using Jenkins. And that's my task. Cactus would be another question I'll ask later (have been banging my head with that one for too long right now). The Selenium tests are written in java and there's a java file that has all the tests as it follows:
package com.mycompany.test.dailySanity;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({
Test1.class,
Test2.class,
Test3.class,
})
public class AllTests {
/**
* This is just a place holder.
* Add All your TestClass one to the list above.
* NOTE, the TestClasses should be "," separated
*/
}
All the information I've found talks about an htmlsuite, but nothing about if the tests are in java (no, exporting them to HTML is not an option). I've tried
export DISPLAY=":99" && java -jar /path/to/selenium-server.jar
-browserSessionReuse -htmlSuite *firefox http://localhost
/path/to/my/testsfile/AllTests.java
/path/to/my/logfile/SeleniumLog.html
as an "Execute Shell" in "Build" step in Jenkins job, but it just stays trying something.
Console output
09:29:48.508 INFO - Java: Sun Microsystems Inc. 14.2-b01
09:29:48.518 INFO - OS: Linux 2.6.18.8-xenU amd64
09:29:48.654 INFO - v2.4.0, with Core v2.4.0. Built from revision 13337
09:29:49.263 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:29:49.264 INFO - Version Jetty/5.1.x
09:29:49.269 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
09:29:49.271 INFO - Started HttpContext[/selenium-server,/selenium-server]
09:29:49.271 INFO - Started HttpContext[/,/]
09:29:49.337 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#7a187814
09:29:49.337 INFO - Started HttpContext[/wd,/wd]
09:29:49.343 INFO - Started SocketListener on 0.0.0.0:4444
09:29:49.343 INFO - Started org.openqa.jetty.jetty.Server#67ad77a7
10:51:00.038 INFO - Shutting down...
10:51:00.040 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
I assume it does nothing else (waited for 2 hours before aboting it) beacause it's a java file and it requires an html file (-htmlsuite is a clue).
To sum up: I need a way to run Selenium tests written in Java and packaged in a java suite on Jenkins.
EDITING
Ok, I'm not getting anywhere and running out of time. I'm adding more information just in case someone can give me a hand (not that I'm not thankful to Ross). Here goes my selenium_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>my.company</groupId>
<artifactId>selenium-test</artifactId>
<version>0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium.client-drivers</groupId>
<artifactId>selenium-java-client-driver</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>/path/to/my/tests/AllTests.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run
mvn -f selenium_pom.xml integration-test
I get the following output
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.kana.sem:selenium-test:jar:0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. # line 44, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-test 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/resources/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) # selenium-test ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # selenium-test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] --- selenium-maven-plugin:2.1:start-server (default) # selenium-test ---
Launching Selenium Server
Waiting for Selenium Server...
[WARNING] OS appears to be Unix and no DISPLAY environment variable has been detected. Browser maybe unable to function correctly. Consider using the selenium:xvfb goal to enable headless operation.
[INFO] User extensions: /localhome/kana/p4/dev/BOT/target/selenium/user-extensions.js
08:05:07,166 INFO [org.openqa.selenium.server.SeleniumServer] Java: IBM Corporation 2.3
08:05:07,173 INFO [org.openqa.selenium.server.SeleniumServer] OS: Linux 2.6.18.8-xenU x86
08:05:07,184 INFO [org.openqa.selenium.server.SeleniumServer] v2.9.0, with Core v2.9.0. Built from revision 14289
08:05:07,273 INFO [org.openqa.selenium.server.SeleniumServer] RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
08:05:07,277 INFO [org.openqa.jetty.http.HttpServer] Version Jetty/5.1.x
08:05:07,686 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.servlet.ServletHandler#51fe51fe
08:05:07,687 INFO [org.openqa.jetty.util.Container] Started HttpContext[/wd,/wd]
08:05:07,687 INFO [org.openqa.jetty.util.Container] Started HttpContext[/,/]
08:05:07,688 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server,/selenium-server]
08:05:07,689 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server/driver,/selenium-server/driver]
08:05:07,705 INFO [org.openqa.jetty.http.SocketListener] Started SocketListener on 0.0.0.0:4444
08:05:07,705 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.Server#40e640e6
08:05:07.916 INFO - Checking Resource aliases
Selenium Server started
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default) # selenium-test ---
[INFO] No tests to run.
[INFO] Surefire report directory: /path/to/surefire-reports/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.387s
[INFO] Finished at: Fri Jan 13 08:05:08 CST 2012
[INFO] Final Memory: 12M/30M
[INFO] ------------------------------------------------------------------------
I'm using perforce, Jenkins, maven3 and Red Hat Enterprise Linux Server release 5.5 (Tikanga). I'm sure my pom is one of the problems, but got it from internet samples...
Thanks (and congratulations to all that have finished reading this post!)
PS: If you also know how to get a report from the Selenium tests that would be great.

The -htmlsuite option is for something completely different from what you're trying to do. Don't let it distract you :-)
Your Java code appears to be written so that the tests are executed via JUnit. That's a very common technique. I expect all you need to do is make sure the Selenium RC server is running before the tests begin. Just java -jar /path/to/selenium-server.jar and leave it running until at least the end of the last test. Your tests will contact the server by creating a connection to it, probably by calling new DefaultSelenium(...).

Jenkins is very well integrated with Maven, so I suggest you concentrate on running the tests using Maven rather than Jenkins. You can use the failsafe plugin to run integration tests such as your selenium tests. Jenkins will automatically find the failsafe reports and show a pretty HTML summary. Also, you can test this more easily on your local machine.
Please can you update your post to clarify whether you're using Selenium 1 or 2. RemoteWebDriver looks like v2, but your POM shows selenium-java-client-driver from 1.0

Related

activejdbc migrator force to create `schema_version` table if it exits

Today I am going to setup another development env by dumping the demo data from one server and restoring to another one. Also I copy the code base to the development server. When I run mvn validate which will invoke migration, it outputs
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.ft:xjobs-server >-----------------------
[INFO] Building API server for xJobs service 0.2-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) # xjobs-server ---
[INFO] Sourcing database configuration from file: /srv/apps/xjobs-server/src/main/resources/database.properties
[INFO] Environment: development
[INFO] Migrating jdbc:postgresql://localhost:5432/xjobs_deve using migrations at /srv/apps/xjobs-server/src/migrations/
[INFO] Creating schema version table for POSTGRESQL DB
[INFO] Executing: create table schema_version (version varchar(32) not null unique, applied_on timestamp not null, duration int not null)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.864 s
[INFO] Finished at: 2021-07-26T00:42:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.javalite:db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) on project xjobs-server: Execution dev_migrations of goal org.javalite:db-migrator-maven-plugin:2.5-j8:migrate failed: org.javalite.activejdbc.DBException: org.postgresql.util.PSQLException: ERROR: relation "schema_version" already exists, query: create table schema_version (version varchar(32) not null unique, applied_on timestamp not null, duration int not null) -> [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/PluginExecutionException
And the javalite version
<javalite.version>2.5-j8</javalite.version>
I have checked schema_version table, it does exist, and it contains all migration sequence numbers. I don't understand why the migrator still needs to create the table again.
-- UPDATE
some config in pom.xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javalite.version>2.5-j8</javalite.version>
<jetty.version>9.4.24.v20191120</jetty.version>
<environments>development</environments>
</properties>
...
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>${javalite.version}</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.18</version>
</dependency>
</dependencies>
<configuration>
<configFile>${project.basedir}/src/main/resources/database.properties</configFile>
<environments>${environments}</environments>
</configuration>
<executions>
<execution>
<id>dev_migrations</id>
<phase>validate</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
</plugin>
I created an example to test exactly the scenario you have. Fortunately, the JavaLite Migrator is working as expected.
Here is the link to the example: https://github.com/javalite/javalite-examples/tree/master/postgresql-example
No matter how many times you run the migrator, it works as expected every time:
[INFO] --- db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) # postgresql-example ---
[INFO] Sourcing database configuration from file: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/main/resources/database.properties
[INFO] Environment: development.test
[INFO] Migrating jdbc:postgresql://localhost/postgres using migrations at /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations/
[INFO] Trying migrations at: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations
[INFO] No new migrations are found
[INFO] Environment: development
[INFO] Migrating jdbc:postgresql://localhost/postgres using migrations at /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations/
[INFO] Trying migrations at: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations
[INFO] No new migrations are found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.460 s
[INFO] Finished at: 2021-07-26T12:39:06-05:00
So, why are you having an issue? It is possible that you have multiple schemas in the database, and improperly configured visibility, such that under one condition, you see the schema_version table and under another, you do not. There have been reported similar cases before for Oracle, and the fix was related to eliminating leaking table visibility under different users. This is where you need to focus to fix the issue.

mvn clean without dependencies

I have a third party jar which is necessary for our project. It is not available on the central maven repository, so I used the maven-install-plugin to install the jar locally during a build. I tied the "install-file" goal to the "validate" phase, and this mostly works. The pom.xml file excerpt is below:
<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>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>install-myartifact</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/myartifact-1.2.3.jar</file>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
However, there's a catch. Most of our developers and our Jenkins installation run "mvn clean install." The "validate" phase is not part of the "clean" lifecycle, and clean inexplicably requires all the dependencies be present to run. So the first time someone runs this build, it does not work.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyModule
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\svn\trunk\mymodule\target
Downloading: http://nexusserver.local:8080/nexus/content/groups/public/com/example/myartifact-1.2.3.pom
[INFO] Unable to find resource 'com.example:myartifact:pom:1.2.3' in repository central (http://central)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example:myartifact:jar:1.2.3
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example:mymodule:war:0.0.1-SNAPSHOT
2) com.example:myartifact:jar:1.2.3
----------
1 required artifact is missing.
for artifact:
com.example:mymodule:war:0.0.1-SNAPSHOT
from the specified remote repositories:
nexus (http://nexusserver.local:8080/nexus/content/groups/public)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Jun 09 11:01:24 EDT 2011
[INFO] Final Memory: 17M/247M
[INFO] ------------------------------------------------------------------------
If I were to run simply "mvn install", the jar is installed during "validate," and I can run "mvn clean install" in subsequent builds. However, our build server does not have that flexibility. I've considered the following:
Moving the phase to "pre-clean," but that assumes everyone always uses clean the first time. It wouldn't help if someone ran simply "mvn install."
Copying the execution, with one occurring during "pre-clean" and one occurring during "validate." This covers all the bases, but the copied code leaves a bad taste.
Ideally, I'd love some other option. Is it possible to run clean without dependencies? Or to run a plugin twice without having to fully copy the execution? Thanks!
I ran into a related issue, and I found this question when googling for a solution, so I'll note it here:
mvn clean fails in a multi-module project when there are missing dependencies within the same project, if plugins are invoked during clean.
We invoke the antrun-plugin during the clean phase in some modules, and because of that all dependencies need to be present in the maven repository, including the other modules in the same reactor, which in some cases have not been built yet (say you just bumped the project version, or you're starting off a new project).
This is a maven-antrun bug reported in https://issues.apache.org/jira/browse/MANTRUN-78 - which again leads back to a bug in maven core: https://issues.apache.org/jira/browse/MNG-3283.
My workaround was to provide the developers (and Jenkins) with an alternative way of doing clean (shell/bat script, ant script or some git/hg clean operation), and have them invoke this instead.
I would suggest a similar workaround for your team (or just set up up a shared maven repository internally in your team, use one of the developer machines if necessary).
It looks like you're using nexus. It might be easier to deploy the artifact to the nexus repo as opposed to having to maintain it with this project.
This is untested, but can you not ignore the error from the clean plugin's configuration? As in:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
(This is from Maven Clean Plugin : Ignoring Clean Errors)
Here is one more possibility.
Configure maven to skip clean phase and run clean during initialize. Have not tried this though.
The drawback of this is maven will always clean the output folders.

exec-maven-plugin goal is not started during build

Hallo,
I try to run a main method during my maven build process. Hence, I added the exec-maven-plugin and the following snippet to my pom.xml
<plugin>
<!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>compile-reports</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>at.xyz.dls.util.JasperReportCompiler</mainClass>
</configuration>
</execution>
</executions>
</plugin>
The main class exists and is also executed, when I call it out of the command line:
mvn exec:java -Dexec.mainClass="at.xyz.dls.util.JasperReportCompiler"
I also tried to create a empty new project to test, if an other depencency in the pom causes the problem, but had no success. In the maven settings.xml in the ~/.m2 folder, there is only the entry for an mirror, but no profiles, or anything else, which could cause a problem.
It just does not start it. When I deleted all my artifacts in my repo under org.codehouse, it did not download the exec-maven-plugin. Only when I did the command line call.
Any hints? Thanks in advance!
edit: I forgot to mention I have used "mvn clean install". so it should have passed the compile phase...
edit:
up to now, I could not solve the problem. Thanks for your answers so far! I will try to give all information once again, and hope, one of you guys, find's the fishy part. I have no idea anymore....
What I did:
Delete the folder org/codehouse/mojo in my maven proxy. just to show, when the dependencies are loaded.
show some java and maven version information
build the project with: mvn -clean install (which should pass the test phase to execute my main method)
execute the main method to show, the exec-maven-plugin is loaded only afterwards and works
As far as I understood, calling "mvn clean install" should pass the test phase (the tests are executed...), hence the exec-maven-plugin should be called, which should execute the main method. Am I right?
D:\Eclipse-3.6.1-JSF\ws\exec-test>java -version java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn -version Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200) Java version: 1.6.0_21 Java home: C:\Programme\Java\jdk1.6.0_21\jre Default locale: de_AT, platform encoding: Cp1252 OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows" D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - at.test:exec-test:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory D:\Eclipse-3.6.1-JSF\ws\exec-test\target
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to D:\Eclipse-3.6.1-JSF\ws\exec-test\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to D:\Eclipse-3.6.1-JSF\ws\exec-test\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: D:\Eclipse-3.6.1-JSF\ws\exec-test\target\surefire-reports
T E S T S
Running at.test.ExecTestTest JUnit Test call: end of junit test.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: D:\Eclipse-3.6.1-JSF\ws\exec-test\target\exec-test.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing D:\Eclipse-3.6.1-JSF\ws\exec-test\target\exec-test.jar to D:\maven.m2\repository\at\test\exec-test\0.0.1-SNAPSHOT\exec-test-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Mar 10 12:07:08 CET 2011
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------ D:\Eclipse-3.6.1-JSF\ws\exec-test>mvn exec:java -Dexec.mainClass="at.test.ExecTest"
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'. Downloading: http://pced06.vab.sozvers.at:8080/artifactory/repo/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.pom 6K downloaded (exec-maven-plugin-1.2.pom) Downloading: http://pced06.vab.sozvers.at:8080/artifactory/repo/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.jar 35K downloaded (exec-maven-plugin-1.2.jar)
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - at.test:exec-test:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java [WARNING] Removing: java from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Thu Mar 10 12:07:20 CET 2011
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
D:\Eclipse-3.6.1-JSF\ws\exec-test>
now again the modified 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>at.test</groupId>
<artifactId>exec-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>exec-test</finalName>
<defaultGoal>install</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<!-- http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>compile-reports</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>at.test.ExecTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
The main class:
package at.test;
public class ExecTest {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("##################################");
}
}
And the JUnit Test Class:
package at.test;
import org.junit.Test;
import at.test.ExecTest;
public class ExecTestTest {
#Test
public void testTestTest() {
System.err.println("JUnit Test call:");
ExecTest.main(null);
System.err.println("end of junit test.");
}
}
Finally I found the problem. Was quite a stupid mistake:
In the pom.xml I used the <pluginManagement> around the <plugins> node.
Maven did not complain, but ignored all plugin configurations.
Maybe someone can use this information...
Thanks for your help!
Compile phase may not be appropriate, have you tried
<phase>test</phase>
If you set it on phase compile then you do have to tell maven that is needs to run compile when running. You don't pass any phase with your maven command. You should have mvn compile exec:java ... or higher (test, install, ...).
This is my usage of the exec maven plugin (with mvn clean package):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.xxx.LanguageGenerator</mainClass>
<arguments>
<argument>${project.build.outputDirectory}/build/PMLanguage.xls</argument>
<argument>PM${project.version}</argument>
<argument>${project.build.outputDirectory}/com/laco/projectmaster/props/resources</argument>
<argument>Created during maven build (POM Version:
${project.version})</argument>
</arguments>
</configuration>
</plugin>

Maven mojo plugin, how to define phases that must be triggered before this goal?

hey,
I have a deploy pojo plugin (deploying a war to a remote server). I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.
With the execution elements (according to a documentation), I can attach my goal to a particular phase, for instance bind it to the phase after, so in my case, install phase ...but that's just a workaround.
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>maven-hello-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
simply put, if I place only my goal into the build section, and run it, package phase is not run before. Please help
Maven Mojo plugin, how to define phases that must be triggered before this goal ?
You can't.
I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.
Just bind it to the package phase, your goal will be called after the goals bounds to package by default (so the war will be there).
Here is an example demonstrating this behavior with the Maven AntRun plugin configured like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo message="Hi!!!!!"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
And the output of mvn package:
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3934833 Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # Q3934833 ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) # Q3934833 ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.1:war (default-war) # Q3934833 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [Q3934833] in [/home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/pascal/Projects/stackoverflow/Q3934833/src/main/webapp]
[INFO] Webapp assembled in [317 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-antrun-plugin:1.6:run (default) # Q3934833 ---
[INFO] Executing tasks
main:
[echo] Hi!!!!!
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
The antrun plugin is executed after package, as expected.
You can try use PREPARE_PACKAGE phase in your #Mojo annotation:
#Mojo(name = "myName", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)

emma not generating reports but cobertura does?

basic reason to put the comparison question between these 2 is I am able to generate the reports in site directory(for cobertura) after putting the following plug in information in build section of my pom. But same would not happening with emma. I checked documentation in codehause mojo its almost same for both. My configuration is :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>emma</goal>
</goals>
</execution>
</executions>
</plugin>
but it dont generate reports as expected in site directory but I can see coverage.em generated and classes instrumented every time. am I missing any configuration ?
I can't reproduce your problem. I copied and pasted your configuration snippet into a random pom.xml and running any phase posterior to process-classes triggers emma:emma and the coverage report is generated as expected:
$ mvn clean process-classes
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Project
[INFO] task-segment: [clean, process-classes]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory /home/pascal/tmp/test-project/target
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/pascal/tmp/test-project/target/classes
[INFO] Preparing emma:emma
...
EMMA: runtime coverage data merged into [/home/pascal/tmp/test-project/coverage.ec] {in 93 ms}
[INFO] [emma:emma {execution: default}]
processing input files ...
2 file(s) read and merged in 3 ms
writing [xml] report to [/home/pascal/tmp/test-project/target/site/emma/coverage.xml] ...
writing [html] report to [/home/pascal/tmp/test-project/target/site/emma/index.html] ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
Do you have unit tests in your project? Is the coverage.em file non empty? What happens if you run emma:emma on the command line? Does running mvn with the -X option give you any hint? Can you post some traces that would be helpful?
As a side note, I wouldn't run emma:emma as part of the regular build personally. I would either run the emma:emma goal from the command line or configure the plugin and the reporting section as suggested in the Usage page. But that's another story and doesn't answer the question.
this is really strange: corrected plugin entry is : see the output directory
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<inherited>true</inherited>
<executions>
<execution>
<id>emma</id>
<phase>process-classes</phase>
<goals>
<goal>emma</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</plugin>
emma even does not accept ${project.build.directory}/emma.
conclusion : emma not generated reports when you add any sub-directory to ${project.build.directory} e.g. ${project.build.directory}/emma-reports.