Trouble debugging Maven integration test in Eclipse - eclipse

I'm using Eclipse Indigo on Win XP, with Maven 3.0.3. I have created a Selenium 2 test that I wish to debug in Eclipse. It is set up to run in the Maven integration test phase. I'm using the Maven Cargo plugin with Tomcat as the container. Here's the relevant section from my pom.xml ...
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<downloadDir>${project.build.directory}/downloads</downloadDir>
<extractDir>${project.build.directory}/extracts</extractDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>8080</cargo.servlet.port>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<pingURL>http://localhost:8080/${project.artifactId}</pingURL>
<pingTimeout>30000</pingTimeout>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</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>
</configuration>
</execution>
</executions>
</plugin>
Problem is, when I right click on my integration test in Eclipse, select "Debug As" and then choose my Debug Configuration (which is just the maven goal "clean install -Dtest=TableIntegrationTest"), the execution runs without hitting the breakpoint I set (http://screencast.com/t/at0AKWwxslE). How can I do step-through debugging on a JUnit/Selenium integration test in Eclipse?

Maven's integration tests by default run in a forked JVM. Therefore, eclipse is unable to attach to the forked JVM and see the breakpoints.
You can force the integration-test to run in the same JVM with the -DforkMode=never option.
More here: http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
Edit: Updated link

Related

auto deploy of tomcat server through tomcat plugin

i want to auto deploy my tomcat server(which is not in eclipse) through my tomcat maven plugin...so i mentioned the goal as run....still is not running....how to mention the goal in tomcat plugin to start the tomcat server by default.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat-run</id>
<phase>package</phase>
<goals>
<goal>tomcat7:deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>myserver</server>
<path>/${project.artifactId}</path>
<username>username</username>
<password>password</password>
</configuration>
</plugin>

How to pass custom configuration file to Akka application with Maven?

I'm developing an Akka application using Maven. For testing, I use scalatest. When I run the tests with the configuration in application.conf, everything goes smoothly. But when I try to use custom files it just doesn't work (e.g. I have one common.conf and other files that include that one for adjusting time-scale in Jenkins and so on). I tried running the tests with mvn -Dconfig.file=/path/to/myenv.conf test and -Dconfig.resource=/path/to/myenv.conf test but no luck. I'm using Akka 2.4.0 and Scala 2.11.7.
P.S. Here is the configuration of the plugins in my pom.xml:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<!--arg>-make:transitive</arg-->
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<stdout>W</stdout>
<!-- Skip coloring output -->
<junitxml>.</junitxml>
</configuration>
<executions>
<execution>
<id>scala-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Thanks a lot!
Well, I actually found a way, just adding this to my scalatest maven plugin worked:
<argLine>-Dconfig.resource=/local.conf</argLine>
Is there a way to pass this externally to mvn test?

Artifact has not been packaged yet

I am letting Maven copy some dependency files into a specific location for a GWT project. The maven-dependency-plugin does the job and so far it works. The only Problem is that I'm getting an error from Eclipse that says:
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.
I have tried to change the <phase> but that did not work. How can I get rid of that error and why is it there because Maven builds as intended.
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/war/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
I got the same error and I solved this issue with a workaround. I have compiled and installed the project with Maven in a console outside Eclipse IDE. After I have refreshed the project inside Eclipse IDE and error has disappeared.
There is a solution similar to s1moner3d answer which doesn't require changes to pom.xml file.
Go to Window > Preferences > Maven > Lifecycle Mappings and click on the Open workspace lifecycle mappings metadata button.
Than add pluginExecution entry like in the code below. If the file is empty, copy the entire content below. You might need to change versionRange.
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>2.10</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
In order for this to take effect go back to Preferences and click Reload workspace lifecycle mappings metadata. Update Maven projects and / or rebuild. The error should be gone.
Useful if you cannot or don't want to modify pom.xml for any reasons but want to stop your Eclipse m2e from executing particular goal of a particular plugin.
I solved by setting the plugin phase to prepare-package. I know it's still a workaround, but I think it's cleaner than compile externally.
<plugins>
[...]
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
[YOUR_CONFIGURATION]
</configuration>
</execution>
</executions>
</plugin>
[...]
</plugins>
EDIT:
This is not fully solving: sometimes it works, other times not.
The final solution is to use the Lifecycle Mapping Maven Dummy Plugin through an eclipse-only maven profile:
<profile>
<id>only-eclipse</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>${maven-dependency-plugin.version}</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
I had to wrap plugins tag under pluginManagement to make the error go away.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>../../lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
I used this answer to fix the problem. That 2017 update to m2eclipse means you don't need to use the pluginManagment xml as in s1moner3d's answer, and so that gets rid of the "POM not found" warning I got for the 'lifecycle-mapping' artifactId tag when I included it.
To summarize:
You don't need a pluginManagment block for org.eclipse.m2e
Add a <?m2e ignore?> tag in your <execution> tag(s) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<?m2e ignore?>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
...{your configuration} ...
</configuration>
</execution>
</executions>
</plugin>
https://www.eclipse.org/m2e/documentation/release-notes-17.html#new-syntax-for-specifying-lifecycle-mapping-metadata
For those returning to this question, it may be useful to report seeing the same problem in Eclipse against maven-dependency-plugin version 2.8. This was in the package phase:
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187. (org.apache.maven.plugins:maven-dependency-plugin:2.8:copy:copy-proguard:package)
In this case upgrading to 3.1.1 solved the problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-proguard</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
...
This issue related to eclipse IDE:
Solution is to update M2E Connector for the maven-dependency-plugin
Steps :
Help ---> Eclipse Marketplace.. then update the plugin.

Maven Javadoc - Unable to generate Javadoc

I have the following dependency and build in my pom file. I'm able to manually create the javadoc with a Maven command. I can also succesfully perform a build. The output doesn't mention javadoc at all. I've also tried leaving out the output directory paths. POM File
Dependency section:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</dependency>
and then the build section:
<build>
<finalName>D</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<outputDirectory>${project.build.directory}/javadoc</outputDirectory>
<reportOutputDirectory>${project.reporting.outputDirectory}/javadoc</reportOutputDirectory>
<version>2.8</version>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The Maven Javadoc plugin doesn't run by default and needs to be bound to one of the default Maven lifecycle phases.
Here's how I would write the plugin's configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<outputDirectory>${project.build.directory}/javadoc</outputDirectory>
<reportOutputDirectory>${project.reporting.outputDirectory}/javadoc</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>site</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
Notice how I added an extra phase element to the execution. This will bind it to the "site" goal so that javadocs are generated when you run mvn site. Check Introduction to the Build Lifecycle if you want one of the default Java build phases.
Also note that I ditched the version parameter; by default, it should use your POM's version anyway.

Maven : How to generate project's war file in two folders

I want that when I run the mvn install, a war can be generated in the /target and an other war in the c:....tomcat 6\deploy directory.
I'm using maven2, Eclipse and m2eclipse. How to do this ??
Thnx :)
You could try to use the maven-antrun-plugin to copy your war to the tomcat deploy directory like this:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="{project.build.directory}/${project.actifactId}-${project.version}.war" tofile="<your tomcat path>/${project.actifactId}-${project.version}.war" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Maybe you don't need to copy the war file if you try the Maven Jetty Plugin. This plugin is for running a web application directly from Maven.
Try the cargo-maven2-plugin. Probably something like this would work:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>deploy-local</id>
<phase>install</phase>
<goals>
<goal>deployer-deploy</goal>
<goals>
</execution>
</executions>
<configuration>
<container>
<containerId>tomcat6x</containerId>
</container>
<configuration>
<type>existing</type>
<home>/your/tomcat/dir</home> <!-- replace as needed -->
</configuration>
</configuration>
</plugin>
... slap that into a profile or the top-level <build><plugins> section and see if it works for you ...