Unable to exclude folders from war file using regex - regex

I'm attempting to exclude all of the js/backbone directories with the exception of the libs directory from my war file. My pom file entry is as follows:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>
%regex[js/backbone/[^l].*/]
</packagingExcludes>
</configuration>
</plugin>
Unfortunately, no directories are being excluded. Any help will be greatly appreciated!!

Try to use a negative lookahead (?!..) to exclude the lib directory:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>
%regex[js/backbone/(?!libs/).*]
</packagingExcludes>
</configuration>
</plugin>
(?!libs/) means not followed by libs/

Related

nar-maven-plugin eclipse API Incompatibility

I'm using eclipse to compile/run my projects. I tried to use maven on c++ projects with nar-maven-plugin to build them. It works well as i launch maven goals in command line.
But when i import my maven project in eclipse, i have the following errors :
Execution default-nar-compile of goal
com.github.maven-nar:nar-maven-plugin:3.2.3:nar-compile failed: An API
incompatibility was encountered while executing
com.github.maven-nar:nar-maven-plugin:3.2.3:nar-compile:
java.lang.NoSuchMethodError:
org.codehaus.plexus.util.DirectoryScanner.setupMatchPatterns()V
----------------------------------------------------- realm = plugin>com.github.maven-nar:nar-maven-plugin:3.2.3 strategy =
org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
...
Moreover, eclipse seems to manage my project as a Java project instead of a C project.
Note : i'm using
Eclipse 4.3.1
M2E 1.4.0
CDT 8.3.0
My pom.xml
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>helloworld-cplusplus-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>nar</packaging>
<name>Helloworld</name>
<properties>
<rootdir>${project.basedir}</rootdir>
<nar.linker>gpp</nar.linker>
<nar.arch>x86</nar.arch>
<nar.os>Windows</nar.os>
</properties>
<build>
<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>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<versionRange>[3.2.3,)</versionRange>
<goals>
<goal>nar-test-unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<fork>true</fork>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<linker>
<name>g++</name>
</linker>
<libraries>
<library>
<type>executable</type>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sample</groupId>
<artifactId>helloworld-shared-library-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>nar</type>
</dependency>
</dependencies>
</project>
If someone is using nar-maven-plugin with eclipse can help me :). I would really like to use it on eclipse.
Thanks!

packagingExcludes and maven property variable

I have a folder structure as shown below under src/main/webapp/
I have a maven property ${sencha.env} that can be either of development | testing or production. I want to exclude the others from the build directory while making WAR. I am trying the below but its not working. Please guide -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp/build/${sencha.env}/BACK</directory>
</resource>
</webResources>
<packagingExcludes>.sencha/**,app/**,ext/**,sass/**,%regex[build/(?!${sencha.env})]</packagingExcludes>
</configuration>
</plugin>
Please notice :
%regex[build/(?!${sencha.env})] in packagingExcludes
thanks!
You are very close; you need to have %regex[build/(?!${sencha.env}/).*]. Notice the .* which means that you are excluding every path below build/(?!${sencha.env}/.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp/build/${sencha.env}/BACK</directory>
</resource>
</webResources>
<packagingExcludes>.sencha/**,app/**,ext/**,sass/**,%regex[build/(?!${sencha.env}/).*]</packagingExcludes>
</configuration>
</plugin>

Could cxf maven plugin generate classes for a directory of wsdl files?

I use cxf-codgen-plugin in maven to generate classes for web services. Here is a part of my pom.xml
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/wsdl/ws1.wsdl</wsdl>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/wsdl/ws2.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is every time I want to add a new WSDL I had to add a line in the pom.xml like this:
<wsdlOption>
<wsdl>${basedir}/wsdl/ws2.wsdl</wsdl>
</wsdlOption>
What I want to do is to specify a directory and cxf will generate classes for all the WSDL files in this directory.
Is there a way to do this?
Thanks.
I found the way to do this:
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlRoot>${basedir}/wsdl</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>

regex for html tags in pom xml using maven-replacer-plugin

I am trying to find and replace an html tag with pom.xml using maven-replacer-plugin.
With the current configurations, I am getting an error that "Missing end tag address" it means pom is not escaping open tag < and close tag >.
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>replace-script-reset-path-variable</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/books/*.xml</include>
</includes>
<replacements>
<replacement>
<token>/<(address)>/</token>
<value>/<(address)>//abc.com</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
The aim is to replace all lines in source file which has html tag <address> with <address>abc.com/
Here is the sample of my source file:
<address>books/category/ebooks1/index.html</address>
<address>books/category/ebooks2/index.html</address>
<address>books/category/ebooks3/index.html</address>
<address>books/category/ebooks4/index.html</address>
<address>books/category/ebooks5/index.html</address>
After applying regex, the expected source file should be:
<address>abc.com/books/category/ebooks1/index.html</address>
<address>abc.com/books/category/ebooks2/index.html</address>
<address>abc.com/books/category/ebooks3/index.html</address>
<address>abc.com/books/category/ebooks4/index.html</address>
<address>abc.com/books/category/ebooks5/index.html</address>
You need to escape < in the actual POM file as <, and similarly for <,
I'd suggest you to use token and value files. In them you can simply write just this:
<address>
and
<address>abc.com
And then you just enter correct path to the file. E.g.:
<tokenFile>resources/common/address-token.txt</tokenFile>
<valueFile>resources/common/address-value.txt</valueFile>
For more details please refer to Replacer usage guide

maven-ear-plugin unpack, filter and repack jarModule

a jarModule that is packaged in my ear file contains a persistence.xml file that I need to remove as part of the package phase. The best I can do is with:
<JarModule>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<unpack>true</unpack> -->
</JarModule>
<packagingExcludes>*/META-INF/persistence.xml,*/META-INF/orm.xml</packagingExcludes>
but I need the jar to be repacked before the packaging the ear.
Any suggestions?
Thanks
You can use the TrueZIP Maven PLugin to remove files from an archive:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>remove-from-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>remove</goal>
</goals>
<configuration>
<fileset>
<directory>${project.build.directory}\<someFolders>\<I-contain-persistence-xml.jar></directory>
<includes>
<include>**\persistence.xml</include>
<include>**\orm.xml</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Archives (*.jar, *.war, ...) can be used like directories with TrueZIP. As shown on the usage page you can move or copy files in archives easily.