Maven: how to copy & filter *test* resources in an EAR module? - filtering

I'm trying to get Maven to filter & copy two files used for testing.
I've tried putting them in src/test/resources as well as src/test/application (in case it works similar to src/main/application) but nothing happens.
The documentation doesn't say anything about test resources.
Thanks in advance!
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals><goal>read-project-properties</goal></goals>
<configuration>
<files>
<file>${filter.build.props}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<filtering>true</filtering>
<displayName>myapp</displayName>
<version>1.4</version>
<defaultJavaBundleDir>lib</defaultJavaBundleDir>
</configuration>
</plugin>
</plugins>
<filters>
<filter>${filter.build.props}</filter>
</filters>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>

Test resources aren't packaged in the final package (be it JAR, WAR, EAR). I'm not sure what you want to achieve exactly but maybe you're actually looking for a solution based on filtering and profiles (to pick up the wanted filter).

Related

Maven resources plugin disable default packing of /src/resources/

I have a maven project in eclipse and want to use the mave-resources-plugin to pack my resources to a jar. I managed to pack it as I like, but have one issue remaining: the 'default-resources' execution is packing unnecessary files to wrong places.
Is there a way to supress the execution of the default-resources and only use the defined packing instructions?
here is the part, where I use the resource-plugin in pom.xml
<!-- PACK MODULES -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>pack-modules</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/modules/${project.artifactId}</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/modules/${project.artifactId}</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
One could just simply bind the default-resource to lifecycle 'none':
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>

Automatic update of generated css files via m2e

I'm using the lesscss-maven-plugin to generate different css files to the target directory (target\generated-sources) and then use maven-war-plugin to add this directory as an webResouce. Those files will generate perfectly fine.
However the m2e-plugin (version 1.0.0) won't copy those files in the according web-resources folder (m2e-wtp\web-resources), when they have changed. Only when I run a eclipse "maven/update project" changes will be updated. But I want the changes to take affect automatically, when the files have changed. Here is my pom configuration:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions><pluginExecution>
<pluginExecutionFilter>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<versionRange>[1.3.3]</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
....
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/less</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/styles</outputDirectory>
<lessJs>${project.basedir}/tools/less/less-1.7.0.min.js</lessJs>
<includes>
<include>backend/backend-main.less</include>
<include>frontend/frontend-main.less</include>
</includes>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-sources/styles</directory>
<targetPath>styles</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
There are two options:
Use an m2e specific profile
This is similar to the workaround you found, but a bit cleaner as it activates the profile only on m2e and you use a property to set an alternative value for when you package not using m2e.
You create an m2e specific profile that, when activated, will put the files directly in the m2e-wtp/web-resources/styles directory
<properties>
<lesscss.outputDirectory>${project.build.directory}/${project.build.finalName}/styles</lesscss.outputDirectory>
</properties>
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<lesscss.outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</lesscss.outputDirectory>
</properties>
</profile>
</profiles>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/styles</sourceDirectory>
<outputDirectory>${lesscss.outputDirectory}</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
Source: https://github.com/marceloverdijk/lesscss-maven-plugin/issues/8
Use m2e-wro4j
It promises to:
execute wro4j-maven-plugin:run on Eclipse incremental builds, if a change is detected on css, js, less, json, sass resources under wro4j-maven-plugin's contextFolder (src/main/webapp by default)
Source: https://github.com/jbosstools/m2e-wro4j
The idea for my actual workaround was to modify the css file in target\m2e-wtp by "hand".
(First I tried to copy the css files from target\generated-sources to target\m2e-wtp with the maven-resource-plugin, but for a unkown reason, even the maven-resource-plugin was not coping when the filed css files in target\generated-sources gets updated.)
So I came up with this soution: let the lesscss-maven-plugin generate the files twice, one bunch to target\generated-sources and the second one to target\m2e-wtp. Of course the lesscss-maven-plugin has only one output folder, so one has to run the less:compile goal twice. (This is a bit slow, but it works.)
Because one need the second bunch of css files only in eclipse I have added the second execution to an profile.
<profile>
<id>less-eclipse-m2e-workarround</id>
<!--
problem: Eclipse is not updating m2e-wtp folder when css files in generated-sources get modified
workarround: generate the css twice: the normal nonce for generated-sources and a second bunch (only
for eclipse) directly into m2e-wtp folder
to enable this profile add the profile-id to: project/properties/maven/active maven profiles
details: http://stackoverflow.com/questions/23521410/automatic-update-of-generated-css-files-via-m2e
-->
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<executions>
<execution>
<id>for-eclipse</id>
<phase>generate-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

