Using Maven for deployment - 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).

Related

How to combine the update of a m2e maven project in Eclipse with a "maven build" run configuration to execute pom.xml

After updating my source code I currently have to manually execute two actions:
Update my maven projects with Alt+F5 (this overrides the Eclipse project settings with corresponding settings from the pom.xml files, e.g. udpates the classpath files)
Run my main pom.xml file with a maven run configuration (this executes all plugins of the pom.xml file)
Is there a way to
automatically execute a run configuration after updating m2e projects? or
include an m2e project update in a run configuration or
write an ant file to execute both, the m2e project update and the maven build or
adapt the m2e plugin to not just update the Eclipse settings but execute all plugins of the pom.xml file (I use packaging pom, not jar) ?
If I export my run configuration for the maven build it looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean install "/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
<intAttribute key="M2_THREADS" value="4"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value="../PowerShare/maven_settings.xml"/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dmaven.multiModuleProjectDirectory="/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:PowerTools}"/>
</launchConfiguration>
Here is an example main pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- HEADER **************************************************************************************************************** -->
<modelVersion>4.0.0</modelVersion>
<groupId>isi.power.tools</groupId>
<artifactId>PowerTools</artifactId>
<version>0.0.1-SNAPSHOT</version> <!-- is available as variable ${project.version} -->
<packaging>pom</packaging>
<!-- CUSTOM PROPERTIES ***************************************************************************************************** -->
<properties>
<!-- set encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<!-- RESOURCES *********************************************************************************************************** -->
<resources>
<resource>
<!-- add java source folder as resource to copy fxml files -->
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- enable replacement of variable place holders with values, e.g. to include version information -->
<filtering>true</filtering>
</resource>
</resources>
<!-- PLUGINS ************************************************************************************************************** -->
<plugins>
<!-- ### RESOURCES ### phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>resource-execution</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ### COMPILE ### phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<!-- specify current java version here: -->
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>compile-execution</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>isi.power.ace.test-compile-execution</id>
<phase>isi.power.ace.test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ### PACKAGE ### phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>package-execution</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ### INSTALL ### phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-execution</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
<execution>
<id>install-file-execution</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>isi.power.tools</groupId>
<artifactId>PowerTools</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${project.basedir}/target/PowerTools-${project.version}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- MODULES ************************************************************************************************************** -->
<modules>
<module>../PowerCluster</module>
</modules>
<!-- DEPENDENCIES ********************************************************************************************************* -->
<dependencies>
<!-- Dependencies on other workspace projects -->
<dependency>
<groupId>isi.power.share</groupId>
<artifactId>PowerShare</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>PowerACEISI_trunk</groupId>
<artifactId>PowerACEISI_trunk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>isi.power.cluster</groupId>
<artifactId>PowerCluster</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
The answer to your question is really dependent on what plugins you're trying to execute and at what point you need them executed.
From what I know, m2e adds its own builder to your eclipse project, and it can invoke plugins you have defined in your pom.xml
That being said, eclipse's build only brings you up to the point of running "maven compile".
If you have plugins that need execution at the package phase, you will have to manually run a "maven package" configuration.
If you have plugins that execute at any phase up to "compile", they can also run in an eclipse build. However, you might need to use lifecycle-mappings to get them to actually run.
You can either do that in Eclipse settings, but I prefer to map specific plugins to my needs in the pom itself, so everyone can use it.
A mapping example:
<build>
<pluginManagement>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<versionRange>[1.0-alpha-3,)</versionRange>
<goals>
<goal>filter-sources</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</pluginManagement>
</build>
this will cause the templating-maven-plugin run the filter-sources goal on every eclipse build. Note you can determine if you want the plugin executed on configuration (full) builds (after Project Clean or Maven Update), and/or on incremental builds (after editing some source code)
you can also set
<action>
<ignore />
</action>
which will cause m2e to ignore the plugin during its builds (it will still run when launching a maven run configuration)
Some plugins don't always play nicely with eclipse, for example if you need to unpack/copy a dependency you have as a project in your workspace. There are workarounds though.
Let me know if you need any more help or if I wasn't clear anywhere
I found a solution that is based on EclipseScript: http://eclipsescript.org
It requires some fine tuning but works in principle. After installing the EclipseScript plugin I created a file updateMavenProject.eclipse.js including the code below. The file can be executed with Alt+R if it is open or with Ctrl+4 (plus selection).
//This script is based on EclipseScript, see following page for more information: http://eclipsescript.org/
//Execute this script by pressing Alt+R
//This script:
// * updates the maven project (like Alt+F5 ...: apply information from pom.xml file to eclipse project settings, e.g. udpate classpath file) and
// * runs the pom.xml file as maven build (like "Run as maven build": executes all maven plugins of the pom.xml file)
// (the run configuration "updateMavenProject.eclipse.js" has to exist)
//#region SCRIPT COMMANDS
//update maven project ************
//get workbench
//var workbench = Packages.org.eclipse.ui.PlatformUI.getWorkbench();
//create maven update job
var currentProject = eclipse.resources.currentProject
var projects = [ currentProject ];
var updateMavenJob = Packages.org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob(projects);
//execute maven update job
var progressMonitor = Packages.org.eclipse.core.runtime.NullProgressMonitor();
eclipse.console.println("Updating maven project...")
updateMavenJob.runInWorkspace(progressMonitor);
eclipse.console.println("Updating maven project finished.")
//execute maven build **************
var launchConfiguration = getLaunchConfiguration("My_Maven_Run_Configuration");
var debugTools = Packages.org.eclipse.debug.ui.DebugUITools();
eclipse.console.println("Launching Maven run configuration asynchonously.")
debugTools.launch(launchConfiguration, Packages.org.eclipse.debug.core.ILaunchManager.RUN_MODE);
//show end message *****************
eclipse.window.alert("finished script. please wait until console is finished, too.");
//#end region
//#region METHODS
//
// Returns the launch configuration with the given name or null if it does not exist
//
function getLaunchConfiguration(nameOfWantedLaunchConfiguration){
var launchManager = Packages.org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
var launchConfiguration = null;
var launchConfigurations = launchManager.getLaunchConfigurations();
launchConfigurations.forEach(
function(currentLaunchConfiguration){
var name = currentLaunchConfiguration.getName();
//eclipse.console.println(name);
if (name.equals(nameOfWantedLaunchConfiguration)){
launchConfiguration = currentLaunchConfiguration;
}
}
);
return launchConfiguration;
}
//#end region

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 remove directories from final build zip archive using maven 3

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.

