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>
Related
I want to replace a property in Maven based on a regex. For that I am using the regex-property plugin. Property will contain space-separated entries and I need to create a xml "node" from each of them.
"C:\some\entry D:\another\entry"
(processing here ... below is the content of variable after processing)
<fileset dir="C:\some\entry" includes="*.myext" />
<fileset dir="D:\another\entry" includes="*.myext" />
The replaced property then should be later used to copy given artifacts:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy files</id>
<phase>initialize</phase>
<configuration>
<tasks>
<copy todir="${project.basedir}/somedir">
${processedPaths} <!-- THIS WILL EXPAND TO <fileset ... /> -->
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I have something that almost works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>testprop</name>
<value>${testprop}</value>
<regex>([^\s]+)</regex>
<replacement><fileset dir="$1" includes="*.myext" /></replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
But the problem here is that the replacement is escaped somewhere along the way. So the resulting property would contain <fileset dir\="C\:\\some\\entry" includes\="*.myext" />, which is not desired.
This approach does seem hackish, but I could not find any other way that would allow me to copy files from directories specified in a property.
I did not mention an important thing - this project is being created from an archetype. Generating a project from an archetype means one can use Velocity syntax. This simplifies my particular usecase quite a bit. The working exerpt of pom.xml looks like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy files</id>
<phase>initialize</phase>
<configuration>
<tasks>
<copy todir="${project.basedir}/${somedir}">
#foreach( $file in $filesPath.split(",") )
<fileset dir="$file.trim()" includes="*.myext"/>
#end
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The #foreach directive will be picked up by Velocity and will print out a <fileset ... line for each comma-separated entry in the $filesPath property.
And in archetype-metadata.xml is declared:
<requiredProperty key="filesPath"/>
Calling mvn archetype:generate ... "-DfilesPath=/some/path/, /other/path" will then generate the correct nodes:
<copy todir="${project.basedir}/${somedir}">
<fileset dir="/some/path" includes="*.myext"/>
<fileset dir="/other/path" includes="*.myext"/>
</copy>
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!
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>
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.
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/