How to generate an aggregated scaladoc for a maven site?

I have a multi-module Maven build and I would like to generate an aggregated Scaladoc in my root module, similar to what the aggregate goal for the maven-javadoc-plugin does. My first attempt was:
<project ...>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<reportPlugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<reports>
<report>doc</report>
</reports>
<configuration>
<aggregateDirectOnly>false</aggregateDirectOnly>
<sendJavaToScalac>false</sendJavaToScalac>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<reports>
<report>aggregate</report>
</reports>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
However, the aggregateDirectOnly property does not seem to have any effect. I always get the Scaladoc for the individual jar-type POMs only.
I also tried to set forceAggregate to true, but it had no effect, too.
How to do this?
This doesn't answer the question exactly as asked, but is a solution that may actually be preferred for mixed java/scala projects until ScalaDoc is capable of parsing JavaDoc comments. It produces a single aggregated JavaDoc that includes documentation from all of the project's Scala source files as well.
The solution is simple: configure Maven to use the GenJavaDoc Scala compiler plugin so that ScalaDocs can be converted to JavaDocs. Then, use the normal javadoc:aggregate goal to aggregate the project as normal.
Here is a sample Maven profile to do this. It configures the Scala compiler to generate the JavaDocs corresponding to the Scala sources, configures Maven to treat the genjavadoc directory created by the Scala compiler as a source directory, and then configures the javadoc plugin itself (this last may be optional if you have no special JavaDoc plugin configuration requirements).
<profile>
<id>javadoc</id>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>doc</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-P:genjavadoc:out=${project.build.directory}/genjavadoc</arg>
</args>
<compilerPlugins>
<compilerPlugin>
<groupId>com.typesafe.genjavadoc</groupId>
<artifactId>genjavadoc-plugin_${scala.binary.full.version}</artifactId>
<version>0.4</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/genjavadoc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<configuration>
<minmemory>64m</minmemory>
<maxmemory>2g</maxmemory>
<outputDirectory>${project.build.directory}</outputDirectory>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
</plugins>
</build>
</profile>

