blob: 8746ffee376900c0a70a5b8ed0bc4709317b8a13 [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 McCullochb4212cc2008-08-05 06:36:05 +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" width="7" height="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>
Stuart McCullochb4212cc2008-08-05 06:36:05 +000019 <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" width="7" height="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" width="7" height="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" width="7" height="7"></sup></a></span>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000022<!-- ApacheCon Ad -->
Stuart McCullochb4212cc2008-08-05 06:36:05 +000023<iframe src="apache-felix-maven-bundle-plugin-bnd_files/button.html" style="border-width: 0pt; float: left; display: none;" scrolling="no" width="135" frameborder="0" height="135"></iframe>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000024<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 McCullochb4212cc2008-08-05 06:36:05 +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" width="7" height="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 McCullochb4212cc2008-08-05 06:36:05 +000039<p><em>NOTE: only compile, runtime and system scoped dependencies are passed to BND. Provided and test dependencies are <b>not</b> included in the classpath seen by BND.</em></p>
40
Stuart McCulloch0340ae42008-02-22 11:27:18 +000041<p>Since the 1.4.0 release, this plugin also aims to automate OBR (OSGi
42Bundle Repository) management. It helps manage a local OBR for your
43local Maven repository, and also supports remote OBRs for bundle
44distribution. The plug-in automatically computes bundle capabilities
45and requirements, using a combination of Bindex and Maven metadata.</p>
46
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000047<p><a name="ApacheFelixMavenBundlePlugin(BND)-simpleexample"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +000048
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000049<h1><a name="ApacheFelixMavenBundlePlugin(BND)-SimpleExample"></a>Simple Example</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000050
51<p>Rather than going straight to a detailed list of plugin features, we
52will first look at a simple example of how to use the plugin to give an
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000053immediate 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 +000054
55<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 +000056
Karl Paulsf87ac142007-07-06 22:36:17 +000057<div class="preformatted"><div class="preformattedContent">
58<pre>org.foo.myproject.api
59org.foo.myproject.impl1
60org.foo.myproject.impl2
61...
62</pre>
63</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000064
Karl Paulsf87ac142007-07-06 22:36:17 +000065<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 +000066
Karl Paulsf87ac142007-07-06 22:36:17 +000067<div class="preformatted"><div class="preformattedContent">
68<pre>...
69&lt;plugins&gt;
70 &lt;plugin&gt;
71 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
72 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
73 &lt;extensions&gt;true&lt;/extensions&gt;
74 &lt;configuration&gt;
75 &lt;instructions&gt;
76 &lt;Export-Package&gt;org.foo.myproject.api&lt;/Export-Package&gt;
77 &lt;Private-Package&gt;org.foo.myproject.*&lt;/Private-Package&gt;
78 &lt;Bundle-Activator&gt;org.foo.myproject.impl1.Activator&lt;/Bundle-Activator&gt;
79 &lt;/instructions&gt;
80 &lt;/configuration&gt;
81 &lt;/plugin&gt;
82&lt;/plugins&gt;
83...
84</pre>
85</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +000086
Karl Paulsf87ac142007-07-06 22:36:17 +000087<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>
88export. If the two sets overlap, as they do in the case, then the
89export takes precedence. Since we did not specify any values for any
90other bundle manifest headers, they will assume default values which
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000091are 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 +000092bundle manifest header based on the contents of the bundle, which means
93that you generally do not ever need to explicitly specify it yourself.
94That's it.</p>
95
Stuart McCullochdd89cdb2008-05-03 08:13:09 +000096<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Features"></a>Features</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +000097
98<p>The BND library underlying the plugin defines instructions to direct
99its behavior. For this Maven plugin, these instructions are issued in
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000100the 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 +0000101
Karl Paulsf87ac142007-07-06 22:36:17 +0000102<ol>
103 <li><em>Manifest headers</em> - Any instruction that starts with
104a capital letter will appear in the resulting bundle's manifest file;
105the value for the header will either be copied, augmented, or generated
106by BND depending on the instruction.</li>
107 <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>
108 <li><em>Directives</em>
109- Any instruction starting with a '-' character is considered to be a
110directive that informs BND to perform some special processing and is
111not copied to the manifest.</li>
112</ol>
113
114
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000115<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" width="7" height="7"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000116
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000117<p><a name="ApacheFelixMavenBundlePlugin(BND)-instructions"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000118
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000119<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Instructions"></a>Instructions</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000120
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000121<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ExportPackage&gt;}}"></a><tt>&lt;Export-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000122
123<p>The <tt>&lt;Export-Package&gt;</tt> instruction is a list of
124packages for the bundle to export. These packages are copied into the
125resulting bundle JAR file from the available classes (i.e., project
126classes, dependencies, and class path); thus, it is possible to include
127classes into your bundle that are not associated with source files in
128your project. <tt>&lt;Export-Package&gt;</tt> can be specified with
129package patterns using the '*' wildcard. Also, it is possible to
130exclude packages using negation by starting the package pattern with
131'!'. Thus, non-negated patterns indicate which of the available
132packages to include in the bundle, whereas negated patterns indicate
133which should not be included in the bundle.</p>
134
135<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>
136
137<p>Following standard OSGi R4 syntax, package patterns can include both
138directives and attributes, which will be copied appropriately into the
139generated Export-Package manifest header. Besides explicitly listing
140package version attributes, BND will also determine package versions by
141examining the source JAR file or from <tt>packageinfo</tt> files in the package directory.</p>
142
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000143<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;PrivatePackage&gt;}}"></a><tt>&lt;Private-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000144
145<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>
146be exported by the bundle. If a package is selected by both the export
147and private package headers, then the export takes precedence.</p>
148
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000149<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;IncludeResource&gt;}}"></a><tt>&lt;Include-Resource&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000150
151<p>The <tt>&lt;Include-Resource&gt;</tt> instruction is a list of
152arbitrary resources that should be copied into the bundle JAR file. The
153specified resources are declared as clauses that can have the following
154forms:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000155
Karl Paulsf87ac142007-07-06 22:36:17 +0000156<div class="preformatted"><div class="preformattedContent">
157<pre>clause ::= assignment | inline | simple
158assignment ::= PATH '=' PATH
159simple ::= PATH
160inline ::= '@' PATH
161</pre>
162</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000163
Karl Paulsf87ac142007-07-06 22:36:17 +0000164<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>
165form will place the resource in the bundle JAR with only the file name,
166i.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>
167points to a directory, the entire directory hierarchy is copied into
168the resulting bundle JAR file relative to the specified directory. If a
169specific resource must be placed into a subdirectory of the bundle jar,
170then use the <tt>assignment</tt> form, where the first path is the the
171destination path (including file name if the resource is a file) and
172the 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>
173
174<p>If a resource clause is specified inside of "{ ... }" brackets, then
175variable substitution will be performed on the resource, where
176variables in the resources are denoted with "${ ... }" syntax.</p>
177
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000178<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>
179
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000180<h3><a name="ApacheFelixMavenBundlePlugin(BND)-{{&lt;ImportPackage&gt;}}"></a><tt>&lt;Import-Package&gt;</tt></h3>
Karl Paulsf87ac142007-07-06 22:36:17 +0000181
182<p>The <tt>&lt;Import-Package&gt;</tt> instruction is a list of
183packages that are required by the bundle's contained packages. The
184default for this header is "*", resulting in importing all referred
185packages. This header rarely has to be explicitly specified. However,
186in certain cases when there is an unwanted import, such an import can
187be removed by using a negation package pattern. The package patterns
188work 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>
189
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000190<p><a name="ApacheFelixMavenBundlePlugin(BND)-defaultbehavior"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000191
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000192<h2><a name="ApacheFelixMavenBundlePlugin(BND)-DefaultBehavior"></a>Default Behavior</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000193
194<p>To use this plugin, very little information is required by BND. As
195part of the Maven integration, the plugin tries to set reasonable
196defaults for various instructions. For example:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000197
Karl Paulsf87ac142007-07-06 22:36:17 +0000198<ul>
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000199 <li><tt>&lt;Bundle-SymbolicName&gt;</tt> is computed using the shared <span class="nobr"><a href="http://svn.apache.org/repos/asf/maven/shared/trunk/maven-osgi/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java" title="Visit page outside Confluence" rel="nofollow">Maven2OsgiConverter<sup><img class="rendericon" src="apache-felix-maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" width="7" height="7"></sup></a></span> component, which uses the following algorithm:<br>
200Get the symbolic name as groupId + "." + artifactId, with the following exceptions:
201 <ul>
202 <li>if
203artifact.getFile is not null and the jar contains a OSGi Manifest with
204Bundle-SymbolicName property then that value is returned</li>
205 <li>if
206groupId has only one section (no dots) and artifact.getFile is not null
207then the first package name with classes is returned. eg.
208commons-logging:commons-logging -&gt; org.apache.commons.logging</li>
209 <li>if artifactId is equal to last section of groupId then groupId is returned. eg. org.apache.maven:maven -&gt; org.apache.maven</li>
210 <li>if
211artifactId starts with last section of groupId that portion is removed.
212eg. org.apache.maven:maven-core -&gt; org.apache.maven.core</li>
213 </ul>
214 </li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000215 <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 +0000216 <li><tt>&lt;Private-Package&gt;</tt> is assumed to be empty by default.</li>
217 <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 +0000218 <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 +0000219which will copy the specified project directory hierarchy into the
220resulting bundle JAR file, mirroring standard Maven behavior.</li>
221 <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>
222 <li><tt>&lt;Bundle-Name&gt;</tt> is assumed to be "<tt>${pom.name</tt>}".</li>
223 <li><tt>&lt;Bundle-Description&gt;</tt> is assumed to be "<tt>${pom.description</tt>}".</li>
224 <li><tt>&lt;Bundle-License&gt;</tt> is assumed to be "<tt>${pom.licenses</tt>}".</li>
225 <li><tt>&lt;Bundle-Vendor&gt;</tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li>
226 <li><tt>&lt;Bundle-DocURL&gt;</tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li>
227</ul>
228
229
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000230<p>Since the plugin creates bundles for OSGi R4, it hard-codes <tt>Bundle-ManifestVersion</tt>
Karl Paulsf87ac142007-07-06 22:36:17 +0000231to be '2'. Additionally, it generates imports for every export to
232ensure package substitutability, which is very important when working
233with collaborating services. It is possible to override any of these
234values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p>
235
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000236<p><a name="ApacheFelixMavenBundlePlugin(BND)-howto"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000237
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000238<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Detailed&quot;HowTo&quot;"></a>Detailed "How To"</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +0000239
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000240<h2><a name="ApacheFelixMavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000241
242<p>The first step in the process of using the plugin is downloading and
243installing the latest version of the Maven2 runtime. The latest Maven2
244release and instuctions for getting started with Maven2 can be found at
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000245the <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" width="7" height="7"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000246
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000247<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000248
249<p>To use the maven-bundle-plugin, you first need to add the plugin and
250some appropriate plugin configuration to your bundle project's POM.
251Below is an example of a simple OSGi bundle POM for Maven2:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000252
Karl Paulsf87ac142007-07-06 22:36:17 +0000253<div class="preformatted"><div class="preformattedContent">
254<pre>&lt;project&gt;
255 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
256 &lt;groupId&gt;my-osgi-bundles&lt;/groupId&gt;
257 &lt;artifactId&gt;examplebundle&lt;/artifactId&gt;
258 &lt;packaging&gt;bundle&lt;/packaging&gt; &lt;!-- (1) --&gt;
259 &lt;version&gt;1.0&lt;/version&gt;
260 &lt;name&gt;Example Bundle&lt;/name&gt;
261 &lt;dependencies&gt;
262 &lt;dependency&gt;
263 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
264 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000265 &lt;version&gt;1.0.0&lt;/version&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000266 &lt;/dependency&gt;
267 &lt;/dependencies&gt;
268 &lt;build&gt;
269 &lt;plugins&gt;
270 &lt;plugin&gt; &lt;!-- (2) START --&gt;
271 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
272 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000273
Karl Paulsf87ac142007-07-06 22:36:17 +0000274 &lt;extensions&gt;true&lt;/extensions&gt;
275 &lt;configuration&gt;
276 &lt;instructions&gt;
277 &lt;Export-Package&gt;com.my.company.api&lt;/Export-Package&gt;
278 &lt;Private-Package&gt;com.my.company.*&lt;/Private-Package&gt;
279 &lt;Bundle-Activator&gt;com.my.company.Activator&lt;/Bundle-Activator&gt;
280 &lt;/instructions&gt;
281 &lt;/configuration&gt;
282 &lt;/plugin&gt; &lt;!-- (2) END --&gt;
283 &lt;/plugins&gt;
284 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000285&lt;/project&gt;
286</pre>
287</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000288
289<p>There are two main things to note: (1) the <tt>&lt;packaging&gt;</tt>
290specifier must be "bundle" and (2) the plugin and configuration must be
Karl Paulsf87ac142007-07-06 22:36:17 +0000291specified (the configuration section is where you will issue
Stuart McCulloch93de6492007-12-16 15:59:05 +0000292instructions to the plugin).</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000293
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000294<h2><a name="ApacheFelixMavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000295
296<p>Consider this more real-world example using Felix' Log Service
297implementation. The Log Service project is comprised of a single
298package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on
299the core OSGi interfaces as well as a dependency on the compendium OSGi
300interfaces for the specific log service interfaces. The following is
301its POM file:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000302
Karl Paulsf87ac142007-07-06 22:36:17 +0000303<div class="preformatted"><div class="preformattedContent">
304<pre>&lt;project&gt;
305 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
306 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
307 &lt;artifactId&gt;org.apache.felix.log&lt;/artifactId&gt;
308 &lt;packaging&gt;bundle&lt;/packaging&gt;
309 &lt;name&gt;Apache Felix Log Service&lt;/name&gt;
310 &lt;version&gt;0.8.0-SNAPSHOT&lt;/version&gt;
311 &lt;description&gt;
312 This bundle provides an implementation of the OSGi R4 Log service.
313 &lt;/description&gt;
314 &lt;dependencies&gt;
315 &lt;dependency&gt;
316 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
317 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
318 &lt;version&gt;0.8.0-incubator&lt;/version&gt;
319 &lt;/dependency&gt;
320 &lt;dependency&gt;
321 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
322 &lt;artifactId&gt;org.osgi.compendium&lt;/artifactId&gt;
323 &lt;version&gt;0.9.0-incubator-SNAPSHOT&lt;/version&gt;
324 &lt;/dependency&gt;
325 &lt;/dependencies&gt;
326 &lt;build&gt;
327 &lt;plugins&gt;
328 &lt;plugin&gt;
329 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
330 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
331 &lt;extensions&gt;true&lt;/extensions&gt;
332 &lt;configuration&gt;
333 &lt;instructions&gt;
334 &lt;Export-Package&gt;org.osgi.service.log&lt;/Export-Package&gt;
335 &lt;Private-Package&gt;org.apache.felix.log.impl&lt;/Private-Package&gt;
336 &lt;Bundle-SymbolicName&gt;${pom.artifactId}&lt;/Bundle-SymbolicName&gt;
337 &lt;Bundle-Activator&gt;${pom.artifactId}.impl.Activator&lt;/Bundle-Activator&gt;
338 &lt;Export-Service&gt;org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService&lt;/Export-Service&gt;
339 &lt;/instructions&gt;
340 &lt;/configuration&gt;
341 &lt;/plugin&gt;
342 &lt;/plugins&gt;
343 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000344&lt;/project&gt;
345</pre>
346</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000347
Karl Paulsf87ac142007-07-06 22:36:17 +0000348<p>Notice that the <tt>&lt;Export-Package&gt;</tt> instruction
349specifies that the bundle exports the Log Service package, even though
350this package is not contained in the bundle project. By declaring this,
351the plugin will copy the Log Service package into the resulting bundle
352JAR file. This is useful in this case because now the bundle can
353resolve without having to download the entire compendium bundle. The
354resulting manifest for the Log Service bundle looks like this (notice
355how the imports/exports automatically have version information
356associated with them, which was obtained from packageinfo files in the
357source packages):</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000358
Karl Paulsf87ac142007-07-06 22:36:17 +0000359<div class="preformatted"><div class="preformattedContent">
360<pre>Manifest-Version: 1
361Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
362Bundle-Activator: org.apache.felix.log.impl.Activator
363Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v
364 ersion=1.3
365Include-Resource: src/main/resources
366Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version=
367 1.3
368Bundle-Version: 0.8.0.SNAPSHOT
369Bundle-Name: Apache Felix Log Service
370Bundle-Description: This bundle provides an implementation of the OSGi
371 R4 Log service.
372Private-Package: org.apache.felix.log.impl
373Bundle-ManifestVersion: 2
374Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L
375 ogReaderService
376Bundle-SymbolicName: org.apache.felix.log
377</pre>
378</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000379
Karl Paulsf87ac142007-07-06 22:36:17 +0000380<p>The resulting bundle JAR file has the following content (notice how
381the 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 +0000382
Karl Paulsf87ac142007-07-06 22:36:17 +0000383<div class="preformatted"><div class="preformattedContent">
384<pre>META-INF/MANIFEST.MF
385LICENSE
386META-INF/
387META-INF/maven/
388META-INF/maven/org.apache.felix/
389META-INF/maven/org.apache.felix/org.apache.felix.log/
390META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties
391META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml
392NOTICE
393org/
394org/apache/
395org/apache/felix/
396org/apache/felix/log/
397org/apache/felix/log/impl/
398org/apache/felix/log/impl/Activator.class
399org/apache/felix/log/impl/Log.class
400org/apache/felix/log/impl/LogEntryImpl.class
401org/apache/felix/log/impl/LogException.class
402org/apache/felix/log/impl/LogListenerThread.class
403org/apache/felix/log/impl/LogNode.class
404org/apache/felix/log/impl/LogNodeEnumeration.class
405org/apache/felix/log/impl/LogReaderServiceFactory.class
406org/apache/felix/log/impl/LogReaderServiceImpl.class
407org/apache/felix/log/impl/LogServiceFactory.class
408org/apache/felix/log/impl/LogServiceImpl.class
409org/osgi/
410org/osgi/service/
411org/osgi/service/log/
412org/osgi/service/log/LogEntry.class
413org/osgi/service/log/LogListener.class
414org/osgi/service/log/LogReaderService.class
415org/osgi/service/log/LogService.class
416org/osgi/service/log/package.html
417org/osgi/service/log/packageinfo
418</pre>
419</div></div>
420
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000421<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 +0000422
423<p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br>
424you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br>
425add this manifest to the final artifact. For example:</p>
426
427<div class="code"><div class="codeContent">
428<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
429 <span class="code-tag">&lt;artifactId&gt;</span>maven-jar-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
430 <span class="code-tag">&lt;configuration&gt;</span>
431 <span class="code-tag">&lt;archive&gt;</span>
432 <span class="code-tag">&lt;manifestFile&gt;</span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag">&lt;/manifestFile&gt;</span>
433 <span class="code-tag">&lt;/archive&gt;</span>
434 <span class="code-tag">&lt;/configuration&gt;</span>
435<span class="code-tag">&lt;/plugin&gt;</span>
436<span class="code-tag">&lt;plugin&gt;</span>
437 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
438 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
439 <span class="code-tag">&lt;executions&gt;</span>
440 <span class="code-tag">&lt;execution&gt;</span>
441 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
442 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
443 <span class="code-tag">&lt;goals&gt;</span>
444 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
445 <span class="code-tag">&lt;/goals&gt;</span>
446 <span class="code-tag">&lt;/execution&gt;</span>
447 <span class="code-tag">&lt;/executions&gt;</span>
448<span class="code-tag">&lt;/plugin&gt;</span></pre>
449</div></div>
450
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000451<h2><a name="ApacheFelixMavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000452
Stuart McCulloch93de6492007-12-16 15:59:05 +0000453<p>The plugin is hosted at the Apache Felix project. The following
454steps describe how to build and install the plugin into your local
455Maven2 repository.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000456
457<p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000458
Karl Paulsf87ac142007-07-06 22:36:17 +0000459<div class="preformatted"><div class="preformattedContent">
Stuart McCulloch93de6492007-12-16 15:59:05 +0000460<pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin
Karl Paulsf87ac142007-07-06 22:36:17 +0000461</pre>
462</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000463
Karl Paulsf87ac142007-07-06 22:36:17 +0000464<p>Using Maven2, build and install the maven-bundle-plugin by issuing
465the following Maven2 command in the project directory that was created
466as a result of the previous step.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000467
Karl Paulsf87ac142007-07-06 22:36:17 +0000468<div class="preformatted"><div class="preformattedContent">
469<pre>$ mvn install
470</pre>
471</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000472
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000473<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Goals"></a>Goals</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000474
475<p>The maven-bundle-plugin also provides additional functionality via
476some Maven goals. Command-line execution of a goal is performed as
477follows:</p>
478
479<div class="preformatted"><div class="preformattedContent">
480<pre>mvn org.apache.felix:maven-bundle-plugin:GOAL
481</pre>
482</div></div>
483
484<p>Where GOAL is one of the following:</p>
485
486<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000487 <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000488configuration options:
489 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000490 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
491 <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000492 <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 +0000493 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000494 <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000495 </ul>
496 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000497</ul>
498
499
500<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000501 <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000502configuration options:
503 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000504 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000505 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000506 </ul>
507 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000508</ul>
509
510
511<ul>
512 <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000513configuration options:
514 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000515 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000516 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000517 </ul>
518 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000519</ul>
520
521
522<ul>
523 <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000524configuration options:
525 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000526 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
527 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000528 </ul>
529 </li>
530</ul>
531
532
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000533<ul>
534 <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br>
535configuration options:
536 <ul>
537 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
538 </ul>
539 </li>
540</ul>
541
542
543<p>More GOALs are available in the <b>1.4.0</b> release:</p>
544
545<ul>
546 <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li>
547</ul>
548
549
550<ul>
551 <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br>
552configuration options:
553 <ul>
554 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
555 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
556 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
557 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
558 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
559 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
560 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
561 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
562 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
563 </ul>
564 </li>
565</ul>
566
567
568<ul>
569 <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br>
570configuration options:
571 <ul>
572 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
573 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
574 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
575 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
576 </ul>
577 </li>
578</ul>
579
580
581<ul>
582 <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br>
583configuration options:
584 <ul>
585 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li>
586 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
587 <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li>
588 <li><em><tt>url</tt></em> remote repository transport URL, like
589<div class="preformatted"><div class="preformattedContent">
590<pre>scpexe://host/path/to/obr
591</pre>
592</div></div></li>
593 <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like
594<div class="preformatted"><div class="preformattedContent">
595<pre>http://www.foo.org/bundles/foo.jar
596</pre>
597</div></div></li>
598 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
599 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
600 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
601 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
602 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
603 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
604 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
605 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
606 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
607 </ul>
608 </li>
609</ul>
610
611
612<ul>
613 <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br>
614configuration options:
615 <ul>
616 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
617 </ul>
618 </li>
619</ul>
620
621
Stuart McCulloch93de6492007-12-16 15:59:05 +0000622<p>There are also new instructions available from the underlying BND
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000623tool, 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" width="7" height="7"></sup></a></span>.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000624
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000625<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 +0000626
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000627<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 +0000628
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000629<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000630
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000631<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 +0000632
633<div class="code"><div class="codeContent">
634<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>dependencies<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
635</div></div>
636
637<p>where:</p>
638
639<div class="preformatted"><div class="preformattedContent">
640<pre>dependencies ::= clause ( ',' clause ) *
641clause ::= MATCH ( ';' attr '=' MATCH | ';inline=true' )
642attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier'
643MATCH ::= &lt;globbed regular expressions&gt;
644</pre>
645</div></div>
646
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000647<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>
648clauses, which are then appended to the current set of instructions and
649passed onto BND. If you want the embedded dependencies to be at the
650start 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 +0000651
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000652<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>
653
Stuart McCulloch93de6492007-12-16 15:59:05 +0000654<p>some examples:</p>
655
656<div class="code"><div class="codeContent">
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000657<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies --&gt;</span></span>
658<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 +0000659
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000660<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 +0000661<span class="code-tag">&lt;Embed-Dependency&gt;</span>junit;scope=test<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
662
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000663<span class="code-tag"><span class="code-comment">&lt;!-- inline all dependencies, except those with scope test --&gt;</span></span>
664<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=!test;inline=true<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
665
666<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>
667<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 +0000668</div></div>
669
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000670<p>examples of using {<tt>maven-dependencies</tt>}:</p>
671
672<div class="code"><div class="codeContent">
673<pre class="code-xml"><span class="code-tag">&lt;Include-Resource&gt;</span>
674 {maven-resources}, {maven-dependencies},
675 org/foo/Example.class=target/classes/org/foo/Example.class
676<span class="code-tag">&lt;/Include-Resource&gt;</span>
677
678<span class="code-tag">&lt;Bundle-ClassPath&gt;</span>.,{maven-dependencies},some.jar<span class="code-tag">&lt;/Bundle-ClassPath&gt;</span></pre>
679</div></div>
680
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000681<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 +0000682
683<ul>
684 <li><tt>&lt;Embed-StripVersion&gt;true&lt;/Embed-StripVersion&gt;</tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li>
685 <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>
686 <li><tt>&lt;Embed-Directory&gt;directory&lt;/Embed-Directory&gt;</tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li>
687</ul>
688
689
690<p>Normally the plugin only checks direct dependencies, but this can be
691changed to include the complete set of transitive dependencies with the
692following option:</p>
693
694<div class="code"><div class="codeContent">
695<pre class="code-xml"><span class="code-tag">&lt;Embed-Transitive&gt;</span>true<span class="code-tag">&lt;/Embed-Transitive&gt;</span></pre>
696</div></div>
697
698<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>
699
700<div class="code"><div class="codeContent">
701<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>
702</div></div>
703
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000704<h3><a name="ApacheFelixMavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000705
706<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>
707instructions will result in classes being inlined in the bundle, even
708though they also exist inside the embedded jar. If you want to export
709packages from an embedded dependency without such duplication then you
710can either inline the dependency, or use a new BND instruction called <tt>&lt;_exportcontents&gt;</tt>.</p>
711
712<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 +0000713
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000714<h2><a name="ApacheFelixMavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000715
716<p>The latest Maven Bundle Plugin automatically updates the local OBR
717repository.xml file during the install phase, using a default location
718of:</p>
719
720<div class="code"><div class="codeContent">
721<pre class="code-java">&lt;LOCAL-MAVEN-REPOSITORY&gt;/repository.xml</pre>
722</div></div>
723
724<p>You can configure the location of the OBR repository by using the command line:</p>
725
726<div class="code"><div class="codeContent">
727<pre class="code-java">mvn clean install -DobrRepository=&lt;PATH_TO_OBR&gt;</pre>
728</div></div>
729
730<p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p>
731
732<div class="code"><div class="codeContent">
733<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
734<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
735<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
736<span class="code-tag">&lt;configuration&gt;</span>
737 <span class="code-tag">&lt;obrRepository&gt;</span>PATH_TO_OBR<span class="code-tag">&lt;/obrRepository&gt;</span>
738 <span class="code-tag">&lt;instructions&gt;</span>
739 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
740 <span class="code-tag">&lt;/instructions&gt;</span>
741<span class="code-tag">&lt;/configuration&gt;</span></pre>
742</div></div>
743
744<p>to disable OBR installation set the obrRepository to NONE, for example:</p>
745
746<div class="code"><div class="codeContent">
747<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
748<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
749<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
750<span class="code-tag">&lt;configuration&gt;</span>
751 <span class="code-tag">&lt;obrRepository&gt;</span>NONE<span class="code-tag">&lt;/obrRepository&gt;</span>
752 <span class="code-tag">&lt;instructions&gt;</span>
753 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
754 <span class="code-tag">&lt;/instructions&gt;</span>
755<span class="code-tag">&lt;/configuration&gt;</span></pre>
756</div></div>
757
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000758<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000759
760<p>It is possible to configure the Maven Bundle Plugin to put the
761bundle manifest where Eclipse/PDE expects it, and use the Maven
762Dependency Plugin to arrange for any embedded dependencies to appear in
763a local directory that matches the Bundle-ClassPath entries. Here is an
764example POM that does this:</p>
765
766<div class="preformatted"><div class="preformattedContent">
767<pre>&lt;project&gt;
768
769 &lt;properties&gt;
770 &lt;bundle.symbolicName&gt;org.example&lt;/bundle.symbolicName&gt;
771 &lt;bundle.namespace&gt;org.example&lt;/bundle.namespace&gt;
772 &lt;/properties&gt;
773
774 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
775 &lt;groupId&gt;examples&lt;/groupId&gt;
776 &lt;artifactId&gt;org.example&lt;/artifactId&gt;
777 &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
778
779 &lt;name&gt;${bundle.symbolicName} [${bundle.namespace}]&lt;/name&gt;
780
781 &lt;packaging&gt;bundle&lt;/packaging&gt;
782
783 &lt;build&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000784 &lt;resources&gt;
785 &lt;resource&gt;
786 &lt;directory&gt;src/main/resources&lt;/directory&gt;
787 &lt;/resource&gt;
788 &lt;resource&gt;
789 &lt;directory&gt;.&lt;/directory&gt;
790 &lt;includes&gt;
791 &lt;include&gt;plugin.xml&lt;/include&gt;
792 &lt;/includes&gt;
793 &lt;/resource&gt;
794 &lt;/resources&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000795 &lt;plugins&gt;
796 &lt;plugin&gt;
797 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
798 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000799 &lt;version&gt;1.2.1&lt;/version&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000800 &lt;extensions&gt;true&lt;/extensions&gt;
801 &lt;!--
802 the following instructions build a simple set of public/private classes into an OSGi bundle
803 --&gt;
804 &lt;configuration&gt;
805 &lt;manifestLocation&gt;META-INF&lt;/manifestLocation&gt;
806 &lt;instructions&gt;
807 &lt;Bundle-SymbolicName&gt;${bundle.symbolicName}&lt;/Bundle-SymbolicName&gt;
808 &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
809 &lt;!--
810 assume public classes are in the top package, and private classes are under ".internal"
811 --&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000812 &lt;Export-Package&gt;!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"&lt;/Export-Package&gt;
813 &lt;Private-Package&gt;${bundle.namespace}.internal.*&lt;/Private-Package&gt;
814 &lt;Bundle-Activator&gt;${bundle.namespace}.internal.ExampleActivator&lt;/Bundle-Activator&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000815 &lt;!--
816 embed compile/runtime dependencies using path that matches the copied dependency folder
817 --&gt;
818 &lt;Embed-Dependency&gt;*;scope=compile|runtime;inline=false&lt;/Embed-Dependency&gt;
819 &lt;Embed-Directory&gt;target/dependency&lt;/Embed-Directory&gt;
820 &lt;Embed-StripGroup&gt;true&lt;/Embed-StripGroup&gt;
821 &lt;/instructions&gt;
822 &lt;/configuration&gt;
823 &lt;/plugin&gt;
824 &lt;plugin&gt;
825 &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
826 &lt;executions&gt;
827 &lt;execution&gt;
828 &lt;id&gt;copy-dependencies&lt;/id&gt;
829 &lt;phase&gt;package&lt;/phase&gt;
830 &lt;goals&gt;
831 &lt;goal&gt;copy-dependencies&lt;/goal&gt;
832 &lt;/goals&gt;
833 &lt;/execution&gt;
834 &lt;/executions&gt;
835 &lt;/plugin&gt;
836 &lt;/plugins&gt;
837 &lt;/build&gt;
838
839 &lt;dependencies&gt;
840 &lt;dependency&gt;
841 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
842 &lt;artifactId&gt;osgi_R4_core&lt;/artifactId&gt;
843 &lt;version&gt;1.0&lt;/version&gt;
844 &lt;scope&gt;provided&lt;/scope&gt;
845 &lt;optional&gt;true&lt;/optional&gt;
846 &lt;/dependency&gt;
847 &lt;dependency&gt;
848 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
849 &lt;artifactId&gt;osgi_R4_compendium&lt;/artifactId&gt;
850 &lt;version&gt;1.0&lt;/version&gt;
851 &lt;scope&gt;provided&lt;/scope&gt;
852 &lt;optional&gt;true&lt;/optional&gt;
853 &lt;/dependency&gt;
854 &lt;dependency&gt;
855 &lt;groupId&gt;junit&lt;/groupId&gt;
856 &lt;artifactId&gt;junit&lt;/artifactId&gt;
857 &lt;version&gt;3.8.1&lt;/version&gt;
858 &lt;scope&gt;compile&lt;/scope&gt;
859 &lt;optional&gt;true&lt;/optional&gt;
860 &lt;/dependency&gt;
861 &lt;/dependencies&gt;
862
863&lt;/project&gt;
864</pre>
865</div></div>
866
867<p>To generate the Eclipse metadata use:</p>
868
869<div class="code"><div class="codeContent">
870<pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre>
871</div></div>
872
873<p>and you should now be able to import this as an existing Eclipse project.</p>
874
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000875<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" width="7" height="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 +0000876
877<p>With the original Pax-Construct generated POM you would simply use:</p>
878
879<div class="code"><div class="codeContent">
880<pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre>
881</div></div>
882
883<p>to create the appropriate Eclipse files and manifest, and also
884handle any embedded entries. The pax:eclipse goal extends
885eclipse:eclipse, and supports the same parameters.</p>
886
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000887<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000888
889<p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>,
890for example when you embed the classes from another jar. This can
891sometimes cause unforeseen problems in Maven, as it will use the output
892directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p>
893
894<p>The easiest way to get around this Maven 'feature' is to unpack the
895contents of the bundle to the output directory after the packaging
896step, so the additional classes will be found where Maven expects them.
897Thankfully there is now an easy option to do this in the bundle-plugin:</p>
898
899<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000900<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
901<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
902<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
903<span class="code-tag">&lt;configuration&gt;</span>
904 <span class="code-tag">&lt;unpackBundle&gt;</span>true<span class="code-tag">&lt;/unpackBundle&gt;</span>
905 <span class="code-tag">&lt;instructions&gt;</span>
906 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
907 <span class="code-tag">&lt;/instructions&gt;</span>
908<span class="code-tag">&lt;/configuration&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000909</div></div>
910
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000911<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000912
913<p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p>
914
915<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000916<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>
917<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 +0000918</div></div>
919
920<p>Bnd will use it when calculating the bundle contents, and will also
921copy across all manifest attributes starting with a capital letter.<br>
922As shown in the above example, you could use this to include a non-OSGi
923manifest which you then customize with extra OSGi attributes.</p>
924
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000925<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 +0000926
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000927<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000928
929<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>
930
931<p>The customized Ant script uses the BND tool to rebuild the bundle,
932so any source changes should be reflected in the (re)generated manifest.</p>
933
934<p>Example:</p>
935<div class="preformatted"><div class="preformattedContent">
936<pre>mvn ant:ant bundle:ant
937
938ant clean package
939</pre>
940</div></div>
941
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000942<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000943
944<p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p>
945
946<p>configuration:</p>
947<ul>
948 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
949 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
950 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
951 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
952 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
953 <li><em>classifier</em> Maven classifier type, defaults to none</li>
954 <li><em>pomFile</em> optional Pom file describing the bundle</li>
955 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
956 <li><em>obrXml</em> optional additional properties for the bundle</li>
957</ul>
958
959
960<p>Example:</p>
961<div class="preformatted"><div class="preformattedContent">
962<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \
963 -DpomFile=myPom.xml -Dfile=foo-1.0.jar
964</pre>
965</div></div>
966
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000967<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000968
969<p>The <b>deploy goal</b> updates the remote OBR with the details of
970the deployed bundle from the local Maven repository. The remote OBR is
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000971found 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" width="7" height="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000972
973<p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p>
974
975<p>configuration:</p>
976<ul>
977 <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
978 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
979 <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li>
980 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
981</ul>
982
983
984<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>
985
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000986<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000987
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000988<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" width="7" height="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000989
990<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>
991
992<p>configuration:</p>
993<ul>
994 <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li>
995 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
996 <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li>
997 <li><em>url</em> remote repository transport URL, like
998<div class="preformatted"><div class="preformattedContent">
999<pre>scpexe://host/path/to/obr
1000</pre>
1001</div></div></li>
1002 <li><em>bundleUrl</em> public URL of deployed bundle, like
1003<div class="preformatted"><div class="preformattedContent">
1004<pre>http://www.foo.org/bundles/foo.jar
1005</pre>
1006</div></div></li>
1007 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
1008 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
1009 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
1010 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
1011 <li><em>classifier</em> Maven classifier type, defaults to none</li>
1012 <li><em>pomFile</em> optional Pom file describing the bundle</li>
1013 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
1014 <li><em>obrXml</em> optional additional properties for the bundle</li>
1015 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
1016</ul>
1017
1018
1019<p>Example:</p>
1020<div class="preformatted"><div class="preformattedContent">
1021<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \
1022 -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \
1023 -DbundleUrl=http://www.foo.org/bundles/foo.jar
1024</pre>
1025</div></div>
1026
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001027<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001028
1029<p>Sometimes you would like to clean your local OBR because it contains
1030bundles that are no longer in your local Maven repository. This case
1031often occurs when artifacts were deleted manually. The
1032maven-bundle-plugin provides a simple goal to check for missing
1033bundles, and remove them from the local OBR.</p>
1034
1035<p>configuration:</p>
1036<ul>
1037 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1038</ul>
1039
1040
1041<p>Example:</p>
1042<div class="preformatted"><div class="preformattedContent">
1043<pre>mvn bundle:clean
1044</pre>
1045</div></div>
1046
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001047<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001048
1049<p>With a remote OBR, several uploads may occur at the same time.
1050However, the remote OBR is centralized in one file, so concurrent
1051modification must be avoided. To achieve this, the plug-in implements a
1052locking system. Each time the plug-in tries to modify the file it sets
1053a file based lock. If it can't take the lock, it will wait and retry.
1054After 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>
1055
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001056<h2><a name="ApacheFelixMavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001057
1058<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>
1059<div class="code"><div class="codeContent">
1060<pre class="code-xml"><span class="code-tag">&lt;build&gt;</span>
1061 <span class="code-tag">&lt;extensions&gt;</span>
1062 <span class="code-tag">&lt;extension&gt;</span>
1063 <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.wagon<span class="code-tag">&lt;/groupId&gt;</span>
1064 <span class="code-tag">&lt;artifactId&gt;</span>wagon-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
1065 <span class="code-tag">&lt;version&gt;</span>1.0-alpha-6<span class="code-tag">&lt;/version&gt;</span>
1066 <span class="code-tag">&lt;/extension&gt;</span>
1067 <span class="code-tag">&lt;/extensions&gt;</span>
1068<span class="code-tag">&lt;/build&gt;</span></pre>
1069</div></div>
1070
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001071<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 +00001072
1073<p>The description of the bundle comes from three different sources:</p>
1074<ul>
1075 <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li>
1076 <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li>
1077 <li>obr.xml : this file contains customized description and capabilities for the bundle</li>
1078</ul>
1079
1080
1081<p>These sources are merged together using the following precedence:</p>
1082<div class="preformatted"><div class="preformattedContent">
1083<pre>Bindex
1084| (overrides)
1085pom.xml
1086| (overrides)
1087obr.xml
1088</pre>
1089</div></div>
1090<p>A warning message is displayed when existing information is overridden.</p>
1091
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001092<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Knownissues&amp;limitations"></a>Known issues &amp; limitations</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001093
1094<ol>
1095 <li>obr.xml (file given by the user to add properties not found
1096by Bindex) must be correct, because the plug-in does not check its
1097syntax.</li>
1098</ol>
1099
1100
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001101<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Feedback"></a>Feedback</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +00001102
Stuart McCullochb4212cc2008-08-05 06:36:05 +00001103<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" width="13" height="12"></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" width="13" height="12"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +00001104 </div>
Stuart McCullochb4212cc2008-08-05 06:36:05 +00001105 </body></html>