blob: 378ac2bed83b4a4e4e4062b011c8b899a34ba397 [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 McCulloch981bd342008-05-03 12:49:39 +00002<html><head>
Karl Paulsf87ac142007-07-06 22:36:17 +00003
4
5
Stuart McCulloch981bd342008-05-03 12:49:39 +00006 <title>Apache Felix - Apache Felix Maven Bundle Plugin (BND)</title>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00007 <link rel="stylesheet" href="apache-felix-maven-bundle-plugin-bnd_files/site.css" type="text/css" media="all">
Stuart McCulloch981bd342008-05-03 12:49:39 +00008 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 </head><body>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000010 <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 +000011 <div class="menu">
Stuart McCulloch93de6492007-12-16 15:59:05 +000012<ul>
Stuart McCulloch93de6492007-12-16 15:59:05 +000013 <li><a href="http://felix.apache.org/site/news.html" title="news">news</a></li>
Stuart McCulloch93de6492007-12-16 15:59:05 +000014 <li><a href="http://felix.apache.org/site/license.html" title="license">license</a></li>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000015 <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 +000016 <li><a href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</a></li>
17 <li><a href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</a></li>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000018 <li><a href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</a></li>
19 <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>
20 <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>
21 <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>
22<!-- ApacheCon Ad -->
23<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>
24<p style="height: 100px;">
25<!-- ApacheCon Ad -->
26</p></li></ul> </div>
Karl Paulsf87ac142007-07-06 22:36:17 +000027 <div class="main">
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000028<h1><a name="ApacheFelixMavenBundlePlugin(BND)-BundlePluginforMaven"></a>Bundle Plugin for Maven</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000029
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000030<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 +000031tool from Peter Kriens. The way BND works is by treating your project
32as a big collection of classes (e.g., project code, dependencies, and
33the class path). The way you create a bundle with BND is to tell it the
34content of the bundle's JAR file as a subset of the available classes.
35This plugin wraps BND to make it work specifically with the Maven 2
36project structure and to provide it with reasonable default behavior
37for Maven 2 projects.</p>
38
Stuart McCulloch0340ae42008-02-22 11:27:18 +000039<p>Since the 1.4.0 release, this plugin also aims to automate OBR (OSGi
40Bundle Repository) management. It helps manage a local OBR for your
41local Maven repository, and also supports remote OBRs for bundle
42distribution. The plug-in automatically computes bundle capabilities
43and requirements, using a combination of Bindex and Maven metadata.</p>
44
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000045<p><a name="ApacheFelixMavenBundlePlugin(BND)-simpleexample"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +000046
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000047<h1><a name="ApacheFelixMavenBundlePlugin(BND)-SimpleExample"></a>Simple Example</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000048
49<p>Rather than going straight to a detailed list of plugin features, we
50will first look at a simple example of how to use the plugin to give an
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000051immediate 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 +000052
53<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 +000054
Karl Paulsf87ac142007-07-06 22:36:17 +000055<div class="preformatted"><div class="preformattedContent">
56<pre>org.foo.myproject.api
57org.foo.myproject.impl1
58org.foo.myproject.impl2
59...
60</pre>
61</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000062
Karl Paulsf87ac142007-07-06 22:36:17 +000063<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 +000064
Karl Paulsf87ac142007-07-06 22:36:17 +000065<div class="preformatted"><div class="preformattedContent">
66<pre>...
67&lt;plugins&gt;
68 &lt;plugin&gt;
69 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
70 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
71 &lt;extensions&gt;true&lt;/extensions&gt;
72 &lt;configuration&gt;
73 &lt;instructions&gt;
74 &lt;Export-Package&gt;org.foo.myproject.api&lt;/Export-Package&gt;
75 &lt;Private-Package&gt;org.foo.myproject.*&lt;/Private-Package&gt;
76 &lt;Bundle-Activator&gt;org.foo.myproject.impl1.Activator&lt;/Bundle-Activator&gt;
77 &lt;/instructions&gt;
78 &lt;/configuration&gt;
79 &lt;/plugin&gt;
80&lt;/plugins&gt;
81...
82</pre>
83</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000084
Karl Paulsf87ac142007-07-06 22:36:17 +000085<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>
86export. If the two sets overlap, as they do in the case, then the
87export takes precedence. Since we did not specify any values for any
88other bundle manifest headers, they will assume default values which
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000089are 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 +000090bundle manifest header based on the contents of the bundle, which means
91that you generally do not ever need to explicitly specify it yourself.
92That's it.</p>
93
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000094<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Features"></a>Features</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000095
96<p>The BND library underlying the plugin defines instructions to direct
97its behavior. For this Maven plugin, these instructions are issued in
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000098the 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 +000099
Karl Paulsf87ac142007-07-06 22:36:17 +0000100<ol>
101 <li><em>Manifest headers</em> - Any instruction that starts with
102a capital letter will appear in the resulting bundle's manifest file;
103the value for the header will either be copied, augmented, or generated
104by BND depending on the instruction.</li>
105 <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>
106 <li><em>Directives</em>
107- Any instruction starting with a '-' character is considered to be a
108directive that informs BND to perform some special processing and is
109not copied to the manifest.</li>
110</ol>
111
112
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000113<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 +0000114
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000115<p><a name="ApacheFelixMavenBundlePlugin(BND)-instructions"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000116
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000117<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Instructions"></a>Instructions</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000118
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000119<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ExportPackage&gt;}}"></a><tt>&lt;Export-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000120
121<p>The <tt>&lt;Export-Package&gt;</tt> instruction is a list of
122packages for the bundle to export. These packages are copied into the
123resulting bundle JAR file from the available classes (i.e., project
124classes, dependencies, and class path); thus, it is possible to include
125classes into your bundle that are not associated with source files in
126your project. <tt>&lt;Export-Package&gt;</tt> can be specified with
127package patterns using the '*' wildcard. Also, it is possible to
128exclude packages using negation by starting the package pattern with
129'!'. Thus, non-negated patterns indicate which of the available
130packages to include in the bundle, whereas negated patterns indicate
131which should not be included in the bundle.</p>
132
133<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>
134
135<p>Following standard OSGi R4 syntax, package patterns can include both
136directives and attributes, which will be copied appropriately into the
137generated Export-Package manifest header. Besides explicitly listing
138package version attributes, BND will also determine package versions by
139examining the source JAR file or from <tt>packageinfo</tt> files in the package directory.</p>
140
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000141<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;PrivatePackage&gt;}}"></a><tt>&lt;Private-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000142
143<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>
144be exported by the bundle. If a package is selected by both the export
145and private package headers, then the export takes precedence.</p>
146
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000147<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;IncludeResource&gt;}}"></a><tt>&lt;Include-Resource&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000148
149<p>The <tt>&lt;Include-Resource&gt;</tt> instruction is a list of
150arbitrary resources that should be copied into the bundle JAR file. The
151specified resources are declared as clauses that can have the following
152forms:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000153
Karl Paulsf87ac142007-07-06 22:36:17 +0000154<div class="preformatted"><div class="preformattedContent">
155<pre>clause ::= assignment | inline | simple
156assignment ::= PATH '=' PATH
157simple ::= PATH
158inline ::= '@' PATH
159</pre>
160</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000161
Karl Paulsf87ac142007-07-06 22:36:17 +0000162<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>
163form will place the resource in the bundle JAR with only the file name,
164i.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>
165points to a directory, the entire directory hierarchy is copied into
166the resulting bundle JAR file relative to the specified directory. If a
167specific resource must be placed into a subdirectory of the bundle jar,
168then use the <tt>assignment</tt> form, where the first path is the the
169destination path (including file name if the resource is a file) and
170the 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>
171
172<p>If a resource clause is specified inside of "{ ... }" brackets, then
173variable substitution will be performed on the resource, where
174variables in the resources are denoted with "${ ... }" syntax.</p>
175
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000176<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>
177
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000178<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ImportPackage&gt;}}"></a><tt>&lt;Import-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000179
180<p>The <tt>&lt;Import-Package&gt;</tt> instruction is a list of
181packages that are required by the bundle's contained packages. The
182default for this header is "*", resulting in importing all referred
183packages. This header rarely has to be explicitly specified. However,
184in certain cases when there is an unwanted import, such an import can
185be removed by using a negation package pattern. The package patterns
186work 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>
187
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000188<p><a name="ApacheFelixMavenBundlePlugin(BND)-defaultbehavior"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000189
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000190<h2><a name="ApacheFelixMavenBundlePlugin(BND)-DefaultBehavior"></a>Default Behavior</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000191
192<p>To use this plugin, very little information is required by BND. As
193part of the Maven integration, the plugin tries to set reasonable
194defaults for various instructions. For example:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000195
Karl Paulsf87ac142007-07-06 22:36:17 +0000196<ul>
197 <li><tt>&lt;Bundle-SymbolicName&gt;</tt> is assumed to be "<tt>${groupId}.${artifactId</tt>}".</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000198 <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 +0000199 <li><tt>&lt;Private-Package&gt;</tt> is assumed to be empty by default.</li>
200 <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 +0000201 <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 +0000202which will copy the specified project directory hierarchy into the
203resulting bundle JAR file, mirroring standard Maven behavior.</li>
204 <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>
205 <li><tt>&lt;Bundle-Name&gt;</tt> is assumed to be "<tt>${pom.name</tt>}".</li>
206 <li><tt>&lt;Bundle-Description&gt;</tt> is assumed to be "<tt>${pom.description</tt>}".</li>
207 <li><tt>&lt;Bundle-License&gt;</tt> is assumed to be "<tt>${pom.licenses</tt>}".</li>
208 <li><tt>&lt;Bundle-Vendor&gt;</tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li>
209 <li><tt>&lt;Bundle-DocURL&gt;</tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li>
210</ul>
211
212
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000213<p>Since the plugin creates bundles for OSGi R4, it hard-codes <tt>Bundle-ManifestVersion</tt>
Karl Paulsf87ac142007-07-06 22:36:17 +0000214to be '2'. Additionally, it generates imports for every export to
215ensure package substitutability, which is very important when working
216with collaborating services. It is possible to override any of these
217values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p>
218
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000219<p><a name="ApacheFelixMavenBundlePlugin(BND)-howto"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000220
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000221<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Detailed&quot;HowTo&quot;"></a>Detailed "How To"</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +0000222
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000223<h2><a name="ApacheFelixMavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000224
225<p>The first step in the process of using the plugin is downloading and
226installing the latest version of the Maven2 runtime. The latest Maven2
227release and instuctions for getting started with Maven2 can be found at
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000228the <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 +0000229
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000230<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000231
232<p>To use the maven-bundle-plugin, you first need to add the plugin and
233some appropriate plugin configuration to your bundle project's POM.
234Below is an example of a simple OSGi bundle POM for Maven2:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000235
Karl Paulsf87ac142007-07-06 22:36:17 +0000236<div class="preformatted"><div class="preformattedContent">
237<pre>&lt;project&gt;
238 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
239 &lt;groupId&gt;my-osgi-bundles&lt;/groupId&gt;
240 &lt;artifactId&gt;examplebundle&lt;/artifactId&gt;
241 &lt;packaging&gt;bundle&lt;/packaging&gt; &lt;!-- (1) --&gt;
242 &lt;version&gt;1.0&lt;/version&gt;
243 &lt;name&gt;Example Bundle&lt;/name&gt;
244 &lt;dependencies&gt;
245 &lt;dependency&gt;
246 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
247 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000248 &lt;version&gt;1.0.0&lt;/version&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000249 &lt;/dependency&gt;
250 &lt;/dependencies&gt;
251 &lt;build&gt;
252 &lt;plugins&gt;
253 &lt;plugin&gt; &lt;!-- (2) START --&gt;
254 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
255 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
256 &lt;extensions&gt;true&lt;/extensions&gt;
257 &lt;configuration&gt;
258 &lt;instructions&gt;
259 &lt;Export-Package&gt;com.my.company.api&lt;/Export-Package&gt;
260 &lt;Private-Package&gt;com.my.company.*&lt;/Private-Package&gt;
261 &lt;Bundle-Activator&gt;com.my.company.Activator&lt;/Bundle-Activator&gt;
262 &lt;/instructions&gt;
263 &lt;/configuration&gt;
264 &lt;/plugin&gt; &lt;!-- (2) END --&gt;
265 &lt;/plugins&gt;
266 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000267&lt;/project&gt;
268</pre>
269</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000270
271<p>There are two main things to note: (1) the <tt>&lt;packaging&gt;</tt>
272specifier must be "bundle" and (2) the plugin and configuration must be
Karl Paulsf87ac142007-07-06 22:36:17 +0000273specified (the configuration section is where you will issue
Stuart McCulloch93de6492007-12-16 15:59:05 +0000274instructions to the plugin).</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000275
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000276<h2><a name="ApacheFelixMavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000277
278<p>Consider this more real-world example using Felix' Log Service
279implementation. The Log Service project is comprised of a single
280package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on
281the core OSGi interfaces as well as a dependency on the compendium OSGi
282interfaces for the specific log service interfaces. The following is
283its POM file:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000284
Karl Paulsf87ac142007-07-06 22:36:17 +0000285<div class="preformatted"><div class="preformattedContent">
286<pre>&lt;project&gt;
287 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
288 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
289 &lt;artifactId&gt;org.apache.felix.log&lt;/artifactId&gt;
290 &lt;packaging&gt;bundle&lt;/packaging&gt;
291 &lt;name&gt;Apache Felix Log Service&lt;/name&gt;
292 &lt;version&gt;0.8.0-SNAPSHOT&lt;/version&gt;
293 &lt;description&gt;
294 This bundle provides an implementation of the OSGi R4 Log service.
295 &lt;/description&gt;
296 &lt;dependencies&gt;
297 &lt;dependency&gt;
298 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
299 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
300 &lt;version&gt;0.8.0-incubator&lt;/version&gt;
301 &lt;/dependency&gt;
302 &lt;dependency&gt;
303 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
304 &lt;artifactId&gt;org.osgi.compendium&lt;/artifactId&gt;
305 &lt;version&gt;0.9.0-incubator-SNAPSHOT&lt;/version&gt;
306 &lt;/dependency&gt;
307 &lt;/dependencies&gt;
308 &lt;build&gt;
309 &lt;plugins&gt;
310 &lt;plugin&gt;
311 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
312 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
313 &lt;extensions&gt;true&lt;/extensions&gt;
314 &lt;configuration&gt;
315 &lt;instructions&gt;
316 &lt;Export-Package&gt;org.osgi.service.log&lt;/Export-Package&gt;
317 &lt;Private-Package&gt;org.apache.felix.log.impl&lt;/Private-Package&gt;
318 &lt;Bundle-SymbolicName&gt;${pom.artifactId}&lt;/Bundle-SymbolicName&gt;
319 &lt;Bundle-Activator&gt;${pom.artifactId}.impl.Activator&lt;/Bundle-Activator&gt;
320 &lt;Export-Service&gt;org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService&lt;/Export-Service&gt;
321 &lt;/instructions&gt;
322 &lt;/configuration&gt;
323 &lt;/plugin&gt;
324 &lt;/plugins&gt;
325 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000326&lt;/project&gt;
327</pre>
328</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000329
Karl Paulsf87ac142007-07-06 22:36:17 +0000330<p>Notice that the <tt>&lt;Export-Package&gt;</tt> instruction
331specifies that the bundle exports the Log Service package, even though
332this package is not contained in the bundle project. By declaring this,
333the plugin will copy the Log Service package into the resulting bundle
334JAR file. This is useful in this case because now the bundle can
335resolve without having to download the entire compendium bundle. The
336resulting manifest for the Log Service bundle looks like this (notice
337how the imports/exports automatically have version information
338associated with them, which was obtained from packageinfo files in the
339source packages):</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000340
Karl Paulsf87ac142007-07-06 22:36:17 +0000341<div class="preformatted"><div class="preformattedContent">
342<pre>Manifest-Version: 1
343Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
344Bundle-Activator: org.apache.felix.log.impl.Activator
345Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v
346 ersion=1.3
347Include-Resource: src/main/resources
348Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version=
349 1.3
350Bundle-Version: 0.8.0.SNAPSHOT
351Bundle-Name: Apache Felix Log Service
352Bundle-Description: This bundle provides an implementation of the OSGi
353 R4 Log service.
354Private-Package: org.apache.felix.log.impl
355Bundle-ManifestVersion: 2
356Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L
357 ogReaderService
358Bundle-SymbolicName: org.apache.felix.log
359</pre>
360</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000361
Karl Paulsf87ac142007-07-06 22:36:17 +0000362<p>The resulting bundle JAR file has the following content (notice how
363the 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 +0000364
Karl Paulsf87ac142007-07-06 22:36:17 +0000365<div class="preformatted"><div class="preformattedContent">
366<pre>META-INF/MANIFEST.MF
367LICENSE
368META-INF/
369META-INF/maven/
370META-INF/maven/org.apache.felix/
371META-INF/maven/org.apache.felix/org.apache.felix.log/
372META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties
373META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml
374NOTICE
375org/
376org/apache/
377org/apache/felix/
378org/apache/felix/log/
379org/apache/felix/log/impl/
380org/apache/felix/log/impl/Activator.class
381org/apache/felix/log/impl/Log.class
382org/apache/felix/log/impl/LogEntryImpl.class
383org/apache/felix/log/impl/LogException.class
384org/apache/felix/log/impl/LogListenerThread.class
385org/apache/felix/log/impl/LogNode.class
386org/apache/felix/log/impl/LogNodeEnumeration.class
387org/apache/felix/log/impl/LogReaderServiceFactory.class
388org/apache/felix/log/impl/LogReaderServiceImpl.class
389org/apache/felix/log/impl/LogServiceFactory.class
390org/apache/felix/log/impl/LogServiceImpl.class
391org/osgi/
392org/osgi/service/
393org/osgi/service/log/
394org/osgi/service/log/LogEntry.class
395org/osgi/service/log/LogListener.class
396org/osgi/service/log/LogReaderService.class
397org/osgi/service/log/LogService.class
398org/osgi/service/log/package.html
399org/osgi/service/log/packageinfo
400</pre>
401</div></div>
402
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000403<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 +0000404
405<p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br>
406you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br>
407add this manifest to the final artifact. For example:</p>
408
409<div class="code"><div class="codeContent">
410<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
411 <span class="code-tag">&lt;artifactId&gt;</span>maven-jar-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
412 <span class="code-tag">&lt;configuration&gt;</span>
413 <span class="code-tag">&lt;archive&gt;</span>
414 <span class="code-tag">&lt;manifestFile&gt;</span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag">&lt;/manifestFile&gt;</span>
415 <span class="code-tag">&lt;/archive&gt;</span>
416 <span class="code-tag">&lt;/configuration&gt;</span>
417<span class="code-tag">&lt;/plugin&gt;</span>
418<span class="code-tag">&lt;plugin&gt;</span>
419 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
420 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
421 <span class="code-tag">&lt;executions&gt;</span>
422 <span class="code-tag">&lt;execution&gt;</span>
423 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
424 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
425 <span class="code-tag">&lt;goals&gt;</span>
426 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
427 <span class="code-tag">&lt;/goals&gt;</span>
428 <span class="code-tag">&lt;/execution&gt;</span>
429 <span class="code-tag">&lt;/executions&gt;</span>
430<span class="code-tag">&lt;/plugin&gt;</span></pre>
431</div></div>
432
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000433<h2><a name="ApacheFelixMavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000434
Stuart McCulloch93de6492007-12-16 15:59:05 +0000435<p>The plugin is hosted at the Apache Felix project. The following
436steps describe how to build and install the plugin into your local
437Maven2 repository.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000438
439<p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000440
Karl Paulsf87ac142007-07-06 22:36:17 +0000441<div class="preformatted"><div class="preformattedContent">
Stuart McCulloch93de6492007-12-16 15:59:05 +0000442<pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin
Karl Paulsf87ac142007-07-06 22:36:17 +0000443</pre>
444</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000445
Karl Paulsf87ac142007-07-06 22:36:17 +0000446<p>Using Maven2, build and install the maven-bundle-plugin by issuing
447the following Maven2 command in the project directory that was created
448as a result of the previous step.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000449
Karl Paulsf87ac142007-07-06 22:36:17 +0000450<div class="preformatted"><div class="preformattedContent">
451<pre>$ mvn install
452</pre>
453</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000454
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000455<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Goals"></a>Goals</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000456
457<p>The maven-bundle-plugin also provides additional functionality via
458some Maven goals. Command-line execution of a goal is performed as
459follows:</p>
460
461<div class="preformatted"><div class="preformattedContent">
462<pre>mvn org.apache.felix:maven-bundle-plugin:GOAL
463</pre>
464</div></div>
465
466<p>Where GOAL is one of the following:</p>
467
468<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000469 <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000470configuration options:
471 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000472 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
473 <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000474 <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 +0000475 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000476 <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000477 </ul>
478 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000479</ul>
480
481
482<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000483 <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000484configuration options:
485 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000486 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000487 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000488 </ul>
489 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000490</ul>
491
492
493<ul>
494 <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000495configuration options:
496 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000497 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000498 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000499 </ul>
500 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000501</ul>
502
503
504<ul>
505 <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000506configuration options:
507 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000508 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
509 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000510 </ul>
511 </li>
512</ul>
513
514
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000515<ul>
516 <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br>
517configuration options:
518 <ul>
519 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
520 </ul>
521 </li>
522</ul>
523
524
525<p>More GOALs are available in the <b>1.4.0</b> release:</p>
526
527<ul>
528 <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li>
529</ul>
530
531
532<ul>
533 <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br>
534configuration options:
535 <ul>
536 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
537 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
538 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
539 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
540 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
541 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
542 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
543 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
544 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
545 </ul>
546 </li>
547</ul>
548
549
550<ul>
551 <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br>
552configuration options:
553 <ul>
554 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
555 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
556 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
557 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
558 </ul>
559 </li>
560</ul>
561
562
563<ul>
564 <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br>
565configuration options:
566 <ul>
567 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li>
568 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
569 <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li>
570 <li><em><tt>url</tt></em> remote repository transport URL, like
571<div class="preformatted"><div class="preformattedContent">
572<pre>scpexe://host/path/to/obr
573</pre>
574</div></div></li>
575 <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like
576<div class="preformatted"><div class="preformattedContent">
577<pre>http://www.foo.org/bundles/foo.jar
578</pre>
579</div></div></li>
580 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
581 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
582 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
583 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
584 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
585 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
586 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
587 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
588 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
589 </ul>
590 </li>
591</ul>
592
593
594<ul>
595 <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br>
596configuration options:
597 <ul>
598 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
599 </ul>
600 </li>
601</ul>
602
603
Stuart McCulloch93de6492007-12-16 15:59:05 +0000604<p>There are also new instructions available from the underlying BND
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000605tool, 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 +0000606
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000607<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 +0000608
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000609<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 +0000610
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000611<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000612
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000613<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 +0000614
615<div class="code"><div class="codeContent">
616<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>dependencies<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
617</div></div>
618
619<p>where:</p>
620
621<div class="preformatted"><div class="preformattedContent">
622<pre>dependencies ::= clause ( ',' clause ) *
623clause ::= MATCH ( ';' attr '=' MATCH | ';inline=true' )
624attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier'
625MATCH ::= &lt;globbed regular expressions&gt;
626</pre>
627</div></div>
628
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000629<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>
630clauses, which are then appended to the current set of instructions and
631passed onto BND. If you want the embedded dependencies to be at the
632start 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 +0000633
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000634<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>
635
Stuart McCulloch93de6492007-12-16 15:59:05 +0000636<p>some examples:</p>
637
638<div class="code"><div class="codeContent">
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000639<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies --&gt;</span></span>
640<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 +0000641
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000642<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 +0000643<span class="code-tag">&lt;Embed-Dependency&gt;</span>junit;scope=test<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
644
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000645<span class="code-tag"><span class="code-comment">&lt;!-- inline all dependencies, except those with scope test --&gt;</span></span>
646<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=!test;inline=true<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
647
648<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>
649<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 +0000650</div></div>
651
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000652<p>examples of using {<tt>maven-dependencies</tt>}:</p>
653
654<div class="code"><div class="codeContent">
655<pre class="code-xml"><span class="code-tag">&lt;Include-Resource&gt;</span>
656 {maven-resources}, {maven-dependencies},
657 org/foo/Example.class=target/classes/org/foo/Example.class
658<span class="code-tag">&lt;/Include-Resource&gt;</span>
659
660<span class="code-tag">&lt;Bundle-ClassPath&gt;</span>.,{maven-dependencies},some.jar<span class="code-tag">&lt;/Bundle-ClassPath&gt;</span></pre>
661</div></div>
662
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000663<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 +0000664
665<ul>
666 <li><tt>&lt;Embed-StripVersion&gt;true&lt;/Embed-StripVersion&gt;</tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li>
667 <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>
668 <li><tt>&lt;Embed-Directory&gt;directory&lt;/Embed-Directory&gt;</tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li>
669</ul>
670
671
672<p>Normally the plugin only checks direct dependencies, but this can be
673changed to include the complete set of transitive dependencies with the
674following option:</p>
675
676<div class="code"><div class="codeContent">
677<pre class="code-xml"><span class="code-tag">&lt;Embed-Transitive&gt;</span>true<span class="code-tag">&lt;/Embed-Transitive&gt;</span></pre>
678</div></div>
679
680<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>
681
682<div class="code"><div class="codeContent">
683<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>
684</div></div>
685
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000686<h3><a name="ApacheFelixMavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000687
688<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>
689instructions will result in classes being inlined in the bundle, even
690though they also exist inside the embedded jar. If you want to export
691packages from an embedded dependency without such duplication then you
692can either inline the dependency, or use a new BND instruction called <tt>&lt;_exportcontents&gt;</tt>.</p>
693
694<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 +0000695
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000696<h2><a name="ApacheFelixMavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000697
698<p>The latest Maven Bundle Plugin automatically updates the local OBR
699repository.xml file during the install phase, using a default location
700of:</p>
701
702<div class="code"><div class="codeContent">
703<pre class="code-java">&lt;LOCAL-MAVEN-REPOSITORY&gt;/repository.xml</pre>
704</div></div>
705
706<p>You can configure the location of the OBR repository by using the command line:</p>
707
708<div class="code"><div class="codeContent">
709<pre class="code-java">mvn clean install -DobrRepository=&lt;PATH_TO_OBR&gt;</pre>
710</div></div>
711
712<p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p>
713
714<div class="code"><div class="codeContent">
715<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
716<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
717<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
718<span class="code-tag">&lt;configuration&gt;</span>
719 <span class="code-tag">&lt;obrRepository&gt;</span>PATH_TO_OBR<span class="code-tag">&lt;/obrRepository&gt;</span>
720 <span class="code-tag">&lt;instructions&gt;</span>
721 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
722 <span class="code-tag">&lt;/instructions&gt;</span>
723<span class="code-tag">&lt;/configuration&gt;</span></pre>
724</div></div>
725
726<p>to disable OBR installation set the obrRepository to NONE, for example:</p>
727
728<div class="code"><div class="codeContent">
729<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
730<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
731<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
732<span class="code-tag">&lt;configuration&gt;</span>
733 <span class="code-tag">&lt;obrRepository&gt;</span>NONE<span class="code-tag">&lt;/obrRepository&gt;</span>
734 <span class="code-tag">&lt;instructions&gt;</span>
735 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
736 <span class="code-tag">&lt;/instructions&gt;</span>
737<span class="code-tag">&lt;/configuration&gt;</span></pre>
738</div></div>
739
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000740<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000741
742<p>It is possible to configure the Maven Bundle Plugin to put the
743bundle manifest where Eclipse/PDE expects it, and use the Maven
744Dependency Plugin to arrange for any embedded dependencies to appear in
745a local directory that matches the Bundle-ClassPath entries. Here is an
746example POM that does this:</p>
747
748<div class="preformatted"><div class="preformattedContent">
749<pre>&lt;project&gt;
750
751 &lt;properties&gt;
752 &lt;bundle.symbolicName&gt;org.example&lt;/bundle.symbolicName&gt;
753 &lt;bundle.namespace&gt;org.example&lt;/bundle.namespace&gt;
754 &lt;/properties&gt;
755
756 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
757 &lt;groupId&gt;examples&lt;/groupId&gt;
758 &lt;artifactId&gt;org.example&lt;/artifactId&gt;
759 &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
760
761 &lt;name&gt;${bundle.symbolicName} [${bundle.namespace}]&lt;/name&gt;
762
763 &lt;packaging&gt;bundle&lt;/packaging&gt;
764
765 &lt;build&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000766 &lt;resources&gt;
767 &lt;resource&gt;
768 &lt;directory&gt;src/main/resources&lt;/directory&gt;
769 &lt;/resource&gt;
770 &lt;resource&gt;
771 &lt;directory&gt;.&lt;/directory&gt;
772 &lt;includes&gt;
773 &lt;include&gt;plugin.xml&lt;/include&gt;
774 &lt;/includes&gt;
775 &lt;/resource&gt;
776 &lt;/resources&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000777 &lt;plugins&gt;
778 &lt;plugin&gt;
779 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
780 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000781 &lt;version&gt;1.2.1&lt;/version&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000782 &lt;extensions&gt;true&lt;/extensions&gt;
783 &lt;!--
784 the following instructions build a simple set of public/private classes into an OSGi bundle
785 --&gt;
786 &lt;configuration&gt;
787 &lt;manifestLocation&gt;META-INF&lt;/manifestLocation&gt;
788 &lt;instructions&gt;
789 &lt;Bundle-SymbolicName&gt;${bundle.symbolicName}&lt;/Bundle-SymbolicName&gt;
790 &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
791 &lt;!--
792 assume public classes are in the top package, and private classes are under ".internal"
793 --&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000794 &lt;Export-Package&gt;!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"&lt;/Export-Package&gt;
795 &lt;Private-Package&gt;${bundle.namespace}.internal.*&lt;/Private-Package&gt;
796 &lt;Bundle-Activator&gt;${bundle.namespace}.internal.ExampleActivator&lt;/Bundle-Activator&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000797 &lt;!--
798 embed compile/runtime dependencies using path that matches the copied dependency folder
799 --&gt;
800 &lt;Embed-Dependency&gt;*;scope=compile|runtime;inline=false&lt;/Embed-Dependency&gt;
801 &lt;Embed-Directory&gt;target/dependency&lt;/Embed-Directory&gt;
802 &lt;Embed-StripGroup&gt;true&lt;/Embed-StripGroup&gt;
803 &lt;/instructions&gt;
804 &lt;/configuration&gt;
805 &lt;/plugin&gt;
806 &lt;plugin&gt;
807 &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
808 &lt;executions&gt;
809 &lt;execution&gt;
810 &lt;id&gt;copy-dependencies&lt;/id&gt;
811 &lt;phase&gt;package&lt;/phase&gt;
812 &lt;goals&gt;
813 &lt;goal&gt;copy-dependencies&lt;/goal&gt;
814 &lt;/goals&gt;
815 &lt;/execution&gt;
816 &lt;/executions&gt;
817 &lt;/plugin&gt;
818 &lt;/plugins&gt;
819 &lt;/build&gt;
820
821 &lt;dependencies&gt;
822 &lt;dependency&gt;
823 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
824 &lt;artifactId&gt;osgi_R4_core&lt;/artifactId&gt;
825 &lt;version&gt;1.0&lt;/version&gt;
826 &lt;scope&gt;provided&lt;/scope&gt;
827 &lt;optional&gt;true&lt;/optional&gt;
828 &lt;/dependency&gt;
829 &lt;dependency&gt;
830 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
831 &lt;artifactId&gt;osgi_R4_compendium&lt;/artifactId&gt;
832 &lt;version&gt;1.0&lt;/version&gt;
833 &lt;scope&gt;provided&lt;/scope&gt;
834 &lt;optional&gt;true&lt;/optional&gt;
835 &lt;/dependency&gt;
836 &lt;dependency&gt;
837 &lt;groupId&gt;junit&lt;/groupId&gt;
838 &lt;artifactId&gt;junit&lt;/artifactId&gt;
839 &lt;version&gt;3.8.1&lt;/version&gt;
840 &lt;scope&gt;compile&lt;/scope&gt;
841 &lt;optional&gt;true&lt;/optional&gt;
842 &lt;/dependency&gt;
843 &lt;/dependencies&gt;
844
845&lt;/project&gt;
846</pre>
847</div></div>
848
849<p>To generate the Eclipse metadata use:</p>
850
851<div class="code"><div class="codeContent">
852<pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre>
853</div></div>
854
855<p>and you should now be able to import this as an existing Eclipse project.</p>
856
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000857<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 +0000858
859<p>With the original Pax-Construct generated POM you would simply use:</p>
860
861<div class="code"><div class="codeContent">
862<pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre>
863</div></div>
864
865<p>to create the appropriate Eclipse files and manifest, and also
866handle any embedded entries. The pax:eclipse goal extends
867eclipse:eclipse, and supports the same parameters.</p>
868
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000869<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000870
871<p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>,
872for example when you embed the classes from another jar. This can
873sometimes cause unforeseen problems in Maven, as it will use the output
874directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p>
875
876<p>The easiest way to get around this Maven 'feature' is to unpack the
877contents of the bundle to the output directory after the packaging
878step, so the additional classes will be found where Maven expects them.
879Thankfully there is now an easy option to do this in the bundle-plugin:</p>
880
881<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000882<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
883<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
884<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
885<span class="code-tag">&lt;configuration&gt;</span>
886 <span class="code-tag">&lt;unpackBundle&gt;</span>true<span class="code-tag">&lt;/unpackBundle&gt;</span>
887 <span class="code-tag">&lt;instructions&gt;</span>
888 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
889 <span class="code-tag">&lt;/instructions&gt;</span>
890<span class="code-tag">&lt;/configuration&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000891</div></div>
892
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000893<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000894
895<p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p>
896
897<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000898<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>
899<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 +0000900</div></div>
901
902<p>Bnd will use it when calculating the bundle contents, and will also
903copy across all manifest attributes starting with a capital letter.<br>
904As shown in the above example, you could use this to include a non-OSGi
905manifest which you then customize with extra OSGi attributes.</p>
906
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000907<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 +0000908
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000909<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000910
911<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>
912
913<p>The customized Ant script uses the BND tool to rebuild the bundle,
914so any source changes should be reflected in the (re)generated manifest.</p>
915
916<p>Example:</p>
917<div class="preformatted"><div class="preformattedContent">
918<pre>mvn ant:ant bundle:ant
919
920ant clean package
921</pre>
922</div></div>
923
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000924<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000925
926<p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p>
927
928<p>configuration:</p>
929<ul>
930 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
931 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
932 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
933 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
934 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
935 <li><em>classifier</em> Maven classifier type, defaults to none</li>
936 <li><em>pomFile</em> optional Pom file describing the bundle</li>
937 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
938 <li><em>obrXml</em> optional additional properties for the bundle</li>
939</ul>
940
941
942<p>Example:</p>
943<div class="preformatted"><div class="preformattedContent">
944<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \
945 -DpomFile=myPom.xml -Dfile=foo-1.0.jar
946</pre>
947</div></div>
948
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000949<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000950
951<p>The <b>deploy goal</b> updates the remote OBR with the details of
952the deployed bundle from the local Maven repository. The remote OBR is
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000953found 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 +0000954
955<p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p>
956
957<p>configuration:</p>
958<ul>
959 <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
960 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
961 <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li>
962 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
963</ul>
964
965
966<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>
967
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000968<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000969
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000970<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 +0000971
972<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>
973
974<p>configuration:</p>
975<ul>
976 <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li>
977 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
978 <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li>
979 <li><em>url</em> remote repository transport URL, like
980<div class="preformatted"><div class="preformattedContent">
981<pre>scpexe://host/path/to/obr
982</pre>
983</div></div></li>
984 <li><em>bundleUrl</em> public URL of deployed bundle, like
985<div class="preformatted"><div class="preformattedContent">
986<pre>http://www.foo.org/bundles/foo.jar
987</pre>
988</div></div></li>
989 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
990 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
991 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
992 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
993 <li><em>classifier</em> Maven classifier type, defaults to none</li>
994 <li><em>pomFile</em> optional Pom file describing the bundle</li>
995 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
996 <li><em>obrXml</em> optional additional properties for the bundle</li>
997 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
998</ul>
999
1000
1001<p>Example:</p>
1002<div class="preformatted"><div class="preformattedContent">
1003<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \
1004 -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \
1005 -DbundleUrl=http://www.foo.org/bundles/foo.jar
1006</pre>
1007</div></div>
1008
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001009<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001010
1011<p>Sometimes you would like to clean your local OBR because it contains
1012bundles that are no longer in your local Maven repository. This case
1013often occurs when artifacts were deleted manually. The
1014maven-bundle-plugin provides a simple goal to check for missing
1015bundles, and remove them from the local OBR.</p>
1016
1017<p>configuration:</p>
1018<ul>
1019 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1020</ul>
1021
1022
1023<p>Example:</p>
1024<div class="preformatted"><div class="preformattedContent">
1025<pre>mvn bundle:clean
1026</pre>
1027</div></div>
1028
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001029<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001030
1031<p>With a remote OBR, several uploads may occur at the same time.
1032However, the remote OBR is centralized in one file, so concurrent
1033modification must be avoided. To achieve this, the plug-in implements a
1034locking system. Each time the plug-in tries to modify the file it sets
1035a file based lock. If it can't take the lock, it will wait and retry.
1036After 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>
1037
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001038<h2><a name="ApacheFelixMavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001039
1040<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>
1041<div class="code"><div class="codeContent">
1042<pre class="code-xml"><span class="code-tag">&lt;build&gt;</span>
1043 <span class="code-tag">&lt;extensions&gt;</span>
1044 <span class="code-tag">&lt;extension&gt;</span>
1045 <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.wagon<span class="code-tag">&lt;/groupId&gt;</span>
1046 <span class="code-tag">&lt;artifactId&gt;</span>wagon-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
1047 <span class="code-tag">&lt;version&gt;</span>1.0-alpha-6<span class="code-tag">&lt;/version&gt;</span>
1048 <span class="code-tag">&lt;/extension&gt;</span>
1049 <span class="code-tag">&lt;/extensions&gt;</span>
1050<span class="code-tag">&lt;/build&gt;</span></pre>
1051</div></div>
1052
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001053<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 +00001054
1055<p>The description of the bundle comes from three different sources:</p>
1056<ul>
1057 <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li>
1058 <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li>
1059 <li>obr.xml : this file contains customized description and capabilities for the bundle</li>
1060</ul>
1061
1062
1063<p>These sources are merged together using the following precedence:</p>
1064<div class="preformatted"><div class="preformattedContent">
1065<pre>Bindex
1066| (overrides)
1067pom.xml
1068| (overrides)
1069obr.xml
1070</pre>
1071</div></div>
1072<p>A warning message is displayed when existing information is overridden.</p>
1073
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001074<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Knownissues&amp;limitations"></a>Known issues &amp; limitations</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001075
1076<ol>
1077 <li>obr.xml (file given by the user to add properties not found
1078by Bindex) must be correct, because the plug-in does not check its
1079syntax.</li>
1080</ol>
1081
1082
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001083<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Feedback"></a>Feedback</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +00001084
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001085<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 +00001086 </div>
Stuart McCulloch981bd342008-05-03 12:49:39 +00001087 </body></html>