How can we make this maven POM.xml more professional? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
It is the first time we're trying maven with google app engine, google web toolkit (platform, gwtp) and eclipse. We put this up with code we found here and there. We wonder if this POM file can be improved and how, since we're pretty sure it can be improved, particularly, the build section:
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.feeling</groupId>
<artifactId>order2012</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>com.feeling.order2012</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwt.version>2.4.0</gwt.version>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<gwtp.version>0.6</gwtp.version>
<gae.version>1.6.0</gae.version>
<gae.home>${user.home}/.m2/repository/com/google/appengine/appengine-java-sdk/${gae.version}/appengine-java-sdk-${gae.version}</gae.home>
<persistence-api.version>1.0</persistence-api.version>
<jsr107cache.version>1.1</jsr107cache.version>
<gin.version>1.5.0</gin.version>
<guice.version>3.0-rc3</guice.version>
<aopalliance.version>1.0</aopalliance.version>
<gwt-maven-plugin.version>2.4.0</gwt-maven-plugin.version>
<maven-gae-plugin.version>0.9.2</maven-gae-plugin.version>
<maven-clean-plugin.version>2.3</maven-clean-plugin.version>
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
<maven-deploy-plugin.version>2.5</maven-deploy-plugin.version>
<maven-eclipse-plugin.version>2.8</maven-eclipse-plugin.version>
<maven-javadoc-plugin.version>2.7</maven-javadoc-plugin.version>
<maven-resources-plugin.version>2.5</maven-resources-plugin.version>
<slf4f.version>1.6.1</slf4f.version>
<maven-source-plugin.version>2.1.2</maven-source-plugin.version>
<maven-checkstyle-plugin.version>2.6</maven-checkstyle-plugin.version>
<localJarDirectory>/Users/healuser/Documents/myGAE10/lib</localJarDirectory>
</properties>
<dependencies>….</dependencies>
<repositories>….</repositories>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>target/www/WEB-INF/classes</outputDirectory>
<plugins>
<!-- Add source folders to test classpath in order to run gwt-tests as
normal junit-tests <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
! - - Folder for generated testing stuff - -
<systemProperties>
<property>
<name>gwt.args</name>
<value>-out target/www</value>
</property>
</systemProperties>
</configuration>
</plugin> -->
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<configuration>
<encoding>${project.encoding}</encoding>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/www</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Eclipse configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin.version}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
<projectnature>com.google.appengine.eclipse.core.gaeNature</projectnature>
<projectnature>net.sf.eclipsecs.core.CheckstyleNature</projectnature>
</additionalProjectnatures>
<additionalConfig>
<file>
<name>.checkstyle</name>
<location>/checkstyle/eclipse-checkstyle.xml</location>
</file>
</additionalConfig>
<sourceIncludes>
<sourceInclude>*.ui.xml</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<!-- GWT configuration -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt-maven-plugin.version}</version>
<configuration>
<appEngineVersion>${gae.version}</appEngineVersion>
<appEngineHome>${gae.home}</appEngineHome>
<logLevel>INFO</logLevel>
<style>
$ {
gwt.style
}
</style>
<hostedWebapp>target/www</hostedWebapp>
<server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server>
<copyWebapp>true</copyWebapp>
<runTarget>order2012.html</runTarget>
</configuration>
<executions>
<execution>
<id>gwtcompile</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- AppEngine configuration -->
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>${maven-gae-plugin.version}</version>
<configuration>
<sdkDir>${gae.home}</sdkDir>
</configuration>
<executions>
<execution>
<id>install-server-jar</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
<execution>
<id>deploy</id>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>remove-gwt-user-jar</id>
<phase>post-installation-test</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</directory>
<includes>
<include>gwt-user*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp/order2012</directory>
</fileset>
<fileset>
<directory>src/main/webapp/WEB-INF/classes</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<versionRange>[0.8.1,)</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Thank you!
Custom Properties are great but don't use them just because they exist. Use them to eliminate redundancy and/or defer management to parent POMs. Other than that, I don't see anything wrong per the scope of your question.
Most of your config would be common to any gae-gwt-eclipse-maven project. So you could create a project to standardise that configuration (say gae-gwt-eclipse-base, with <packaging>pom</packaging>) containing all that, then your real project would inherit from that POM and divest itself of all the boilerplate you've listed. Indeed it might be completely empty aside from the identifiers and <parent> section, which would amount to declaring "This is a standard GAE-GWT-Eclipse project."
If you've only got one GAE-GWT-Eclipse project, it's hard to be sure what's common and what's specific, but I think it might be worth doing all the same.
Another improvement would be to put configuration into the pluginManagement section instead of plugins.
pluginManagement says, "If I should use these plugins, here's the configuration I'll want (unless I choose to override it). But I'm not saying I will use them." Whereas the plugins section says, "I want you to execute these plugins when you build this project," and maybe also, "and use this configuration rather than anything you've inherited."

Using Maven for deployment

