I've been using maven-ear-plugin to create ear bundle and generate application.xml with custom contextRoot (everything works fine). Now I want to create 2 ear bundles and deploy them under different context path, so I defined plugin with 2 executions. But for some reason, maven-ear-plugin ignores contextRoot property and in generated application.xml it is using artifactId instead of contextRoot in both ears (so they have same context-root "app-ui").
Here is my maven-ear-plugin definition:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>app1</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<finalName>app1</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app1-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<execution>
<id>app2</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<finalName>app2</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app2-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
Any suggestions please?
The problem is that you generate the application.xml only once while you need two application.xml. For this you need to put also two executions of the generate-application-xml goal binded on the generate-resources phase of the maven lifecycle in order to generate the application.xml file two times (in two different folders preferably ^^) with two different configurations like this :
<!-- first execution for the first application.xml in folder target/app1/META-INF -->
<execution>
<id>appxml-app1</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-application-xml</goal>
</goals>
<configuration>
<generatedDescriptorLocation>target/app1/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app1-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<!-- first execution for the generation of the ear with the application.xml in folder target/app1 -->
<execution>
<id>app1</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<workDirectory>target/app1</workDirectory>
<finalName>app1</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
</webModule>
</modules>
</configuration>
</execution>
<!-- second execution for the second application.xml in folder target/app2/META-INF -->
<execution>
<id>appxml-app2</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-application-xml</goal>
</goals>
<configuration>
<generatedDescriptorLocation>target/app2/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app2-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<!-- second execution for the generation of the ear with the application.xml in folder target/app2 -->
<execution>
<id>app2</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<workDirectory>target/app2</workDirectory>
<finalName>app2</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
</webModule>
</modules>
</configuration>
</execution>
To improve this, you can use variables to ensure that the folders will be the same for the two executions that concerns app1, etc, this is just a draft ;)
Related
I have a pom as below
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>X.0.0</modelVersion>
<parent>
<groupId>asdasd</groupId>
<artifactId>asdasd</artifactId>
<version>0.334.0-SNAPSHOT</version>
<relativePath>../something/pom.xml</relativePath>
</parent>
<!-- ======================================================================= -->
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>dfdfd</artifactId>
<name>xxxxx</name>
<packaging>content-package</packaging>
<properties>
<sonar.sources>${basedir}/src/main/angular/src</sonar.sources>
<sonar.tests>${basedir}/src/main/angular/src</sonar.tests>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/content/jcr_root</directory>
<excludes>
<exclude>**/*.iml</exclude>
</excludes>
<targetPath>jcr_root</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/content/META-INF/xxx/definition</directory>
<targetPath>../xxx/META-INF/vault/definition</targetPath>
</resource>
</resources>
<sourceDirectory>${basedir}/src/main/content/jcr_root</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
</plugin>
<!-- start frontend -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<inherited>false</inherited>
<configuration>
<nodeVersion>v16.17.0</nodeVersion>
<npmVersion>8.15.0</npmVersion>
<nodeDownloadRoot>xxxxx</nodeDownloadRoot>
<npmDownloadRoot>xxxxx</npmDownloadRoot>
<installDirectory>src/main/angular</installDirectory>
<workingDirectory>src/main/angular</workingDirectory>
</configuration>
<executions>
<execution>
......
</execution>
<execution>
<id>npm rebuild node-sass</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>rebuild node-sass</arguments>
</configuration>
</execution>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- end frontend -->
</plugins>
</build>
</project>
I want to run execution step with id npm run e2e based on profile. What I have in mind is 2 profiles default and e2eTests. With default, I can set activeByDefault as true and skip the e2e test. And when I pass e2eTests using -P , I should be able to run all execution including id=npm run e2e
I tried to move them into <profiles> but then the <sourceDirectory> was complaining. I found some links like this for it, but the problem comes on how to access plugins when I have <profiles> outside of <build>
I am not able to structure it properly.
Normally, it is not required to copy entire <build> configuration into profile definition - it should be enough to just define extra plugin execution, smth. like that:
<profiles>
<profile>
<id>e2eTests</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<executions>
<execution>
<id>npm run e2e</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
However, I would configure that in different way:
either bind execution of e2e tests to the lifecycle phase designed for that (integration-test) - in this case mvn package won't trigger e2e tests:
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run e2e</arguments>
</configuration>
</execution>
...
or take advantage of properties and profiles, for example:
<properties>
...
<skip.e2e>true</skip.e2e>
...
</properties>
<profiles>
<profile>
<id>e2eTests</id>
<properties>
<skip.e2e>false</skip.e2e>
</properties>
</profile>
</profiles>
...
<execution>
<id>npm run e2e</id>
<phase>integration-test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<skip>${skip.e2e}</skip>
<arguments>run e2e</arguments>
</configuration>
</execution>
...
I want to generate two artifacts (.ear) for one profile with two maven builds. I need that the name of the artifact doesn't contain the project version, I can't do it this way.
I'm trying multiple solutions but none has served to me.
I tried to include the tag <outputFileNameMapping>#{artifactId}#.#{extension}#</outputFileNameMapping>
or the tag
<fileNameMapping>no-version</fileNameMapping>
to the configuration tag.
I tried to change the maven-ear-plugin version too, with the same result.
This is my configuration:
<finalName>${area}${project.parent.artifactId}</finalName>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>ear-prepro</id>
<configuration>
<finalName>${project.parent.artifactId}finalll</finalName>
<outputFileNameMapping>#{artifactId}#.#{extension}#</outputFileNameMapping>
<earSourceDirectory>src/main/resources</earSourceDirectory>
<displayName>${area}${artifactId}</displayName>
<fileNameMapping>no-version</fileNameMapping>
<outputDirectory>${project.build.directory}</outputDirectory>
<modules>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>${project.parent.artifactId}-web</artifactId>
<bundleFileName>${project.parent.artifactId}-web.war</bundleFileName>
<contextRoot>/${project.parent.artifactId}</contextRoot>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
--------------------------
AND THE OTHER EAR CONFIGURATION
----------------------------
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>ear-protest</id>
<configuration>
<fileNameMapping>no-version</fileNameMapping>
<finalName>${area}${project.parent.artifactId}-PROTEST</finalName>
<earSourceDirectory>src/main/resources</earSourceDirectory>
<displayName>${area}${artifactId}-PROTEST</displayName>
<outputDirectory>${project.build.directory}/PROTEST</outputDirectory>
<modules>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>${project.parent.artifactId}-web</artifactId>
<bundleFileName>${project.parent.artifactId}-web.war</bundleFileName>
<contextRoot>/${project.parent.artifactId}</contextRoot>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
It seems that the tag concats the version number to the artifact, but I don't need it. I need the name of the artifact without the project version on the .war file.
Some ideas?
I'm using the copy-rename-maven-plugin during the package phase to first copy the jar that I just generated to another directory, then using launch4j-maven-plugin I'm generating exes that wrap the jar and then I need to rename one of the exes (to scr), so, I'm using copy-rename-maven-plugin again.
The problem is that all copy-rename-maven-plugin executions are run together, before launch4j-maven-plugin, so, the second execution fails.
How do define the order of executions? I'm happy creating more phases if that's what's necessary, but creating a Maven plugin seemed a bit of an overkill.
A simplified example of what's going with my pom.xml would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.projecx</groupId>
<artifactId>projecx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the just-built projecx jar to targte/win32/jars -->
<id>copy-jar-for-exe</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <!-- Make the exes -->
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the screensaver from the exe to the proper scr -->
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The order in which executions need to run is this:
copy-jar-for-exe
wrap-screensaver-as-exe
rename-screensaver-to-scr
Any other order doesn't work, but because, I think, copy-jar-for-exe and renamer-screensaver-to-scr are executions from the same plugin, Maven runs it like this:
copy-jar-for-exe
rename-screensaver-to-scr
wrap-screensaver-as-exe
so, it fails.
You could run the copy-jar-for-exe in the prepare-package phase. I beleive you could define both executions in the same plugin configuration but declare the plugin after the launch4j plugin.
Basic idea is, the plugins with executions in the same phase are executed in the order of appearance in the pom. If you bind a single execution to another (earlier) phase, it should be executed before.
I haven't tested this, but I think it should work
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>copy-jar-for-exe</id>
<phase>prepare-package</phase> <!-- run this execution before package phase -->
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
<execution>
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
I'm trying to build a Maven parent project script which incorporates a 3rd party project (with all its dependencies) and another couple of projects of mine.
I'd like to copy all dependencies (I mean ALL dependencies, including jars requested by other dependencies which in turn are requested by one of my child project) to a parent project directory, e.g. "lib", so that I can just run java with a wildcard classpath:
java -cp "lib/*" package.blah.blah.Main
I tried with various methods using the maven-dependency-plugin such as copy-dependencies, but all I can point Maven to is my own child projects, not their dependencies (I mean in the parent project pom).
This is the parent project pom I've been writing:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<properties>
<server.version>7.0.2</server.version>
<ext.version>1.0-alpha3-SNAPSHOT</ext.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>org.kontalk</groupId>
<artifactId>tigase-kontalk</artifactId>
<version>devel</version>
<packaging>pom</packaging>
<modules>
<module>../tigase-server/modules/master</module>
<module>../tigase-extension</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-artifact</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.kontalk</groupId>
<artifactId>tigase-server</artifactId>
<version>${server.version}</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>org.kontalk</groupId>
<artifactId>tigase-extension</artifactId>
<version>${ext.version}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>bin</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.kontalk</groupId>
<artifactId>tigase-server</artifactId>
<version>${server.version}</version>
</dependency>
<dependency>
<groupId>org.kontalk</groupId>
<artifactId>tigase-extension</artifactId>
<version>${ext.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
It will copy just the two direct child project jars in the bin directory, but nothing else.
I'm thinking of doing a manual copy (as in a Maven copy) to brutally copy all jars from my child projects' target/dependency directories, but it just seems... brutal.
If it can't be done with the existing Maven software, I can even be content with using maven exec directly (which, I hope, should set up classpath automatically, right?)
EDIT: I'd like to modify the child projects poms as little as possible, especially the 3rd party one.
If you want to build a simply runnable jar file with maven then you can use this config:
<profiles>
<profile>
<id>dist</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>yourJarName</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>your.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
then you can build it using mvn clean package -Pdist
edit: then you can run it with java -jar target/yourJarName.jar
I ended up using copy-dependencies. This is the main project pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/jars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>jars</outputDirectory>
<resources>
<resource>
<directory>../tigase-extension/target/lib</directory>
<excludes>
<exclude>junit*</exclude>
</excludes>
</resource>
<resource>
<directory>../tigase-server/target/lib</directory>
<excludes>
<exclude>junit*</exclude>
</excludes>
</resource>
<resource>
<directory>../tigase-extension/target</directory>
<includes>
<include>tigase-extension-*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
In the submodules I've added to the same plugin this code:
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
Basically, the submodules copy their dependency jars into target/lib, then the main project copies those jars into its own jars folder.
It has some project-specific filenames and other hard-coded things, but still I think this is the best option if I want to use only Maven-provided tools. Probably a new Maven plugin would have been optimal, but I don't really have the time.
I'm a Maven newbie and my project is finally compiling and running correctly.
On each run my project writes reports on a dynamic location created at runtime (username_timestamp) and sets a System.property called REPORTS_LOCATION with this location. After execution I would like to copy some static resources (style, images, js, etc) to this dynamic folder using a maven goal.
What I can't figure out is how to let Maven know about this dynamic location or access this System.property
I'm about ready to just let my project copy these resources to the directory but I figure I'll give it another try in case there is an easy/Maven way of doing this.
I've gotten as far as copying the resources to a hard coded location. Here is a snippet of the POM. I'm using Jbehave's Maven goals and they do execute in order
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<executions>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/Stories.java</include>
</includes>
<excludes />
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
<!-- Copy the resources AFTER the execution is done -->
<execution>
<id>unpack-view-resources</id>
<phase>integration-test</phase>
<configuration>
<viewDirectory>${basedir}/src/main/java/project/reports/{NEED TO FEED DIRECTORY HERE}</viewDirectory>
</configuration>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
It sounds like you have a piece of Java code calculating {username_timestamp}, and you then want that code to be able to communicate the calculated {username_timestamp} back to Maven for use in later steps of its lifecycle. I'm not sure that this is possible. Instead, how about inverting the process, so that Maven produces the timestamp, and you consume it from your code? You can achieve this using a combination of build-helper-maven-plugin, Maven resource filtering, and Java code to load a properties file.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>junk</groupId>
<artifactId>junk</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!--
Use build-helper-maven-plugin to generate a timestamp during the
initialize phase and store it as a property named "timestamp".
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>timestamp-property</id>
<phase>initialize</phase>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<locale>en_US</locale>
<name>timestamp</name>
<pattern>yyyyMMDDHHmmssSSS</pattern>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${pom.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!--
Turn on resource filtering so that references to ${timestamp} in a
properties file get replaced with the value of the timestamp property.
-->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
src/main/resources/junk.properties
timestamp=${timestamp}
src/main/java/Main.java
import java.util.Properties;
public final class Main {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.load(Main.class.getResourceAsStream("/junk.properties"));
System.out.println(props.getProperty("timestamp"));
}
}
Thanks a lot cnauroth, this worked like a charm. Here is my working updated POM in case it helps someone else
<resources>
<resource>
<directory>${basedir}/src/main/java/resources</directory>
<excludes><exclude>**/locale/**</exclude></excludes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- Use build-helper-maven-plugin to generate a timestamp during the initialize
phase and store it as a property named "mavenTimestamp". -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>timestamp-property</id>
<phase>initialize</phase>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<locale>en_US</locale>
<name>mavenTimestamp</name>
<pattern>yyyyMMDDHHmmssSSS</pattern>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<executions>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/Stories.java</include>
</includes>
<excludes />
<ignoreFailureInStories>true</ignoreFailureInStories>
<verboseFailures>true</verboseFailures>
<threads>5</threads>
<metaFilters>
<metaFilter>${meta.filter}</metaFilter>
</metaFilters>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
<!-- THIS WORKS :) Copy the resources AFTER the execution is done -->
<execution>
<id>unpack-view-resources</id>
<phase>integration-test</phase>
<configuration>
<viewDirectory>${basedir}/src/main/java/project/reports/${mavenTimestamp}</viewDirectory>
</configuration>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
If you set the folder as an environment variable during the runtime, you can do the following:
just use
<properties>
<REPORTS_LOCATION><${env.REPORTS_LOCATION}></REPORTS_LOCATION>
</properties>
then you can reference to theproperty via ${REPORTS_LOCATION} in you pom