Setting up third party libraries for UIMA AS application

I have an UIMA AS application that is using third party libraries. I would like to know the following:
1. Where (location) we can add these third libraries such that the deployed application to be aware of them and not throwing "ClassNotFoundException"?
A brute force solution for me, was to add them directly in the UIMA AS "lib/" folder, but this solution was just for testing and is not acceptable in production.
2. How can be set up this third party libraries when generating PEAR file in a such a way that deploying the application will consider them and won't be necessary to manually add them to the classpath?
I'll look forward for your answer. Thank you.
For the first question: my approach was
1. Create a lib folder for the third library
2. create a script that adds to the UIMACLASSPATH the lib folder
#set UIMA_CLASSPATH=%UIMA_CLASSPATH%;../../lib;../../bin
call deployAsyncService.cmd
for the second question:
I use the maven plugin for generating the pear file.
Excerpt from the pom.xml (maven related)
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- Copy the dependencies to the lib folder for the PEAR to
copy -->
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/lib</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.uima</groupId>
<artifactId>PearPackagingMavenPlugin</artifactId>
<version>2.3.1</version>
<!-- if version is omitted, then -->
<!-- version is inherited from parent's pluginManagement section -->
<!-- otherwise, include a version element here -->
<!-- says to load Maven extensions (such as packaging and type
handlers) from this plugin -->
<extensions>true</extensions>
<executions>
<execution>
<configuration>
<classpath>
<!-- PEAR file component classpath settings -->
$main_root/lib/*.jar
</classpath>
<mainComponentDesc>
<!-- PEAR file main component descriptor -->
</mainComponentDesc>
<componentId>
<!-- PEAR file component ID -->
${project.artifactId}
</componentId>
<datapath>
<!-- PEAR file UIMA datapath settings -->
$main_root/
</datapath>
</configuration>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Clean the libraries after packaging -->
<execution>
<id>CleanLib</id>
<phase>clean</phase>
<configuration>
<tasks>
<delete quiet="false" failOnError="false">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
</delete>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
You can extract the compiled classes from your external jars and pack them into your UIMA component jar. As for the PEAR file, you might find that a similar approach works (unpack the pear, add the .class files, repack)

How to check and access javadoc/source for Maven Artifacts

I am writing a Maven plugin which needs to check if a certain project
dependency has javadocs and sources available... and if so, would like
to download them and archive them on a server.
I cannot find out how to check if the javadocs and source are available
or how to access them if they are.
Any help would be appreciated.
You can reference additional artifacts by adding the classifier tag to a dependency. The classifier is the additional part of the artifact's name in the repository, e.g junit-4.5-sources.jar
So to directly declare a dependency on the junit sources jar you can specify it as follows:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
If you want to download all the dependency sources, use the maven-dependency-plugin's copy-dependencies goal specifying the classifier sources. The following example defines two executions, one for sources and one for javadocs.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>sources</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
</configuration>
</execution>
<execution>
<id>javadocs</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/javadocs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you want to package all the downloaded artifacts into a zip, you can use the maven-assembly-plugin to create an archive of the project. The example below are the contents of an assembly descriptor file to include the sources and javadocs directories:
<assembly>
<id>project</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>${project.build.directory}/sources</include>
<include>${project.build.directory}/javadocs</include>
</includes>
</fileSet>
</fileSets>
</assembly>
To reference the assembly, add a plugin configuration to your pom. This assumes the above contents have been put in src/main/assembly/sources.xml (make sure it is defined after the dependency configuration above):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/sources.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>