Export OSGi bundles to a specific folder using maven - maven

Can anyone plz guide me how can I copy the generated OSGi bundle to a different location on the disk?
I am using maven for building the OSGi bundle.
Complete Solution: Update on 9th Jan, 2014:
I got a better approach and updated the pom.xml with following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-installed</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>some-other-place</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This was able to copy once the bundle generation was done an I could give the destination folder too.

When do you want to copy your bundle?
Assuming you have a project generating the bundle, then it should be available in your target folder, and will also be installed (running mvn install) in your local repository (~/.m2/repository/...).
You could just use a cp command to copy it wherever you want.
Deploying it to a test folder as part of the build is not necessarily a great idea: you're making your build dependent on machine specific settings or magic injected properties. That said, if you wanted to do that anyway, I'll use the following approach:
have a separate maven project which depends on the bundle and just deploys it wherever you like
define a property specifying the target directory (you can pass it on the command line, define it in your settings.xml or provide a default value for in your pom.xml)
use the maven-dependency-plugin:copy-dependency goal in your deployment project to copy your bundle

Guess this question is not really related to OSGi, more to maven... maybe you could have a look at the maven resources plugin, specifically http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html which helps you copying arbitrary resources.

Related

Let MVN store libraries in MyProject/lib/?

I would like maven to store the dependent jars in the project specific lib folder instead of in the default MyUser/.m2/repository/. Not everybody has internet access when he gets the project, and copying the global local repository seems like a less-than-ideal solution.
How do I persuade maven to store and use these dependencies in a local, relative, project specific folder?
Seems my question is a rephrased version of this Stackoverflow question
I did something like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${mvn-dependency-plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/${local-lib-dir}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<build>
The only downside is, that eclipses maven still refer to the jars in the local repository.
I'm sorry to say that, but if you really like to have a lib folder which contains the dependencies you are working with you are back in Ant times and start also checking in the lib folder into your version control which is really bad.
If you argument that an internet access does not exist you should start using a repository manager like Artifactory, Nexus or Archiva which is installed within the local network and only the repository manager needs the internet connection. Everyone else just uses a version control tool to checkout the sources and can start working with the project.
You can manage your external dependencies like this:
<dependency>
<groupId>mydependencygroup</groupId>
<artifactId>my.artifact</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\myartifact.jar</systemPath>
</dependency>
The lib folder is inside your src folder.
Hope it hepls.

Xcode Maven Plugin : adding extra headers

The Xcode Maven Plugin from http://sap-production.github.io/xcode-maven-plugin/site is a nice maven plugin for people who like maven and wan't to avoid some pain with xcode dependencies, framework creation and such.
It creates and installs lib and headers in the repository.
The headers are bundled in a .tar file during the process.
For some reason, I need to edit the tar file and add a few files in it before installing.
But as I'm quite the noob regarding maven, I need some help !
How can I modify on a byproduct of Maven before it is installed ? I suppose I can write some script that add some files to the .taf, but how can I be sure it's executed prior the installation ?
#Redwarp - It's been a while since this question was asked, but I'll offer up an answer.
You can configure a Maven plug-in's goal to be executed during a particular phase in the Maven build lifecycle.
Pick a phase that's executed before the install phase. Package may be the best phase for you to edit your tar file and add your required files.
The following is just a generalized example (the focus should be on phase and goal):
<project>
...
<build>
<plugins>
<plugin>
<groupId>com.sap.prd.mobile.ios.mios</groupId>
<artifactId>xcode-maven-plugin</artifactId>
<version>1.12.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>do-something</id>
<phase>package</phase>
<configuration>
...
</configuration>
<goals>
<goal>plugin-goal</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Find the plug-ins that suit your needs and bind their goals to the appropriate Maven lifecycle phases...which there's a good chance that you have already figured out by this point.

how to wildcard attach multiple files to an artifact in maven?

In my maven project, the ant plugin generate multiple war files and I want to attach them all in the same artifact. I tried the build-helper-maven-plugin like this
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/*.war</file>
<type>war</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
I don't want to specify each war file separately because the ant plugin is dynamic. Is there a way to do that?
Thanks,
Providing wildcards for single artifacts does not seem to be supported by the Build Helper plugin (btw, if it did, it would likely use the includes/excludes configuration used by Resources Plugin).
I've learned that, if you choose to use Maven, it's best to just adjust your build to "the Maven way."
In this case, you should revise your build to not use the ant war plugin, and instead have a multi-module build with a separate module (sub-project) for each war file.
Alternatively, in the past I have accomplished something like you are doing via the Maven Assembly plugin, where the wars are all shipped together in a single tar/gz file. The archive (which contains each of the wars) is then attached to the build.
Note that you should prefer to have your "web apps" module have a artifact type of "pom." The assembly plugin will attach the archives to the final build.
For more information, I've found that Sonatype's online books are a great resource:
http://www.sonatype.com/Support/Books

Maven assembly: copy from specific sub-folder of dependency

I'm using Maven assembly plugin to build a WAR of our product (previously done by Ant). As there're many leftovers of Apache Ant, there's one specific requirement that would make build process easier: copy specific sub-folder of dependency (e.g., jar or war resource) to a specific target sub-folder.
So far I learned that Assembly descriptors allow to specify <outputDirectory>, but is there's any chance to specify a <sourceDirectory>? E.g., I want to apply this rule for one single WAR or JAR type dependency.
Consider this example of assembly descriptor fragment (not 100% accurate):
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>my-specific-dependency:war</include>
</includes>
<outputDirectory>WEB-INF/myresources</outputDirectory>
</dependencySet>
I want to say that I want to copy some folder from my-specific-dependency:war to WEB-INF/myresources.
EDIT NB: I'm aware that this is not a very correct requirement as we shouldn't know what's inside an artifact, the correct way would be declaring to extract the whole artifact to the target directory (neat declarative approach).
You should be able to use the Maven Dependency plugin to do this, with the unpack goal:
http://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-database-scripts</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0</version>
<type>war</type>
<overWrite>true</overWrite>
<includes>...</includes>
<outputDirectory>…</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
First i recomment that you check the maven-war-plugin to do that job instead with maven-assembly-plugin. Furthermore check the documentation about the dependencySet which contains such options for unpacking etc. Change your packaging of the module to war and make it fit to the maven conventions and don't use Maven as ant...which currently looks like it.
It turned out that assembly descriptor (since ver. 2.2-beta-1) provides unpackOptions instructions, including <dependencySet>. Exactly what I needed.

maven-install-plugin: Can i define a custom packaging type but get the artifact installed as jar in the repo?

I am trying to come out with a plugin to detect and process Java EE application clients.
I created a new packaging type called 'car' through META-INF/plexus/components.xml (http://maven-car-plugin.googlecode.com/svn/trunk/maven-car-plugin/src/main/resources/META-INF/plexus/components.xml) and a corresponding mojo for Java EE app clients. I have pretty much followed the same steps as the maven-ejb-plugin.
The behaviour i want is the same as the maven-ejb-plugin: Defines an ejb packaging type but the artifact gets installed in the repo as a .jar and gets bundled in the ear as .jar too.
I believe must be configurable some how because ejb packaging type gets installed as .jar but war packaging type produces a .war.
The problem in my case is that a .car file gets installed in the repo and a .car file gets bundled in the ear.
Does anyone know how to make sure it gets installed in the repo as a .jar file?
I ran into the same issue you have, except, I'm building a .war file and wanted a .jar file installed into my local repo. What I did was use the maven-jar-plugin to create a jar file in addition to a war file, it's generated in my /target directory. I also used the maven-install-plugin to install the outputted jar to my local repo.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-jar</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Perhaps you could try using the packaging parameter in maven install plugin to see if that helps in your case?
I would assume you would have to specify
<packaging>jar</packaging>
as well in the component descriptor. Otherwise it looks correct to me..

Resources