I have this task for the project with 4 nested subprojects using Maven:
For each child: jar-up resource directory including project dependencies
Move up to the parent project
With a single command extract all created archives into various remote destinations (full install), that may include http server, app server, file server, etc. (mostly *NIX). Destination is provided on subproject level
It should also be possible to unzip/copy from the individual subproject (partial install)
Files are not Java - mostly various scripts and HTML
I'm looking at the various plugins to help with the task: assembly, dependency, antrun, unzip. Dependency looks promising but I need to unzip not only dependency jars but the (sub)project content as well. Also since I can't really tight the operation to the Maven lifecycle how would I trigger remote install? mvn dependency:unpack? That's not very descriptive or intuitive. Is is possible to create a custom goal (e.g. project:install) without writing a plugin?
Using Maven is company standard so please do not offer alternatives - I'm pretty much stuck with what I have
Ok, I think the following might do what you need. The drawback of this approach is that there will be an interval between each deployment as the subsequent build is executed. Is this acceptable?
Define a profile in each project with the same name (say "publish"). Within that profile you can define a configuration to use the antrun-plugin to deliver the files with FTP (see below).
In the parent project you'll have a modules element, defining each project as a module. If you run mvn install -P publish, each project will be built in turn with the publish profile enabled, and the final artifact published to the target during the install phase. If you need to deploy additional files, modify the include element accordingly.
Note the parameters for the FTP task have been set as properties, this allows them to be overridden from the command-line and/or inherited from the parent POM.
<profiles>
<profile>
<id>publish</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory}">
<include
name="${project.build.finalName}.${project.packaging}"/>
</fileset>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
<properties>
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
Update: based on your comment: You could use the dependency plugin to download each dependency, except that a parent can't have a dependency on a child, and it will be built before the child. It would have to be another project. you also need to have somewhere the information for where to deploy them to. At the moment you have the target information in the individual projects so it isn't accessible in the deployer project.
Taking this approach, you can define multiple profiles in the new project, one for each artifact. Each profile defines a dependency:copy execution to obtain the jar and an antrun execution for one of the projects. Common configuration (such as the dependencies for the antrun plugin) can be pulled out of the profiles. Also be aware that the properties will be merged if you define multiple profiles, so yo may need to qualify them with the artifact name, for example ftp.artifact1.host.
<profiles>
<profile>
<id>deploy-artifact1</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>name.seller.rich</groupId>
<artifactId>artifact1</artifactId>
<version>1.0.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/deploy-staging</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory} includes="deploy-staging/"/>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<properties>
<!--if the properties differ between targets, qualify them with the artifact name-->
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
Below POM will help to copy jar's file from project build directory to remote SFTP/FTP server.
Use command mvn install -Dftp.password=password
Since I want to pass password from command prompt for security reason, I have used -Dftp.password=password
After execution of above command all the jar files from maven project target folder will be deployed in MAVEN folder on server.com
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<scp todir="user#server.com:/MAVEN/"
sftp="true" port="22" trust="true" password="${ftp.password}"
failonerror="false" verbose="true" passphrase="">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</scp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
Does not work without passphrase.
<profile>
<id>publish</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>scp</id>
<phase>deploy</phase>
<configuration>
<tasks>
<scp todir="user#host:some/remote/dir"
sftp="true"
keyfile="${user.home}/.ssh/devel-deploy.id_dsa"
failonerror="false"
verbose="true"
passphrase="nopass"
>
<fileset dir="${project.build.directory}">
<include
name="${project.build.finalName}.${project.packaging}"/>
</fileset>
</scp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
However, my favourite is
<profile>
<id>upload-devel</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>upload-devel</id>
<phase>deploy</phase>
<configuration>
<target>
<exec executable="rsync" failonerror="false">
<arg value="-aiz" />
<arg value="${project.build.directory}/${project.artifactId}.${project.packaging}" />
<arg value="user#host:some/remote/dir/." />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
though I don't know how compatible that is over different platforms.
I would look at using the maven-assembly-plugin to do this.
Something like this can be used to grab the files from the child projects and stuff them in output directories.
<assembly>
<id>xyzzy</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>../subproject1/target/</directory>
<outputDirectory>/foo</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>../subproject1/target/html-output/</directory>
<outputDirectory>/foo</outputDirectory>
<includes>
<include>*.html</include>
<include>*.js</include>
<include>*.css</include>
</includes>
</fileSet>
<fileSet>
<directory>../subproject2/target/</directory>
<outputDirectory>/bar</outputDirectory>
<includes>
<include>**/**</include>
</includes>
<excludes>
<exclude>**/*.exclude-this</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
Maven is not really designed to deploy jars to a remote location; its main use is compiling and packaging artifacts. The assembly and dependency targets are primarily used to gather dependencies and files to package into an artifact.
Having said that, maven does have a deploy goal which uses a component called wagon. This is primarily intended to deploy to a maven repository. There is a plugin called Cargo that can be used to deploy artifacts to a remote server, but that doesn't explode the jar contents by itself (it relies on the target app server to do all that). You might be able to extend the Maven Wagon functionality yourself.
Also, it is possible to package a custom lifecycle, but that is getting into some pretty low level maven mojo (pun intended).