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 ...
Related
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?
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.
When the build is ready i have p2 folder in all build archives for different platforms.As i understand it's imposible to exclude p2 directory from archives on building stage. So I try pack archive myself instead of using archive-products execution.
The problem is if i want to make archives for others platform or architecture I will need to change pom.
Now i have the following build schema:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>pack-zip-files</id>
<phase>package</phase>
<configuration>
<target>
<zip basedir="${project.build.directory}/products/xxx/win32/win32/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-win32.win32.x86.zip"
excludes="${exclude_p2}" />
<zip basedir="${project.build.directory}/products/xxx/linux/gtk/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-linux.gtk.x86.zip"
excludes="${exclude_p2}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The quiestion is how to remove p2 folder from all zip files?
What you are doing now is really the only way to do it. You could change the packaging type to eclipse-application and that directory won't be created, but it is a deprecated packaging type and has a whole slew of problems.
The only way to help with multiple POM support would be to put that POM configuration into a profile and have your projects that build products inherit from it. You can also use the osgi.os osgi.arch properties in place of hard-coding things like win32 and linux.
I have a fairly simple Maven project:
<project>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
However, I get the following error in m2eclipse:
Description Resource Path Location Type
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. pom.xml /jasperreports-test line 60 Maven Project Build Lifecycle Mapping Problem
Why do I care if m2eclipse doesn't "support" this task? Maven does, and that's all I really care about. How can I get this error in my project to go away?
It seems to be a known issue. You can instruct m2e to ignore this.
Option 1: pom.xml
Add the following inside your <build/> tag:
<pluginManagement>
<plugins>
<!-- Ignore/Execute plugin execution -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins></pluginManagement>
You will need to do Maven... -> Update Project Configuration on your project after this.
Read more: http://wiki.eclipse.org/M2E_plugin_execution_not_covered#m2e_maven_plugin_coverage_status
Option 2: Global Eclipse Override
To avoid changing your POM files, the ignore override can be applied to the whole workspace via Eclipse settings.
Save this file somewhere on the disk: https://gist.github.com/maksimov/8906462
In Eclipse/Preferences/Maven/Lifecycle Mappings browse to this file and click OK:
This is a problem of M2E for Eclipse M2E plugin execution not covered.
To solve this problem, all you got to do is to map the lifecycle it doesn't recognize and instruct M2E to execute it.
You should add this after your plugins, inside the build. This will remove the error and make M2E recognize the goal copy-depencies of maven-dependency-plugin and make the POM work as expected, copying dependencies to folder every time Eclipse build it. If you just want to ignore the error, then you change <execute /> for <ignore />. No need for enclosing your maven-dependency-plugin into pluginManagement, as suggested before.
<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>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
If copy-dependencies, unpack, pack, etc., are important for your project you shouldn't ignore it. You have to enclose your <plugins> in <pluginManagement> tested with Eclipse Indigo SR1, maven 2.2.1
To make it work, instead of ignoring it, you can install the m2e connector for the maven-dependency-plugin:
https://github.com/ianbrandt/m2e-maven-dependency-plugin
Here is how you would do it in Eclipse:
go to Window/Preferences/Maven/Discovery/
enter Catalog URL: http://download.eclipse.org/technology/m2e/discovery/directory-1.4.xml
click Open Catalog
choose the m2e-maven-dependency-plugin
enjoy
Despite answer from CaioToOn above, I still had problems getting this to work initially.
After multiple attempts, finally got it working.
Am pasting my final version here - hoping it will benefit somebody else.
<build>
<plugins>
<!--
Copy all Maven Dependencies (-MD) into libMD/ folder to use in classpath via shellscript
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libMD</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!--
Above maven-dependepcy-plugin gives a validation error in m2e.
To fix that, add the plugin management step below. Per: http://stackoverflow.com/a/12109018
-->
<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>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I had the same problem when trying to load Hadoop project in eclipse. I tried the solutions above, and I believe it might have worked in Eclipse Kepler... not even sure anymore (tried too many things).
With all the problems I was having, I decided to move on to Eclipse Luna, and the solutions above did not work for me.
There was another post that recommended changing the ... tag to package. I started doing that, and it would "clear" the errors... However, I start to think that the changes would bite me later - I am not an expert on Maven.
Fortunately, I found out how to remove all the errors. Go to Window->Preferences->Maven-> Error/Warnings and change "Plugin execution not covered by lifecycle..." option to "Ignore". Hope it helps.
I know this is old post but I struggled today with this problem also and I used template from this page: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
and everything works fine under m2e 1.3.1.
When I tried to use
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also got m2e error.
Another option is to navigate to problems tab, right click on error, click apply quick fix. The should generate the ignore xml code and apply it .pom file for you.
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