blob: ae67807c0c8330a60fac1e1cae5d4ca6684b20f0 [file] [log] [blame]
Karl Paulsf87ac142007-07-06 22:36:17 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Stuart McCulloch3f38f732008-05-03 08:13:09 +00002<html><head><title>Apache Felix - Apache Felix Maven Bundle Plugin (BND)</title>
Karl Paulsf87ac142007-07-06 22:36:17 +00003
4
5
6
Stuart McCulloch3f38f732008-05-03 08:13:09 +00007 <link rel="stylesheet" href="apache-felix-maven-bundle-plugin-bnd_files/site.css" type="text/css" media="all">
Karl Paulsf87ac142007-07-06 22:36:17 +00008 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head><body>
Stuart McCulloch3f38f732008-05-03 08:13:09 +00009 <div class="title"><div class="logo"><a href="http://felix.apache.org/site/index.html"><img alt="Apache Felix" src="apache-felix-maven-bundle-plugin-bnd_files/logo.png" border="0"></a></div><div class="header"><a href="http://www.apache.org/"><img alt="Apache" src="apache-felix-maven-bundle-plugin-bnd_files/apache.png" border="0"></a></div></div>
Karl Paulsf87ac142007-07-06 22:36:17 +000010 <div class="menu">
Stuart McCulloch93de6492007-12-16 15:59:05 +000011<ul>
Stuart McCulloch93de6492007-12-16 15:59:05 +000012 <li><a href="http://felix.apache.org/site/news.html" title="news">news</a></li>
Stuart McCulloch93de6492007-12-16 15:59:05 +000013 <li><a href="http://felix.apache.org/site/license.html" title="license">license</a></li>
Stuart McCulloch3f38f732008-05-03 08:13:09 +000014 <li><span class="nobr"><a href="http://felix.apache.org/site/downloads.cgi" title="Visit page outside Confluence" rel="nofollow">downloads<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li>
Stuart McCulloch93de6492007-12-16 15:59:05 +000015 <li><a href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</a></li>
16 <li><a href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</a></li>
Stuart McCulloch3f38f732008-05-03 08:13:09 +000017 <li><a href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</a></li>
18 <li><span class="nobr"><a href="http://www.apache.org/" title="Visit page outside Confluence" rel="nofollow">asf<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li>
19 <li><span class="nobr"><a href="http://www.apache.org/foundation/sponsorship.html" title="Visit page outside Confluence" rel="nofollow">sponsorship<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li>
20 <li><span class="nobr"><a href="http://www.apache.org/foundation/thanks.html" title="Visit page outside Confluence" rel="nofollow">sponsors<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>
21<!-- ApacheCon Ad -->
22<iframe src="apache-felix-maven-bundle-plugin-bnd_files/button.html" style="border-width: 0pt; float: left; display: none;" frameborder="0" height="135" scrolling="no" width="135"></iframe>
23<p style="height: 100px;">
24<!-- ApacheCon Ad -->
25</p></li></ul> </div>
Karl Paulsf87ac142007-07-06 22:36:17 +000026 <div class="main">
Stuart McCulloch3f38f732008-05-03 08:13:09 +000027<h1><a name="ApacheFelixMavenBundlePlugin(BND)-BundlePluginforMaven"></a>Bundle Plugin for Maven</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000028
Stuart McCulloch3f38f732008-05-03 08:13:09 +000029<p>This plugin for Maven 2 is based on the <span class="nobr"><a href="http://www.aqute.biz/Code/Bnd" title="Visit page outside Confluence" rel="nofollow">BND<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>
Karl Paulsf87ac142007-07-06 22:36:17 +000030tool from Peter Kriens. The way BND works is by treating your project
31as a big collection of classes (e.g., project code, dependencies, and
32the class path). The way you create a bundle with BND is to tell it the
33content of the bundle's JAR file as a subset of the available classes.
34This plugin wraps BND to make it work specifically with the Maven 2
35project structure and to provide it with reasonable default behavior
36for Maven 2 projects.</p>
37
Stuart McCulloch0340ae42008-02-22 11:27:18 +000038<p>Since the 1.4.0 release, this plugin also aims to automate OBR (OSGi
39Bundle Repository) management. It helps manage a local OBR for your
40local Maven repository, and also supports remote OBRs for bundle
41distribution. The plug-in automatically computes bundle capabilities
42and requirements, using a combination of Bindex and Maven metadata.</p>
43
Stuart McCulloch3f38f732008-05-03 08:13:09 +000044<p><a name="ApacheFelixMavenBundlePlugin(BND)-simpleexample"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +000045
Stuart McCulloch3f38f732008-05-03 08:13:09 +000046<h1><a name="ApacheFelixMavenBundlePlugin(BND)-SimpleExample"></a>Simple Example</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000047
48<p>Rather than going straight to a detailed list of plugin features, we
49will first look at a simple example of how to use the plugin to give an
Stuart McCulloch3f38f732008-05-03 08:13:09 +000050immediate flavor. A detailed "<a href="#ApacheFelixMavenBundlePlugin%2528BND%2529-howto" title="how-to on Apache Felix Maven Bundle Plugin (BND)">how to</a>" will follow.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +000051
52<p>Assume that we have a simple bundle project that has a pubic API package an several implementation packages, such as:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +000053
Karl Paulsf87ac142007-07-06 22:36:17 +000054<div class="preformatted"><div class="preformattedContent">
55<pre>org.foo.myproject.api
56org.foo.myproject.impl1
57org.foo.myproject.impl2
58...
59</pre>
60</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000061
Karl Paulsf87ac142007-07-06 22:36:17 +000062<p>If we also assume that we have a bundle activator in one of the implementation packages, then the <tt>&lt;plugins&gt;</tt> section of the POM file for this bundle project would look like this:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +000063
Karl Paulsf87ac142007-07-06 22:36:17 +000064<div class="preformatted"><div class="preformattedContent">
65<pre>...
66&lt;plugins&gt;
67 &lt;plugin&gt;
68 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
69 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
70 &lt;extensions&gt;true&lt;/extensions&gt;
71 &lt;configuration&gt;
72 &lt;instructions&gt;
73 &lt;Export-Package&gt;org.foo.myproject.api&lt;/Export-Package&gt;
74 &lt;Private-Package&gt;org.foo.myproject.*&lt;/Private-Package&gt;
75 &lt;Bundle-Activator&gt;org.foo.myproject.impl1.Activator&lt;/Bundle-Activator&gt;
76 &lt;/instructions&gt;
77 &lt;/configuration&gt;
78 &lt;/plugin&gt;
79&lt;/plugins&gt;
80...
81</pre>
82</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000083
Karl Paulsf87ac142007-07-06 22:36:17 +000084<p>The <tt>&lt;Export-Package&gt;</tt> and <tt>&lt;Private-Package&gt;</tt> instructions tell the plugin about the contents of the resulting bundle JAR file. The <tt>&lt;Export-Package&gt;</tt> instruction tells the plugin which of the available packages to copy into the bundle <b>and</b> export, while the <tt>&lt;Private-Package&gt;</tt> instruction indicates which of the available packages to copy into the bundle <b>but not</b>
85export. If the two sets overlap, as they do in the case, then the
86export takes precedence. Since we did not specify any values for any
87other bundle manifest headers, they will assume default values which
Stuart McCulloch3f38f732008-05-03 08:13:09 +000088are described <a href="#ApacheFelixMavenBundlePlugin%2528BND%2529-defaultbehavior" title="default-behavior on Apache Felix Maven Bundle Plugin (BND)">below</a>. One specific behavior to highlight is that the plugin generates the <tt>Import-Package</tt>
Karl Paulsf87ac142007-07-06 22:36:17 +000089bundle manifest header based on the contents of the bundle, which means
90that you generally do not ever need to explicitly specify it yourself.
91That's it.</p>
92
Stuart McCulloch3f38f732008-05-03 08:13:09 +000093<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Features"></a>Features</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000094
95<p>The BND library underlying the plugin defines instructions to direct
96its behavior. For this Maven plugin, these instructions are issued in
Stuart McCulloch3f38f732008-05-03 08:13:09 +000097the plugin configuration section of the POM file, as was illustrated <a href="#ApacheFelixMavenBundlePlugin%2528BND%2529-simpleexample" title="simple-example on Apache Felix Maven Bundle Plugin (BND)">above</a>. BND recognizes three types of instructions:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +000098
Karl Paulsf87ac142007-07-06 22:36:17 +000099<ol>
100 <li><em>Manifest headers</em> - Any instruction that starts with
101a capital letter will appear in the resulting bundle's manifest file;
102the value for the header will either be copied, augmented, or generated
103by BND depending on the instruction.</li>
104 <li><em>Variables</em> - Any instruction starting with a lowercase letter is assumed to be a variable in the form of a name-value pair, such as <tt>version=3.0</tt>, that can be used for property substitution, but is not copied to the manifest.</li>
105 <li><em>Directives</em>
106- Any instruction starting with a '-' character is considered to be a
107directive that informs BND to perform some special processing and is
108not copied to the manifest.</li>
109</ol>
110
111
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000112<p>The remainder of this section covers the most important aspects of BND's instructions; for complete details refer to the <span class="nobr"><a href="http://www.aqute.biz/Code/Bnd" title="Visit page outside Confluence" rel="nofollow">BND documentation<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000113
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000114<p><a name="ApacheFelixMavenBundlePlugin(BND)-instructions"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000115
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000116<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Instructions"></a>Instructions</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000117
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000118<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ExportPackage&gt;}}"></a><tt>&lt;Export-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000119
120<p>The <tt>&lt;Export-Package&gt;</tt> instruction is a list of
121packages for the bundle to export. These packages are copied into the
122resulting bundle JAR file from the available classes (i.e., project
123classes, dependencies, and class path); thus, it is possible to include
124classes into your bundle that are not associated with source files in
125your project. <tt>&lt;Export-Package&gt;</tt> can be specified with
126package patterns using the '*' wildcard. Also, it is possible to
127exclude packages using negation by starting the package pattern with
128'!'. Thus, non-negated patterns indicate which of the available
129packages to include in the bundle, whereas negated patterns indicate
130which should not be included in the bundle.</p>
131
132<p>The list of package patterns is ordered and earlier patterns are applied before later patterns. For example, if you specify "<tt>org.foo.*,!org.foo.impl</tt>" the second pattern has no effect since all <tt>org.foo</tt> packages have already been selected by the first pattern. Instead, you should specify "<tt>!org.foo.impl,org.foo.*</tt>", which will export all <tt>org.foo</tt> packages except <tt>org.foo.impl</tt>.</p>
133
134<p>Following standard OSGi R4 syntax, package patterns can include both
135directives and attributes, which will be copied appropriately into the
136generated Export-Package manifest header. Besides explicitly listing
137package version attributes, BND will also determine package versions by
138examining the source JAR file or from <tt>packageinfo</tt> files in the package directory.</p>
139
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000140<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;PrivatePackage&gt;}}"></a><tt>&lt;Private-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000141
142<p>The <tt>&lt;Private-Package&gt;</tt> instruction is similar in every way to the <tt>&lt;Export-Package&gt;</tt> instruction, except for the fact that these packages will <b>not</b>
143be exported by the bundle. If a package is selected by both the export
144and private package headers, then the export takes precedence.</p>
145
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000146<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;IncludeResource&gt;}}"></a><tt>&lt;Include-Resource&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000147
148<p>The <tt>&lt;Include-Resource&gt;</tt> instruction is a list of
149arbitrary resources that should be copied into the bundle JAR file. The
150specified resources are declared as clauses that can have the following
151forms:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000152
Karl Paulsf87ac142007-07-06 22:36:17 +0000153<div class="preformatted"><div class="preformattedContent">
154<pre>clause ::= assignment | inline | simple
155assignment ::= PATH '=' PATH
156simple ::= PATH
157inline ::= '@' PATH
158</pre>
159</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000160
Karl Paulsf87ac142007-07-06 22:36:17 +0000161<p>For the <tt>&lt;Include-Resource&gt;</tt> instruction, actual file paths are relative to the <tt>pom.xml</tt>, while file copy destinations are relative to the root of the resulting bundle JAR file. In the case of <tt>assignment</tt> or <tt>simple</tt> forms, the <tt>PATH</tt> parameter can point to a file or directory. The <tt>simple</tt>
162form will place the resource in the bundle JAR with only the file name,
163i.e., without any path component. For example, including <tt>src/main/resources/a/b.c</tt> will result in a resource <tt>b.c</tt> in the root of the bundle JAR. If the <tt>PATH</tt>
164points to a directory, the entire directory hierarchy is copied into
165the resulting bundle JAR file relative to the specified directory. If a
166specific resource must be placed into a subdirectory of the bundle jar,
167then use the <tt>assignment</tt> form, where the first path is the the
168destination path (including file name if the resource is a file) and
169the second path is the resource to copy. The <tt>inline</tt> form requires a ZIP or JAR file, which will be completely expanded in the bundle JAR.</p>
170
171<p>If a resource clause is specified inside of "{ ... }" brackets, then
172variable substitution will be performed on the resource, where
173variables in the resources are denoted with "${ ... }" syntax.</p>
174
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000175<p>By default the bundle plugin converts the project's Maven resource directories into a single <tt>&lt;Include-Resource&gt;</tt> instruction. If you specify your own <tt>&lt;Include-Resource&gt;</tt> instruction, this will replace the generated one. To include the generated list of Maven resources in your own <tt>&lt;Include-Resource&gt;</tt> instruction just add {<tt>maven-resources</tt>} to the list and it will be expanded automatically.</p>
176
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000177<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ImportPackage&gt;}}"></a><tt>&lt;Import-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000178
179<p>The <tt>&lt;Import-Package&gt;</tt> instruction is a list of
180packages that are required by the bundle's contained packages. The
181default for this header is "*", resulting in importing all referred
182packages. This header rarely has to be explicitly specified. However,
183in certain cases when there is an unwanted import, such an import can
184be removed by using a negation package pattern. The package patterns
185work in the same way as for <tt>&lt;Export-Package&gt;</tt>, which means they are ordered. For example, if you wanted to import all packages except <tt>org.foo.impl</tt> you would specify "<tt>!org.foo.impl,*</tt>"</p>
186
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000187<p><a name="ApacheFelixMavenBundlePlugin(BND)-defaultbehavior"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000188
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000189<h2><a name="ApacheFelixMavenBundlePlugin(BND)-DefaultBehavior"></a>Default Behavior</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000190
191<p>To use this plugin, very little information is required by BND. As
192part of the Maven integration, the plugin tries to set reasonable
193defaults for various instructions. For example:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000194
Karl Paulsf87ac142007-07-06 22:36:17 +0000195<ul>
196 <li><tt>&lt;Bundle-SymbolicName&gt;</tt> is assumed to be "<tt>${groupId}.${artifactId</tt>}".</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000197 <li><tt>&lt;Export-Package&gt;</tt> is assumed to be "<tt>&lt;Bundle-SymbolicName&gt;.*</tt>", unless <tt>&lt;Private-Package&gt;</tt> is specified, then <tt>&lt;Export-Package&gt;</tt> is assumed to be empty.</li>
Karl Paulsf87ac142007-07-06 22:36:17 +0000198 <li><tt>&lt;Private-Package&gt;</tt> is assumed to be empty by default.</li>
199 <li><tt>&lt;Import-Package&gt;</tt> is assumed to be "<tt>*</tt>", which imports everything referred to by the bundle content, but not contained in the bundle.</li>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000200 <li><tt>&lt;Include-Resource&gt;</tt> is generated from the project's Maven resources, typically "<tt>src/main/resources/</tt>",
Karl Paulsf87ac142007-07-06 22:36:17 +0000201which will copy the specified project directory hierarchy into the
202resulting bundle JAR file, mirroring standard Maven behavior.</li>
203 <li><tt>&lt;Bundle-Version&gt;</tt> is assumed to be "<tt>${pom.version</tt>}" with '-' character separator of the qualifier replaced with a '.' character.</li>
204 <li><tt>&lt;Bundle-Name&gt;</tt> is assumed to be "<tt>${pom.name</tt>}".</li>
205 <li><tt>&lt;Bundle-Description&gt;</tt> is assumed to be "<tt>${pom.description</tt>}".</li>
206 <li><tt>&lt;Bundle-License&gt;</tt> is assumed to be "<tt>${pom.licenses</tt>}".</li>
207 <li><tt>&lt;Bundle-Vendor&gt;</tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li>
208 <li><tt>&lt;Bundle-DocURL&gt;</tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li>
209</ul>
210
211
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000212<p>Since the plugin creates bundles for OSGi R4, it hard-codes <tt>Bundle-ManifestVersion</tt>
Karl Paulsf87ac142007-07-06 22:36:17 +0000213to be '2'. Additionally, it generates imports for every export to
214ensure package substitutability, which is very important when working
215with collaborating services. It is possible to override any of these
216values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p>
217
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000218<p><a name="ApacheFelixMavenBundlePlugin(BND)-howto"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000219
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000220<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Detailed&quot;HowTo&quot;"></a>Detailed "How To"</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +0000221
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000222<h2><a name="ApacheFelixMavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000223
224<p>The first step in the process of using the plugin is downloading and
225installing the latest version of the Maven2 runtime. The latest Maven2
226release and instuctions for getting started with Maven2 can be found at
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000227the <span class="nobr"><a href="http://maven.apache.org/index.html" title="Visit page outside Confluence" rel="nofollow">Maven website<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000228
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000229<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000230
231<p>To use the maven-bundle-plugin, you first need to add the plugin and
232some appropriate plugin configuration to your bundle project's POM.
233Below is an example of a simple OSGi bundle POM for Maven2:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000234
Karl Paulsf87ac142007-07-06 22:36:17 +0000235<div class="preformatted"><div class="preformattedContent">
236<pre>&lt;project&gt;
237 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
238 &lt;groupId&gt;my-osgi-bundles&lt;/groupId&gt;
239 &lt;artifactId&gt;examplebundle&lt;/artifactId&gt;
240 &lt;packaging&gt;bundle&lt;/packaging&gt; &lt;!-- (1) --&gt;
241 &lt;version&gt;1.0&lt;/version&gt;
242 &lt;name&gt;Example Bundle&lt;/name&gt;
243 &lt;dependencies&gt;
244 &lt;dependency&gt;
245 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
246 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000247 &lt;version&gt;1.0.0&lt;/version&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000248 &lt;/dependency&gt;
249 &lt;/dependencies&gt;
250 &lt;build&gt;
251 &lt;plugins&gt;
252 &lt;plugin&gt; &lt;!-- (2) START --&gt;
253 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
254 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
255 &lt;extensions&gt;true&lt;/extensions&gt;
256 &lt;configuration&gt;
257 &lt;instructions&gt;
258 &lt;Export-Package&gt;com.my.company.api&lt;/Export-Package&gt;
259 &lt;Private-Package&gt;com.my.company.*&lt;/Private-Package&gt;
260 &lt;Bundle-Activator&gt;com.my.company.Activator&lt;/Bundle-Activator&gt;
261 &lt;/instructions&gt;
262 &lt;/configuration&gt;
263 &lt;/plugin&gt; &lt;!-- (2) END --&gt;
264 &lt;/plugins&gt;
265 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000266&lt;/project&gt;
267</pre>
268</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000269
270<p>There are two main things to note: (1) the <tt>&lt;packaging&gt;</tt>
271specifier must be "bundle" and (2) the plugin and configuration must be
Karl Paulsf87ac142007-07-06 22:36:17 +0000272specified (the configuration section is where you will issue
Stuart McCulloch93de6492007-12-16 15:59:05 +0000273instructions to the plugin).</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000274
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000275<h2><a name="ApacheFelixMavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000276
277<p>Consider this more real-world example using Felix' Log Service
278implementation. The Log Service project is comprised of a single
279package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on
280the core OSGi interfaces as well as a dependency on the compendium OSGi
281interfaces for the specific log service interfaces. The following is
282its POM file:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000283
Karl Paulsf87ac142007-07-06 22:36:17 +0000284<div class="preformatted"><div class="preformattedContent">
285<pre>&lt;project&gt;
286 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
287 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
288 &lt;artifactId&gt;org.apache.felix.log&lt;/artifactId&gt;
289 &lt;packaging&gt;bundle&lt;/packaging&gt;
290 &lt;name&gt;Apache Felix Log Service&lt;/name&gt;
291 &lt;version&gt;0.8.0-SNAPSHOT&lt;/version&gt;
292 &lt;description&gt;
293 This bundle provides an implementation of the OSGi R4 Log service.
294 &lt;/description&gt;
295 &lt;dependencies&gt;
296 &lt;dependency&gt;
297 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
298 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
299 &lt;version&gt;0.8.0-incubator&lt;/version&gt;
300 &lt;/dependency&gt;
301 &lt;dependency&gt;
302 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
303 &lt;artifactId&gt;org.osgi.compendium&lt;/artifactId&gt;
304 &lt;version&gt;0.9.0-incubator-SNAPSHOT&lt;/version&gt;
305 &lt;/dependency&gt;
306 &lt;/dependencies&gt;
307 &lt;build&gt;
308 &lt;plugins&gt;
309 &lt;plugin&gt;
310 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
311 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
312 &lt;extensions&gt;true&lt;/extensions&gt;
313 &lt;configuration&gt;
314 &lt;instructions&gt;
315 &lt;Export-Package&gt;org.osgi.service.log&lt;/Export-Package&gt;
316 &lt;Private-Package&gt;org.apache.felix.log.impl&lt;/Private-Package&gt;
317 &lt;Bundle-SymbolicName&gt;${pom.artifactId}&lt;/Bundle-SymbolicName&gt;
318 &lt;Bundle-Activator&gt;${pom.artifactId}.impl.Activator&lt;/Bundle-Activator&gt;
319 &lt;Export-Service&gt;org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService&lt;/Export-Service&gt;
320 &lt;/instructions&gt;
321 &lt;/configuration&gt;
322 &lt;/plugin&gt;
323 &lt;/plugins&gt;
324 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000325&lt;/project&gt;
326</pre>
327</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000328
Karl Paulsf87ac142007-07-06 22:36:17 +0000329<p>Notice that the <tt>&lt;Export-Package&gt;</tt> instruction
330specifies that the bundle exports the Log Service package, even though
331this package is not contained in the bundle project. By declaring this,
332the plugin will copy the Log Service package into the resulting bundle
333JAR file. This is useful in this case because now the bundle can
334resolve without having to download the entire compendium bundle. The
335resulting manifest for the Log Service bundle looks like this (notice
336how the imports/exports automatically have version information
337associated with them, which was obtained from packageinfo files in the
338source packages):</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000339
Karl Paulsf87ac142007-07-06 22:36:17 +0000340<div class="preformatted"><div class="preformattedContent">
341<pre>Manifest-Version: 1
342Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
343Bundle-Activator: org.apache.felix.log.impl.Activator
344Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v
345 ersion=1.3
346Include-Resource: src/main/resources
347Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version=
348 1.3
349Bundle-Version: 0.8.0.SNAPSHOT
350Bundle-Name: Apache Felix Log Service
351Bundle-Description: This bundle provides an implementation of the OSGi
352 R4 Log service.
353Private-Package: org.apache.felix.log.impl
354Bundle-ManifestVersion: 2
355Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L
356 ogReaderService
357Bundle-SymbolicName: org.apache.felix.log
358</pre>
359</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000360
Karl Paulsf87ac142007-07-06 22:36:17 +0000361<p>The resulting bundle JAR file has the following content (notice how
362the LICENSE and NOTICE files were automatically copied from the <tt>src/main/resources/</tt> directory of the project):</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000363
Karl Paulsf87ac142007-07-06 22:36:17 +0000364<div class="preformatted"><div class="preformattedContent">
365<pre>META-INF/MANIFEST.MF
366LICENSE
367META-INF/
368META-INF/maven/
369META-INF/maven/org.apache.felix/
370META-INF/maven/org.apache.felix/org.apache.felix.log/
371META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties
372META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml
373NOTICE
374org/
375org/apache/
376org/apache/felix/
377org/apache/felix/log/
378org/apache/felix/log/impl/
379org/apache/felix/log/impl/Activator.class
380org/apache/felix/log/impl/Log.class
381org/apache/felix/log/impl/LogEntryImpl.class
382org/apache/felix/log/impl/LogException.class
383org/apache/felix/log/impl/LogListenerThread.class
384org/apache/felix/log/impl/LogNode.class
385org/apache/felix/log/impl/LogNodeEnumeration.class
386org/apache/felix/log/impl/LogReaderServiceFactory.class
387org/apache/felix/log/impl/LogReaderServiceImpl.class
388org/apache/felix/log/impl/LogServiceFactory.class
389org/apache/felix/log/impl/LogServiceImpl.class
390org/osgi/
391org/osgi/service/
392org/osgi/service/log/
393org/osgi/service/log/LogEntry.class
394org/osgi/service/log/LogListener.class
395org/osgi/service/log/LogReaderService.class
396org/osgi/service/log/LogService.class
397org/osgi/service/log/package.html
398org/osgi/service/log/packageinfo
399</pre>
400</div></div>
401
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000402<h2><a name="ApacheFelixMavenBundlePlugin(BND)-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype"></a>Adding OSGi metadata to existing projects without changing the packaging type</h2>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000403
404<p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br>
405you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br>
406add this manifest to the final artifact. For example:</p>
407
408<div class="code"><div class="codeContent">
409<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
410 <span class="code-tag">&lt;artifactId&gt;</span>maven-jar-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
411 <span class="code-tag">&lt;configuration&gt;</span>
412 <span class="code-tag">&lt;archive&gt;</span>
413 <span class="code-tag">&lt;manifestFile&gt;</span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag">&lt;/manifestFile&gt;</span>
414 <span class="code-tag">&lt;/archive&gt;</span>
415 <span class="code-tag">&lt;/configuration&gt;</span>
416<span class="code-tag">&lt;/plugin&gt;</span>
417<span class="code-tag">&lt;plugin&gt;</span>
418 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
419 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
420 <span class="code-tag">&lt;executions&gt;</span>
421 <span class="code-tag">&lt;execution&gt;</span>
422 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
423 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
424 <span class="code-tag">&lt;goals&gt;</span>
425 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
426 <span class="code-tag">&lt;/goals&gt;</span>
427 <span class="code-tag">&lt;/execution&gt;</span>
428 <span class="code-tag">&lt;/executions&gt;</span>
429<span class="code-tag">&lt;/plugin&gt;</span></pre>
430</div></div>
431
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000432<h2><a name="ApacheFelixMavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000433
Stuart McCulloch93de6492007-12-16 15:59:05 +0000434<p>The plugin is hosted at the Apache Felix project. The following
435steps describe how to build and install the plugin into your local
436Maven2 repository.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000437
438<p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000439
Karl Paulsf87ac142007-07-06 22:36:17 +0000440<div class="preformatted"><div class="preformattedContent">
Stuart McCulloch93de6492007-12-16 15:59:05 +0000441<pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin
Karl Paulsf87ac142007-07-06 22:36:17 +0000442</pre>
443</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000444
Karl Paulsf87ac142007-07-06 22:36:17 +0000445<p>Using Maven2, build and install the maven-bundle-plugin by issuing
446the following Maven2 command in the project directory that was created
447as a result of the previous step.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000448
Karl Paulsf87ac142007-07-06 22:36:17 +0000449<div class="preformatted"><div class="preformattedContent">
450<pre>$ mvn install
451</pre>
452</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000453
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000454<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Goals"></a>Goals</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000455
456<p>The maven-bundle-plugin also provides additional functionality via
457some Maven goals. Command-line execution of a goal is performed as
458follows:</p>
459
460<div class="preformatted"><div class="preformattedContent">
461<pre>mvn org.apache.felix:maven-bundle-plugin:GOAL
462</pre>
463</div></div>
464
465<p>Where GOAL is one of the following:</p>
466
467<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000468 <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000469configuration options:
470 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000471 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
472 <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000473 <li><em><tt>excludeDependencies</tt></em> comma-separated list of dependency artifactIds to exclude from the classpath passed to Bnd (use "true" to exclude everything)</li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000474 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000475 <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000476 </ul>
477 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000478</ul>
479
480
481<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000482 <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000483configuration options:
484 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000485 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000486 </ul>
487 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000488</ul>
489
490
491<ul>
492 <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000493configuration options:
494 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000495 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000496 </ul>
497 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000498</ul>
499
500
501<ul>
502 <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000503configuration options:
504 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000505 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
506 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000507 </ul>
508 </li>
509</ul>
510
511
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000512<ul>
513 <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br>
514configuration options:
515 <ul>
516 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
517 </ul>
518 </li>
519</ul>
520
521
522<p>More GOALs are available in the <b>1.4.0</b> release:</p>
523
524<ul>
525 <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li>
526</ul>
527
528
529<ul>
530 <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br>
531configuration options:
532 <ul>
533 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
534 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
535 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
536 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
537 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
538 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
539 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
540 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
541 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
542 </ul>
543 </li>
544</ul>
545
546
547<ul>
548 <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br>
549configuration options:
550 <ul>
551 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
552 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
553 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
554 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
555 </ul>
556 </li>
557</ul>
558
559
560<ul>
561 <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br>
562configuration options:
563 <ul>
564 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li>
565 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
566 <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li>
567 <li><em><tt>url</tt></em> remote repository transport URL, like
568<div class="preformatted"><div class="preformattedContent">
569<pre>scpexe://host/path/to/obr
570</pre>
571</div></div></li>
572 <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like
573<div class="preformatted"><div class="preformattedContent">
574<pre>http://www.foo.org/bundles/foo.jar
575</pre>
576</div></div></li>
577 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
578 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
579 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
580 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
581 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
582 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
583 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
584 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
585 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
586 </ul>
587 </li>
588</ul>
589
590
591<ul>
592 <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br>
593configuration options:
594 <ul>
595 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
596 </ul>
597 </li>
598</ul>
599
600
Stuart McCulloch93de6492007-12-16 15:59:05 +0000601<p>There are also new instructions available from the underlying BND
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000602tool, which continues to be improved independently; for the latest see <span class="nobr"><a href="http://aqute.biz/Code/Bnd" title="Visit page outside Confluence" rel="nofollow">BND documentation<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000603
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000604<p>The default goal <b><tt>bundle</tt></b> will be initialized by setting the &lt;packaging&gt; entry to "bundle".</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000605
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000606<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Thefollowingfeaturesareonlyavailablefromversion1.2.0onwards"></a>The following features are only available from version 1.2.0 onwards</h1>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000607
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000608<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000609
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000610<p>The Maven Bundle Plugin supports embedding of selected project dependencies inside the bundle by using the <tt>&lt;Embed-Dependency&gt;</tt> instruction:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000611
612<div class="code"><div class="codeContent">
613<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>dependencies<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
614</div></div>
615
616<p>where:</p>
617
618<div class="preformatted"><div class="preformattedContent">
619<pre>dependencies ::= clause ( ',' clause ) *
620clause ::= MATCH ( ';' attr '=' MATCH | ';inline=true' )
621attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier'
622MATCH ::= &lt;globbed regular expressions&gt;
623</pre>
624</div></div>
625
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000626<p>The plugin uses the <tt>&lt;Embed-Dependency&gt;</tt> instruction to transform the project dependencies into <tt>&lt;Include-Resource&gt;</tt> and <tt>&lt;Bundle-ClassPath&gt;</tt>
627clauses, which are then appended to the current set of instructions and
628passed onto BND. If you want the embedded dependencies to be at the
629start or middle of <tt>&lt;Include-Resource&gt;</tt> or <tt>&lt;Bundle-ClassPath&gt;</tt> then you can use {<tt>maven-dependencies</tt>}, which will automatically expand to the relevant clauses.</p>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000630
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000631<p>The MATCH section accepts alternatives, separated by <b>|</b>, and can be negated by using <b>!</b> at the <em>beginning</em> of the MATCH. Use <b>*</b> to represent zero or more unknown characters and <b>?</b> to represent a single unknown character. There is no need to escape the <b>.</b> character inside MATCH. The first MATCH in a clause will filter against the artifactId.</p>
632
Stuart McCulloch93de6492007-12-16 15:59:05 +0000633<p>some examples:</p>
634
635<div class="code"><div class="codeContent">
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000636<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies --&gt;</span></span>
637<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=compile|runtime<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000638
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000639<span class="code-tag"><span class="code-comment">&lt;!-- embed any dependencies with artifactId junit and scope test --&gt;</span></span>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000640<span class="code-tag">&lt;Embed-Dependency&gt;</span>junit;scope=test<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
641
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000642<span class="code-tag"><span class="code-comment">&lt;!-- inline all dependencies, except those with scope test --&gt;</span></span>
643<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=!test;inline=true<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
644
645<span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies, except those with artifactIds in the given list --&gt;</span></span>
646<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=compile|runtime;inline=false;artifactId=!cli|lang|runtime|tidy|jsch<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000647</div></div>
648
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000649<p>examples of using {<tt>maven-dependencies</tt>}:</p>
650
651<div class="code"><div class="codeContent">
652<pre class="code-xml"><span class="code-tag">&lt;Include-Resource&gt;</span>
653 {maven-resources}, {maven-dependencies},
654 org/foo/Example.class=target/classes/org/foo/Example.class
655<span class="code-tag">&lt;/Include-Resource&gt;</span>
656
657<span class="code-tag">&lt;Bundle-ClassPath&gt;</span>.,{maven-dependencies},some.jar<span class="code-tag">&lt;/Bundle-ClassPath&gt;</span></pre>
658</div></div>
659
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000660<p>By default matched dependencies are embedded in the bundle as <tt>artifactId-version.jar</tt>. This behaviour can be modified using the following instructions:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000661
662<ul>
663 <li><tt>&lt;Embed-StripVersion&gt;true&lt;/Embed-StripVersion&gt;</tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li>
664 <li><tt>&lt;Embed-StripGroup&gt;false&lt;/Embed-StripGroup&gt;</tt> - adds the groupId as a subdirectory (ie. <em>groupId/artifactId-version.jar</em>)</li>
665 <li><tt>&lt;Embed-Directory&gt;directory&lt;/Embed-Directory&gt;</tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li>
666</ul>
667
668
669<p>Normally the plugin only checks direct dependencies, but this can be
670changed to include the complete set of transitive dependencies with the
671following option:</p>
672
673<div class="code"><div class="codeContent">
674<pre class="code-xml"><span class="code-tag">&lt;Embed-Transitive&gt;</span>true<span class="code-tag">&lt;/Embed-Transitive&gt;</span></pre>
675</div></div>
676
677<p>If you want a dependency inlined instead of embedded add the <tt>inline=true</tt>. For example to inline all <em>compile</em> and <em>runtime</em> scoped dependencies use:</p>
678
679<div class="code"><div class="codeContent">
680<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=compile|runtime;inline=true<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
681</div></div>
682
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000683<h3><a name="ApacheFelixMavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000684
685<p>If you embed a dependency with <tt>&lt;Embed-Dependency&gt;</tt>, and your <tt>&lt;Export-Package&gt;</tt> or <tt>&lt;Private-Package&gt;</tt> instructions match packages inside the embedded jar, you will see some duplication inside the bundle. This is because the <tt>&lt;Export-Package&gt;</tt> and <tt>&lt;Private-Package&gt;</tt>
686instructions will result in classes being inlined in the bundle, even
687though they also exist inside the embedded jar. If you want to export
688packages from an embedded dependency without such duplication then you
689can either inline the dependency, or use a new BND instruction called <tt>&lt;_exportcontents&gt;</tt>.</p>
690
691<p><tt>&lt;_exportcontents&gt;</tt> behaves just like Export-Package, except it doesn't change the content of the bundle, just what content should be exported.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000692
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000693<h2><a name="ApacheFelixMavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000694
695<p>The latest Maven Bundle Plugin automatically updates the local OBR
696repository.xml file during the install phase, using a default location
697of:</p>
698
699<div class="code"><div class="codeContent">
700<pre class="code-java">&lt;LOCAL-MAVEN-REPOSITORY&gt;/repository.xml</pre>
701</div></div>
702
703<p>You can configure the location of the OBR repository by using the command line:</p>
704
705<div class="code"><div class="codeContent">
706<pre class="code-java">mvn clean install -DobrRepository=&lt;PATH_TO_OBR&gt;</pre>
707</div></div>
708
709<p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p>
710
711<div class="code"><div class="codeContent">
712<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
713<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
714<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
715<span class="code-tag">&lt;configuration&gt;</span>
716 <span class="code-tag">&lt;obrRepository&gt;</span>PATH_TO_OBR<span class="code-tag">&lt;/obrRepository&gt;</span>
717 <span class="code-tag">&lt;instructions&gt;</span>
718 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
719 <span class="code-tag">&lt;/instructions&gt;</span>
720<span class="code-tag">&lt;/configuration&gt;</span></pre>
721</div></div>
722
723<p>to disable OBR installation set the obrRepository to NONE, for example:</p>
724
725<div class="code"><div class="codeContent">
726<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
727<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
728<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
729<span class="code-tag">&lt;configuration&gt;</span>
730 <span class="code-tag">&lt;obrRepository&gt;</span>NONE<span class="code-tag">&lt;/obrRepository&gt;</span>
731 <span class="code-tag">&lt;instructions&gt;</span>
732 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
733 <span class="code-tag">&lt;/instructions&gt;</span>
734<span class="code-tag">&lt;/configuration&gt;</span></pre>
735</div></div>
736
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000737<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000738
739<p>It is possible to configure the Maven Bundle Plugin to put the
740bundle manifest where Eclipse/PDE expects it, and use the Maven
741Dependency Plugin to arrange for any embedded dependencies to appear in
742a local directory that matches the Bundle-ClassPath entries. Here is an
743example POM that does this:</p>
744
745<div class="preformatted"><div class="preformattedContent">
746<pre>&lt;project&gt;
747
748 &lt;properties&gt;
749 &lt;bundle.symbolicName&gt;org.example&lt;/bundle.symbolicName&gt;
750 &lt;bundle.namespace&gt;org.example&lt;/bundle.namespace&gt;
751 &lt;/properties&gt;
752
753 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
754 &lt;groupId&gt;examples&lt;/groupId&gt;
755 &lt;artifactId&gt;org.example&lt;/artifactId&gt;
756 &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
757
758 &lt;name&gt;${bundle.symbolicName} [${bundle.namespace}]&lt;/name&gt;
759
760 &lt;packaging&gt;bundle&lt;/packaging&gt;
761
762 &lt;build&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000763 &lt;resources&gt;
764 &lt;resource&gt;
765 &lt;directory&gt;src/main/resources&lt;/directory&gt;
766 &lt;/resource&gt;
767 &lt;resource&gt;
768 &lt;directory&gt;.&lt;/directory&gt;
769 &lt;includes&gt;
770 &lt;include&gt;plugin.xml&lt;/include&gt;
771 &lt;/includes&gt;
772 &lt;/resource&gt;
773 &lt;/resources&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000774 &lt;plugins&gt;
775 &lt;plugin&gt;
776 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
777 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000778 &lt;version&gt;1.2.1&lt;/version&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000779 &lt;extensions&gt;true&lt;/extensions&gt;
780 &lt;!--
781 the following instructions build a simple set of public/private classes into an OSGi bundle
782 --&gt;
783 &lt;configuration&gt;
784 &lt;manifestLocation&gt;META-INF&lt;/manifestLocation&gt;
785 &lt;instructions&gt;
786 &lt;Bundle-SymbolicName&gt;${bundle.symbolicName}&lt;/Bundle-SymbolicName&gt;
787 &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
788 &lt;!--
789 assume public classes are in the top package, and private classes are under ".internal"
790 --&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000791 &lt;Export-Package&gt;!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"&lt;/Export-Package&gt;
792 &lt;Private-Package&gt;${bundle.namespace}.internal.*&lt;/Private-Package&gt;
793 &lt;Bundle-Activator&gt;${bundle.namespace}.internal.ExampleActivator&lt;/Bundle-Activator&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000794 &lt;!--
795 embed compile/runtime dependencies using path that matches the copied dependency folder
796 --&gt;
797 &lt;Embed-Dependency&gt;*;scope=compile|runtime;inline=false&lt;/Embed-Dependency&gt;
798 &lt;Embed-Directory&gt;target/dependency&lt;/Embed-Directory&gt;
799 &lt;Embed-StripGroup&gt;true&lt;/Embed-StripGroup&gt;
800 &lt;/instructions&gt;
801 &lt;/configuration&gt;
802 &lt;/plugin&gt;
803 &lt;plugin&gt;
804 &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
805 &lt;executions&gt;
806 &lt;execution&gt;
807 &lt;id&gt;copy-dependencies&lt;/id&gt;
808 &lt;phase&gt;package&lt;/phase&gt;
809 &lt;goals&gt;
810 &lt;goal&gt;copy-dependencies&lt;/goal&gt;
811 &lt;/goals&gt;
812 &lt;/execution&gt;
813 &lt;/executions&gt;
814 &lt;/plugin&gt;
815 &lt;/plugins&gt;
816 &lt;/build&gt;
817
818 &lt;dependencies&gt;
819 &lt;dependency&gt;
820 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
821 &lt;artifactId&gt;osgi_R4_core&lt;/artifactId&gt;
822 &lt;version&gt;1.0&lt;/version&gt;
823 &lt;scope&gt;provided&lt;/scope&gt;
824 &lt;optional&gt;true&lt;/optional&gt;
825 &lt;/dependency&gt;
826 &lt;dependency&gt;
827 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
828 &lt;artifactId&gt;osgi_R4_compendium&lt;/artifactId&gt;
829 &lt;version&gt;1.0&lt;/version&gt;
830 &lt;scope&gt;provided&lt;/scope&gt;
831 &lt;optional&gt;true&lt;/optional&gt;
832 &lt;/dependency&gt;
833 &lt;dependency&gt;
834 &lt;groupId&gt;junit&lt;/groupId&gt;
835 &lt;artifactId&gt;junit&lt;/artifactId&gt;
836 &lt;version&gt;3.8.1&lt;/version&gt;
837 &lt;scope&gt;compile&lt;/scope&gt;
838 &lt;optional&gt;true&lt;/optional&gt;
839 &lt;/dependency&gt;
840 &lt;/dependencies&gt;
841
842&lt;/project&gt;
843</pre>
844</div></div>
845
846<p>To generate the Eclipse metadata use:</p>
847
848<div class="code"><div class="codeContent">
849<pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre>
850</div></div>
851
852<p>and you should now be able to import this as an existing Eclipse project.</p>
853
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000854<p>FYI: the above POM was generated using the <tt>pax-create-bundle</tt> command from <span class="nobr"><a href="http://www.ops4j.org/projects/pax/construct/index.html" title="Visit page outside Confluence" rel="nofollow">Pax-Construct<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> and then tweaked to demonstrate using the Maven Dependency Plugin to handle embedded jars in Eclipse.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000855
856<p>With the original Pax-Construct generated POM you would simply use:</p>
857
858<div class="code"><div class="codeContent">
859<pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre>
860</div></div>
861
862<p>to create the appropriate Eclipse files and manifest, and also
863handle any embedded entries. The pax:eclipse goal extends
864eclipse:eclipse, and supports the same parameters.</p>
865
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000866<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000867
868<p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>,
869for example when you embed the classes from another jar. This can
870sometimes cause unforeseen problems in Maven, as it will use the output
871directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p>
872
873<p>The easiest way to get around this Maven 'feature' is to unpack the
874contents of the bundle to the output directory after the packaging
875step, so the additional classes will be found where Maven expects them.
876Thankfully there is now an easy option to do this in the bundle-plugin:</p>
877
878<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000879<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
880<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
881<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
882<span class="code-tag">&lt;configuration&gt;</span>
883 <span class="code-tag">&lt;unpackBundle&gt;</span>true<span class="code-tag">&lt;/unpackBundle&gt;</span>
884 <span class="code-tag">&lt;instructions&gt;</span>
885 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
886 <span class="code-tag">&lt;/instructions&gt;</span>
887<span class="code-tag">&lt;/configuration&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000888</div></div>
889
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000890<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000891
892<p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p>
893
894<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000895<pre class="code-xml"><span class="code-tag">&lt;_include&gt;</span>src/main/resources/META-INF/MANIFEST.MF<span class="code-tag">&lt;/_include&gt;</span>
896<span class="code-tag">&lt;Export-Package&gt;</span>org.example.*<span class="code-tag">&lt;/Export-Package&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000897</div></div>
898
899<p>Bnd will use it when calculating the bundle contents, and will also
900copy across all manifest attributes starting with a capital letter.<br>
901As shown in the above example, you could use this to include a non-OSGi
902manifest which you then customize with extra OSGi attributes.</p>
903
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000904<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Thefollowingfeaturesareonlyavailablefromversion1.4.0onwards"></a>The following features are only available from version 1.4.0 onwards</h1>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000905
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000906<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000907
908<p>The <b>ant</b> goal creates a customized <tt>build.xml</tt> Ant script along with a collection of BND instructions and properties, taken from the current project and stored in <tt>maven-build.bnd</tt>. You also need to run <b><tt>ant:ant</tt></b> to create the standard Ant support tasks to download Maven dependencies and perform compilation, etc.</p>
909
910<p>The customized Ant script uses the BND tool to rebuild the bundle,
911so any source changes should be reflected in the (re)generated manifest.</p>
912
913<p>Example:</p>
914<div class="preformatted"><div class="preformattedContent">
915<pre>mvn ant:ant bundle:ant
916
917ant clean package
918</pre>
919</div></div>
920
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000921<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000922
923<p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p>
924
925<p>configuration:</p>
926<ul>
927 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
928 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
929 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
930 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
931 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
932 <li><em>classifier</em> Maven classifier type, defaults to none</li>
933 <li><em>pomFile</em> optional Pom file describing the bundle</li>
934 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
935 <li><em>obrXml</em> optional additional properties for the bundle</li>
936</ul>
937
938
939<p>Example:</p>
940<div class="preformatted"><div class="preformattedContent">
941<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \
942 -DpomFile=myPom.xml -Dfile=foo-1.0.jar
943</pre>
944</div></div>
945
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000946<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000947
948<p>The <b>deploy goal</b> updates the remote OBR with the details of
949the deployed bundle from the local Maven repository. The remote OBR is
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000950found by querying the <tt>&lt;distributionManagement&gt;</tt> section of the project, unless <tt>-DaltDeploymentRepository</tt> is set. See <span class="nobr"><a href="http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html" title="Visit page outside Confluence" rel="nofollow">http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000951
952<p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p>
953
954<p>configuration:</p>
955<ul>
956 <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
957 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
958 <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li>
959 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
960</ul>
961
962
963<p>This goal is part of the "bundle" packaging lifecycle, but is disabled by default - to enable just set the <tt>remoteOBR</tt> parameter.</p>
964
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000965<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000966
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000967<p>The <b>deploy-file</b> goal updates the remote OBR with the details of a deployed bundle from the local filesystem. The remote OBR is found using the <tt>-DrepositoryId</tt> and <tt>-Durl</tt> parameters. See <span class="nobr"><a href="http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html" title="Visit page outside Confluence" rel="nofollow">http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000968
969<p>You can use the <tt>-DbundleUrl</tt> parameter to give the public location of the deployed bundle, which may differ from the remote OBR location.</p>
970
971<p>configuration:</p>
972<ul>
973 <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li>
974 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
975 <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li>
976 <li><em>url</em> remote repository transport URL, like
977<div class="preformatted"><div class="preformattedContent">
978<pre>scpexe://host/path/to/obr
979</pre>
980</div></div></li>
981 <li><em>bundleUrl</em> public URL of deployed bundle, like
982<div class="preformatted"><div class="preformattedContent">
983<pre>http://www.foo.org/bundles/foo.jar
984</pre>
985</div></div></li>
986 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
987 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
988 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
989 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
990 <li><em>classifier</em> Maven classifier type, defaults to none</li>
991 <li><em>pomFile</em> optional Pom file describing the bundle</li>
992 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
993 <li><em>obrXml</em> optional additional properties for the bundle</li>
994 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
995</ul>
996
997
998<p>Example:</p>
999<div class="preformatted"><div class="preformattedContent">
1000<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \
1001 -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \
1002 -DbundleUrl=http://www.foo.org/bundles/foo.jar
1003</pre>
1004</div></div>
1005
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001006<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001007
1008<p>Sometimes you would like to clean your local OBR because it contains
1009bundles that are no longer in your local Maven repository. This case
1010often occurs when artifacts were deleted manually. The
1011maven-bundle-plugin provides a simple goal to check for missing
1012bundles, and remove them from the local OBR.</p>
1013
1014<p>configuration:</p>
1015<ul>
1016 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1017</ul>
1018
1019
1020<p>Example:</p>
1021<div class="preformatted"><div class="preformattedContent">
1022<pre>mvn bundle:clean
1023</pre>
1024</div></div>
1025
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001026<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001027
1028<p>With a remote OBR, several uploads may occur at the same time.
1029However, the remote OBR is centralized in one file, so concurrent
1030modification must be avoided. To achieve this, the plug-in implements a
1031locking system. Each time the plug-in tries to modify the file it sets
1032a file based lock. If it can't take the lock, it will wait and retry.
1033After 3 attempts the upload process fails. To bypass this lock add <tt>-DignoreLock</tt> to the command-line (or add <tt>&lt;ignoreLock&gt;true&lt;ignoreLock&gt;</tt> to the configuration section of your Pom).</p>
1034
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001035<h2><a name="ApacheFelixMavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001036
1037<p>Not all protocols are supported by Maven out of the box. For example the ftp protocol requires the <b>wagon-ftp</b> component. To enable the ftp protocol add this to your Pom:</p>
1038<div class="code"><div class="codeContent">
1039<pre class="code-xml"><span class="code-tag">&lt;build&gt;</span>
1040 <span class="code-tag">&lt;extensions&gt;</span>
1041 <span class="code-tag">&lt;extension&gt;</span>
1042 <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.wagon<span class="code-tag">&lt;/groupId&gt;</span>
1043 <span class="code-tag">&lt;artifactId&gt;</span>wagon-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
1044 <span class="code-tag">&lt;version&gt;</span>1.0-alpha-6<span class="code-tag">&lt;/version&gt;</span>
1045 <span class="code-tag">&lt;/extension&gt;</span>
1046 <span class="code-tag">&lt;/extensions&gt;</span>
1047<span class="code-tag">&lt;/build&gt;</span></pre>
1048</div></div>
1049
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001050<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Howtheplugincomputesthedescriptionofthebundle"></a>How the plug-in computes the description of the bundle</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001051
1052<p>The description of the bundle comes from three different sources:</p>
1053<ul>
1054 <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li>
1055 <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li>
1056 <li>obr.xml : this file contains customized description and capabilities for the bundle</li>
1057</ul>
1058
1059
1060<p>These sources are merged together using the following precedence:</p>
1061<div class="preformatted"><div class="preformattedContent">
1062<pre>Bindex
1063| (overrides)
1064pom.xml
1065| (overrides)
1066obr.xml
1067</pre>
1068</div></div>
1069<p>A warning message is displayed when existing information is overridden.</p>
1070
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001071<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Knownissues&amp;limitations"></a>Known issues &amp; limitations</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001072
1073<ol>
1074 <li>obr.xml (file given by the user to add properties not found
1075by Bindex) must be correct, because the plug-in does not check its
1076syntax.</li>
1077</ol>
1078
1079
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001080<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Feedback"></a>Feedback</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +00001081
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001082<p>Subscribe to the Felix users mailing list by sending a message to <span class="nobr"><a href="mailto:users-subscribe@felix.apache.org" title="Send mail to users-subscribe@felix.apache.org" rel="nofollow">users-subscribe@felix.apache.org<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/mail_small.gif" alt="" align="absmiddle" border="0" height="12" width="13"></sup></a></span>; after subscribing, email questions or feedback to <span class="nobr"><a href="mailto:users@felix.apache.org" title="Send mail to users@felix.apache.org" rel="nofollow">users@felix.apache.org<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/mail_small.gif" alt="" align="absmiddle" border="0" height="12" width="13"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +00001083 </div>
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001084
1085</body></html>