Move a config file into etc folder(of Karaf) when a (Maven)bundle is deployed - maven

I want to move a cfg file into the etc folder of karaf whenever a bundle is deployed.
the cfg file is in under src/main/resource .i tried the following in the pom but its not working.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Using env.test.properties</echo>
<copy file="src/main/resources/test.cfg" tofile="${env.KARAF_HOME}/etc/test.cfg"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
How can i do it ?

One of the solution could be:
- put your test.cfg file in a more specific folder. (eg: src/main/resources/cfg)
- use the maven resources plugin
This is a working example based on the maven phase generate-resources (replace that phase by deploy in your case):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-to-karaf</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/cfg</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>D:\apache-karaf-3.0.1\etc\</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

Related

Preparing Tests for upload into Appcenter does not include src classfiles

I hope someone can help. When I am trying to prepare my tests to upload into appcenter for mobile testing, the command they tell me to use to prepare the upload does not include the src class files for my tests. It only adds the test class files that are specified in the "prepare-for-upload" section in the pom file.
when I upload and run the tests, it complains that it can not find the class files in classes.
I think that is because it isn't in the upload folder.
All the things I have tried still only leaves me with the following folders and files
This is all new to me so I have read so much without success.
I have tried to add the resources to the pom.xml and it still does not package them correctly.
I added this section to the pom file in the same tag as the Appcenter stuff.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
I tried the following as well to see if I can copy the resources over.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This is my section that is meant for appcenter:
<profiles>
<profile>
<id>prepare-for-upload</id>
<build>
<plugins>
<!-- Owen Added-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
/Users/owensieber/Projects/mobileautomation/target/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/dependency-jars/</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
<addParentPoms>true</addParentPoms>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-pom</id>
<phase>package</phase>
<goals>
<goal>effective-pom</goal>
</goals>
<configuration>
<output>${project.build.directory}/upload/pom.xml</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-testclasses</id>
<phase>package</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/test-classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.testOutputDirectory}
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

reading properties file into maven pom.xml not working

I need to use values from properties file in maven pom.xml, so i used properties-maven-plugin to read my properties file as follows
pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/src/main/resources/qura.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
qura.properties file contains something like this..
config.file.path = resources/python/config/test.py
I need use this config.file.path variable in resource element of pom.xml
pom.xml
<resources>
<resource>
<directory>${basedir}/multilang/</directory>
<includes>
<include>${config.file.path}</include>
</includes>
</resource>
<resources>
But the value for ${config.file.path} is not taking up from qura.properties file and I couldn't find test.py file in jar.
what I'm doing wrong in this code?
Thanks in Advance
try using version 1.0.0 and removing spaces around equal sign in properties file.
eg:
key=value
IMO, it does not matter whether you put the spaces or not around equal sign in properties file. You may need to check if the ${config.file.path} exists in the directory specified by ${basedir}/multilang
The below snippet works for me.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main</directory>
<includes>
<include>${config.file.path}</include>
</includes>
</resource>
</resources>
</configuration>
<inherited></inherited>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/src/main/resources/qura.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Creating directory structure for application with maven

How can I tell maven to create a particular directory structure and to put jar files in certain places?
For example I want to put put some jars in a directory called plugins which are loaded at runtime.
Is that possible? Or am I missing the principles behind maven?
It looks like your jars is your project dependency, so to copy all dependencies at plugins folder use next:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-alldeps</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
When your project use jars like resources, use maven resource section or next plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-config-files</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/plugins/</outputDirectory>
<resources>
<resource>
<filtering>false</filtering>
<directory>${project.basedir}/jars/</directory>
<includes>
<include>file1.jar</include>
<include>file5.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

Attaching only a contents of the folder to the jar

I am using maven-jar-plugin to generate a sources jar.
I have the following folder structure:
folder/foo/baz/A.java
folder/bar/baz/B.java
I want the sources jar to contain the following:
baz/A.java
baz/B.java
I am using the following configuration:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>folder</classesDirectory>
<includes>
<include>foo/**</include>
<include>bar/**</include>
</includes>
<finalName>sources</finalName>
</configuration>
</execution>
</executions>
</plugin>
But this creates the jar like this:
folder/foo/baz/A.java
folder/bar/baz/B.java
How can i modify the code to get my desired structure in the jar?
I could not solve this with the maven-jar-plugin, i had to use maven-resources-plugin, too:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/sources/</outputDirectory>
<resources>
<resource>
<directory>folder/foo/</directory>
</resource>
<resource>
<directory>folder/bar/</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.directory}/sources</classesDirectory>
<includes>
<include>**/*</include>
</includes>
<finalName>sources</finalName>
</configuration>
</execution>
</executions>
</plugin>

Copying files from my project in Maven

Is it possible to copy folders from my project to a certain location during some Maven phase? Does anybody know how?
The Maven way of doing this would be using the copy-resources goal in maven-resources-plugin
From http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
Take a look at the maven-antrun plugin. You can copy a file in any maven phase like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<configuration>
<tasks>
<copy file="myFileSource" tofile="MyFileDest"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
A solution similar to #mort's one with maven-antrun-plugin 1.8:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<configuration>
<target>
<copy file="sourceFile" tofile="targetFile"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Note that <tasks> node is deprecated in favor of <target> node as of maven-antrun-plugin 1.5.

Resources