blob: 39e639015896ccda957c7f138fb8a3cd42770021 [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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" 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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" 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="" width="7" align="absmiddle" border="0" 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="" width="7" align="absmiddle" border="0" 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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" 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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" 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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" height="7"></sup></a></span> component, which uses the following algorithm:<br>
Stuart McCullochb4212cc2008-08-05 06:36:05 +0000200Get 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 McCullochc9b81e12009-02-26 21:29:51 +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="" width="7" align="absmiddle" border="0" 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 McCullochc9b81e12009-02-26 21:29:51 +0000451<p>If you want to use packaging types other than "jar" and "bundle" then you also need to enable support<br>
452for them in the bundleplugin configuration, for example if you want to use the plugin with WAR files:</p>
453
454<div class="code"><div class="codeContent">
455<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
456 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
457 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
458 <span class="code-tag">&lt;executions&gt;</span>
459 <span class="code-tag">&lt;execution&gt;</span>
460 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
461 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
462 <span class="code-tag">&lt;goals&gt;</span>
463 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
464 <span class="code-tag">&lt;/goals&gt;</span>
465 <span class="code-tag">&lt;/execution&gt;</span>
466 <span class="code-tag">&lt;/executions&gt;</span>
467 <span class="code-tag">&lt;configuration&gt;</span>
468 <span class="code-tag">&lt;supportedProjectTypes&gt;</span>
469 <span class="code-tag">&lt;supportedProjectType&gt;</span>jar<span class="code-tag">&lt;/supportedProjectType&gt;</span>
470 <span class="code-tag">&lt;supportedProjectType&gt;</span>bundle<span class="code-tag">&lt;/supportedProjectType&gt;</span>
471 <span class="code-tag">&lt;supportedProjectType&gt;</span>war<span class="code-tag">&lt;/supportedProjectType&gt;</span>
472 <span class="code-tag">&lt;/supportedProjectTypes&gt;</span>
473 <span class="code-tag">&lt;instructions&gt;</span>
474 <span class="code-tag"><span class="code-comment">&lt;!-- ...etc... --&gt;</span></span>
475 <span class="code-tag">&lt;/instructions&gt;</span>
476 <span class="code-tag">&lt;/configuration&gt;</span>
477<span class="code-tag">&lt;/plugin&gt;</span></pre>
478</div></div>
479
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000480<h2><a name="ApacheFelixMavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000481
Stuart McCulloch93de6492007-12-16 15:59:05 +0000482<p>The plugin is hosted at the Apache Felix project. The following
483steps describe how to build and install the plugin into your local
484Maven2 repository.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000485
486<p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000487
Karl Paulsf87ac142007-07-06 22:36:17 +0000488<div class="preformatted"><div class="preformattedContent">
Stuart McCulloch93de6492007-12-16 15:59:05 +0000489<pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin
Karl Paulsf87ac142007-07-06 22:36:17 +0000490</pre>
491</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000492
Karl Paulsf87ac142007-07-06 22:36:17 +0000493<p>Using Maven2, build and install the maven-bundle-plugin by issuing
494the following Maven2 command in the project directory that was created
495as a result of the previous step.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000496
Karl Paulsf87ac142007-07-06 22:36:17 +0000497<div class="preformatted"><div class="preformattedContent">
498<pre>$ mvn install
499</pre>
500</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000501
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000502<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Goals"></a>Goals</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000503
504<p>The maven-bundle-plugin also provides additional functionality via
505some Maven goals. Command-line execution of a goal is performed as
506follows:</p>
507
508<div class="preformatted"><div class="preformattedContent">
509<pre>mvn org.apache.felix:maven-bundle-plugin:GOAL
510</pre>
511</div></div>
512
513<p>Where GOAL is one of the following:</p>
514
515<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000516 <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000517configuration options:
518 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000519 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
520 <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000521 <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 McCulloch0340ae42008-02-22 11:27:18 +0000522 <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000523 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000524 </ul>
525 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000526</ul>
527
528
529<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000530 <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000531configuration options:
532 <ul>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000533 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000534 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000535 </ul>
536 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000537</ul>
538
539
540<ul>
541 <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000542configuration options:
543 <ul>
Stuart McCulloch981bd342008-05-03 12:49:39 +0000544 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000545 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000546 </ul>
547 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000548</ul>
549
550
551<ul>
552 <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000553configuration options:
554 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000555 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
556 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000557 </ul>
558 </li>
559</ul>
560
561
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000562<ul>
563 <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br>
564configuration options:
565 <ul>
566 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000567 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000568 </ul>
569 </li>
570</ul>
571
572
573<p>More GOALs are available in the <b>1.4.0</b> release:</p>
574
575<ul>
576 <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li>
577</ul>
578
579
580<ul>
581 <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br>
582configuration options:
583 <ul>
584 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
585 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
586 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
587 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
588 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
589 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
590 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
591 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
592 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
593 </ul>
594 </li>
595</ul>
596
597
598<ul>
599 <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br>
600configuration options:
601 <ul>
602 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
603 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000604 <li><em><tt>prefixUrl</tt></em> optional public URL prefix for the remote repository</li>
605 <li><em><tt>bundleUrl</tt></em> optional public URL where the bundle has been deployed</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000606 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000607 <li><em><tt>obrDeploymentRepository</tt></em> optional OBR specific deployment repository.</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000608 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000609 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000610 </ul>
611 </li>
612</ul>
613
614
615<ul>
616 <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br>
617configuration options:
618 <ul>
619 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li>
620 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
621 <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li>
622 <li><em><tt>url</tt></em> remote repository transport URL, like
623<div class="preformatted"><div class="preformattedContent">
624<pre>scpexe://host/path/to/obr
625</pre>
626</div></div></li>
627 <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like
628<div class="preformatted"><div class="preformattedContent">
629<pre>http://www.foo.org/bundles/foo.jar
630</pre>
631</div></div></li>
632 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
633 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
634 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
635 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
636 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
637 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
638 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
639 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
640 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
641 </ul>
642 </li>
643</ul>
644
645
646<ul>
647 <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br>
648configuration options:
649 <ul>
650 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
651 </ul>
652 </li>
653</ul>
654
655
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000656
657<ul>
658 <li><b><tt>remote-clean</tt></b> - cleans a remote OBR, removing missing bundles<br>
659configuration options:
660 <ul>
661 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote cleaning)</li>
662 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
663 <li><em><tt>prefixUrl</tt></em> optional public URL prefix for the remote repository</li>
664 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
665 <li><em><tt>obrDeploymentRepository</tt></em> optional OBR specific deployment repository.</li>
666 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
667 </ul>
668 </li>
669</ul>
670
671
Stuart McCulloch93de6492007-12-16 15:59:05 +0000672<p>There are also new instructions available from the underlying BND
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000673tool, 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="" width="7" align="absmiddle" border="0" height="7"></sup></a></span>.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000674
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000675<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 +0000676
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000677<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 +0000678
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000679<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000680
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000681<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 +0000682
683<div class="code"><div class="codeContent">
684<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>dependencies<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
685</div></div>
686
687<p>where:</p>
688
689<div class="preformatted"><div class="preformattedContent">
690<pre>dependencies ::= clause ( ',' clause ) *
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000691clause ::= MATCH ( ';' attr '=' MATCH | ';inline=' inline )
Stuart McCulloch93de6492007-12-16 15:59:05 +0000692attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier'
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000693inline ::= 'true' | 'false' | PATH ( '|' PATH ) *
694MATCH ::= &lt;globbed regular expression&gt;
695PATH ::= &lt;Ant-style path expression&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000696</pre>
697</div></div>
698
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000699<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>
700clauses, which are then appended to the current set of instructions and
701passed onto BND. If you want the embedded dependencies to be at the
702start 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 +0000703
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000704<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>
705
Stuart McCulloch93de6492007-12-16 15:59:05 +0000706<p>some examples:</p>
707
708<div class="code"><div class="codeContent">
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000709<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies --&gt;</span></span>
710<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 +0000711
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000712<span class="code-tag"><span class="code-comment">&lt;!-- embed any dependencies with artifactId junit and scope runtime --&gt;</span></span>
713<span class="code-tag">&lt;Embed-Dependency&gt;</span>junit;scope=runtime<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000714
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000715<span class="code-tag"><span class="code-comment">&lt;!-- inline all non-pom dependencies, except those with scope runtime --&gt;</span></span>
716<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;scope=!runtime;type=!pom;inline=true<span class="code-tag">&lt;/Embed-Dependency&gt;</span>
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000717
718<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>
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000719<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>
720
721<span class="code-tag"><span class="code-comment">&lt;!-- inline contents of selected folders from all dependencies --&gt;</span></span>
722<span class="code-tag">&lt;Embed-Dependency&gt;</span>*;inline=images/**|icons/**<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000723</div></div>
724
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000725<p>examples of using {<tt>maven-dependencies</tt>}:</p>
726
727<div class="code"><div class="codeContent">
728<pre class="code-xml"><span class="code-tag">&lt;Include-Resource&gt;</span>
729 {maven-resources}, {maven-dependencies},
730 org/foo/Example.class=target/classes/org/foo/Example.class
731<span class="code-tag">&lt;/Include-Resource&gt;</span>
732
733<span class="code-tag">&lt;Bundle-ClassPath&gt;</span>.,{maven-dependencies},some.jar<span class="code-tag">&lt;/Bundle-ClassPath&gt;</span></pre>
734</div></div>
735
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000736<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 +0000737
738<ul>
739 <li><tt>&lt;Embed-StripVersion&gt;true&lt;/Embed-StripVersion&gt;</tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li>
740 <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>
741 <li><tt>&lt;Embed-Directory&gt;directory&lt;/Embed-Directory&gt;</tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li>
742</ul>
743
744
745<p>Normally the plugin only checks direct dependencies, but this can be
746changed to include the complete set of transitive dependencies with the
747following option:</p>
748
749<div class="code"><div class="codeContent">
750<pre class="code-xml"><span class="code-tag">&lt;Embed-Transitive&gt;</span>true<span class="code-tag">&lt;/Embed-Transitive&gt;</span></pre>
751</div></div>
752
753<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>
754
755<div class="code"><div class="codeContent">
756<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>
757</div></div>
758
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000759<h3><a name="ApacheFelixMavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000760
761<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>
762instructions will result in classes being inlined in the bundle, even
763though they also exist inside the embedded jar. If you want to export
764packages from an embedded dependency without such duplication then you
765can either inline the dependency, or use a new BND instruction called <tt>&lt;_exportcontents&gt;</tt>.</p>
766
767<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 +0000768
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000769<h2><a name="ApacheFelixMavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000770
771<p>The latest Maven Bundle Plugin automatically updates the local OBR
772repository.xml file during the install phase, using a default location
773of:</p>
774
775<div class="code"><div class="codeContent">
776<pre class="code-java">&lt;LOCAL-MAVEN-REPOSITORY&gt;/repository.xml</pre>
777</div></div>
778
779<p>You can configure the location of the OBR repository by using the command line:</p>
780
781<div class="code"><div class="codeContent">
782<pre class="code-java">mvn clean install -DobrRepository=&lt;PATH_TO_OBR&gt;</pre>
783</div></div>
784
785<p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p>
786
787<div class="code"><div class="codeContent">
788<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
789<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
790<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
791<span class="code-tag">&lt;configuration&gt;</span>
792 <span class="code-tag">&lt;obrRepository&gt;</span>PATH_TO_OBR<span class="code-tag">&lt;/obrRepository&gt;</span>
793 <span class="code-tag">&lt;instructions&gt;</span>
794 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
795 <span class="code-tag">&lt;/instructions&gt;</span>
796<span class="code-tag">&lt;/configuration&gt;</span></pre>
797</div></div>
798
799<p>to disable OBR installation set the obrRepository to NONE, for example:</p>
800
801<div class="code"><div class="codeContent">
802<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
803<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
804<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
805<span class="code-tag">&lt;configuration&gt;</span>
806 <span class="code-tag">&lt;obrRepository&gt;</span>NONE<span class="code-tag">&lt;/obrRepository&gt;</span>
807 <span class="code-tag">&lt;instructions&gt;</span>
808 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
809 <span class="code-tag">&lt;/instructions&gt;</span>
810<span class="code-tag">&lt;/configuration&gt;</span></pre>
811</div></div>
812
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000813<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000814
815<p>It is possible to configure the Maven Bundle Plugin to put the
816bundle manifest where Eclipse/PDE expects it, and use the Maven
817Dependency Plugin to arrange for any embedded dependencies to appear in
818a local directory that matches the Bundle-ClassPath entries. Here is an
819example POM that does this:</p>
820
821<div class="preformatted"><div class="preformattedContent">
822<pre>&lt;project&gt;
823
824 &lt;properties&gt;
825 &lt;bundle.symbolicName&gt;org.example&lt;/bundle.symbolicName&gt;
826 &lt;bundle.namespace&gt;org.example&lt;/bundle.namespace&gt;
827 &lt;/properties&gt;
828
829 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
830 &lt;groupId&gt;examples&lt;/groupId&gt;
831 &lt;artifactId&gt;org.example&lt;/artifactId&gt;
832 &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
833
834 &lt;name&gt;${bundle.symbolicName} [${bundle.namespace}]&lt;/name&gt;
835
836 &lt;packaging&gt;bundle&lt;/packaging&gt;
837
838 &lt;build&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000839 &lt;resources&gt;
840 &lt;resource&gt;
841 &lt;directory&gt;src/main/resources&lt;/directory&gt;
842 &lt;/resource&gt;
843 &lt;resource&gt;
844 &lt;directory&gt;.&lt;/directory&gt;
845 &lt;includes&gt;
846 &lt;include&gt;plugin.xml&lt;/include&gt;
847 &lt;/includes&gt;
848 &lt;/resource&gt;
849 &lt;/resources&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000850 &lt;plugins&gt;
851 &lt;plugin&gt;
852 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
853 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000854 &lt;version&gt;1.2.1&lt;/version&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000855 &lt;extensions&gt;true&lt;/extensions&gt;
856 &lt;!--
857 the following instructions build a simple set of public/private classes into an OSGi bundle
858 --&gt;
859 &lt;configuration&gt;
860 &lt;manifestLocation&gt;META-INF&lt;/manifestLocation&gt;
861 &lt;instructions&gt;
862 &lt;Bundle-SymbolicName&gt;${bundle.symbolicName}&lt;/Bundle-SymbolicName&gt;
863 &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
864 &lt;!--
865 assume public classes are in the top package, and private classes are under ".internal"
866 --&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000867 &lt;Export-Package&gt;!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"&lt;/Export-Package&gt;
868 &lt;Private-Package&gt;${bundle.namespace}.internal.*&lt;/Private-Package&gt;
869 &lt;Bundle-Activator&gt;${bundle.namespace}.internal.ExampleActivator&lt;/Bundle-Activator&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000870 &lt;!--
871 embed compile/runtime dependencies using path that matches the copied dependency folder
872 --&gt;
873 &lt;Embed-Dependency&gt;*;scope=compile|runtime;inline=false&lt;/Embed-Dependency&gt;
874 &lt;Embed-Directory&gt;target/dependency&lt;/Embed-Directory&gt;
875 &lt;Embed-StripGroup&gt;true&lt;/Embed-StripGroup&gt;
876 &lt;/instructions&gt;
877 &lt;/configuration&gt;
878 &lt;/plugin&gt;
879 &lt;plugin&gt;
880 &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
881 &lt;executions&gt;
882 &lt;execution&gt;
883 &lt;id&gt;copy-dependencies&lt;/id&gt;
884 &lt;phase&gt;package&lt;/phase&gt;
885 &lt;goals&gt;
886 &lt;goal&gt;copy-dependencies&lt;/goal&gt;
887 &lt;/goals&gt;
888 &lt;/execution&gt;
889 &lt;/executions&gt;
890 &lt;/plugin&gt;
891 &lt;/plugins&gt;
892 &lt;/build&gt;
893
894 &lt;dependencies&gt;
895 &lt;dependency&gt;
896 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
897 &lt;artifactId&gt;osgi_R4_core&lt;/artifactId&gt;
898 &lt;version&gt;1.0&lt;/version&gt;
899 &lt;scope&gt;provided&lt;/scope&gt;
900 &lt;optional&gt;true&lt;/optional&gt;
901 &lt;/dependency&gt;
902 &lt;dependency&gt;
903 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
904 &lt;artifactId&gt;osgi_R4_compendium&lt;/artifactId&gt;
905 &lt;version&gt;1.0&lt;/version&gt;
906 &lt;scope&gt;provided&lt;/scope&gt;
907 &lt;optional&gt;true&lt;/optional&gt;
908 &lt;/dependency&gt;
909 &lt;dependency&gt;
910 &lt;groupId&gt;junit&lt;/groupId&gt;
911 &lt;artifactId&gt;junit&lt;/artifactId&gt;
912 &lt;version&gt;3.8.1&lt;/version&gt;
913 &lt;scope&gt;compile&lt;/scope&gt;
914 &lt;optional&gt;true&lt;/optional&gt;
915 &lt;/dependency&gt;
916 &lt;/dependencies&gt;
917
918&lt;/project&gt;
919</pre>
920</div></div>
921
922<p>To generate the Eclipse metadata use:</p>
923
924<div class="code"><div class="codeContent">
925<pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre>
926</div></div>
927
928<p>and you should now be able to import this as an existing Eclipse project.</p>
929
Stuart McCullochc9b81e12009-02-26 21:29:51 +0000930<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="" width="7" align="absmiddle" border="0" 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 +0000931
932<p>With the original Pax-Construct generated POM you would simply use:</p>
933
934<div class="code"><div class="codeContent">
935<pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre>
936</div></div>
937
938<p>to create the appropriate Eclipse files and manifest, and also
939handle any embedded entries. The pax:eclipse goal extends
940eclipse:eclipse, and supports the same parameters.</p>
941
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000942<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000943
944<p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>,
945for example when you embed the classes from another jar. This can
946sometimes cause unforeseen problems in Maven, as it will use the output
947directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p>
948
949<p>The easiest way to get around this Maven 'feature' is to unpack the
950contents of the bundle to the output directory after the packaging
951step, so the additional classes will be found where Maven expects them.
952Thankfully there is now an easy option to do this in the bundle-plugin:</p>
953
954<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000955<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
956<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
957<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
958<span class="code-tag">&lt;configuration&gt;</span>
959 <span class="code-tag">&lt;unpackBundle&gt;</span>true<span class="code-tag">&lt;/unpackBundle&gt;</span>
960 <span class="code-tag">&lt;instructions&gt;</span>
961 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
962 <span class="code-tag">&lt;/instructions&gt;</span>
963<span class="code-tag">&lt;/configuration&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000964</div></div>
965
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000966<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000967
968<p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p>
969
970<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000971<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>
972<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 +0000973</div></div>
974
975<p>Bnd will use it when calculating the bundle contents, and will also
976copy across all manifest attributes starting with a capital letter.<br>
977As shown in the above example, you could use this to include a non-OSGi
978manifest which you then customize with extra OSGi attributes.</p>
979
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000980<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 +0000981
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000982<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000983
984<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>
985
986<p>The customized Ant script uses the BND tool to rebuild the bundle,
987so any source changes should be reflected in the (re)generated manifest.</p>
988
989<p>Example:</p>
990<div class="preformatted"><div class="preformattedContent">
991<pre>mvn ant:ant bundle:ant
992
993ant clean package
994</pre>
995</div></div>
996
Stuart McCullochdd89cdb2008-05-03 08:13:09 +0000997<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000998
999<p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p>
1000
1001<p>configuration:</p>
1002<ul>
1003 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1004 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
1005 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
1006 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
1007 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
1008 <li><em>classifier</em> Maven classifier type, defaults to none</li>
1009 <li><em>pomFile</em> optional Pom file describing the bundle</li>
1010 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
1011 <li><em>obrXml</em> optional additional properties for the bundle</li>
1012</ul>
1013
1014
1015<p>Example:</p>
1016<div class="preformatted"><div class="preformattedContent">
1017<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \
1018 -DpomFile=myPom.xml -Dfile=foo-1.0.jar
1019</pre>
1020</div></div>
1021
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001022<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001023
1024<p>The <b>deploy goal</b> updates the remote OBR with the details of
1025the deployed bundle from the local Maven repository. The remote OBR is
Stuart McCullochc9b81e12009-02-26 21:29:51 +00001026found 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="" width="7" align="absmiddle" border="0" height="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001027
1028<p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p>
1029
1030<p>configuration:</p>
1031<ul>
1032 <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
1033 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
1034 <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li>
1035 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
1036</ul>
1037
1038
1039<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>
1040
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001041<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001042
Stuart McCullochc9b81e12009-02-26 21:29:51 +00001043<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="" width="7" align="absmiddle" border="0" height="7"></sup></a></span> for more details about these particular settings.</p>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001044
1045<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>
1046
1047<p>configuration:</p>
1048<ul>
1049 <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li>
1050 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
1051 <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li>
1052 <li><em>url</em> remote repository transport URL, like
1053<div class="preformatted"><div class="preformattedContent">
1054<pre>scpexe://host/path/to/obr
1055</pre>
1056</div></div></li>
1057 <li><em>bundleUrl</em> public URL of deployed bundle, like
1058<div class="preformatted"><div class="preformattedContent">
1059<pre>http://www.foo.org/bundles/foo.jar
1060</pre>
1061</div></div></li>
1062 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
1063 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
1064 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
1065 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
1066 <li><em>classifier</em> Maven classifier type, defaults to none</li>
1067 <li><em>pomFile</em> optional Pom file describing the bundle</li>
1068 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
1069 <li><em>obrXml</em> optional additional properties for the bundle</li>
1070 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
1071</ul>
1072
1073
1074<p>Example:</p>
1075<div class="preformatted"><div class="preformattedContent">
1076<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \
1077 -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \
1078 -DbundleUrl=http://www.foo.org/bundles/foo.jar
1079</pre>
1080</div></div>
1081
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001082<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001083
1084<p>Sometimes you would like to clean your local OBR because it contains
1085bundles that are no longer in your local Maven repository. This case
1086often occurs when artifacts were deleted manually. The
1087maven-bundle-plugin provides a simple goal to check for missing
1088bundles, and remove them from the local OBR.</p>
1089
1090<p>configuration:</p>
1091<ul>
1092 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1093</ul>
1094
1095
1096<p>Example:</p>
1097<div class="preformatted"><div class="preformattedContent">
1098<pre>mvn bundle:clean
1099</pre>
1100</div></div>
1101
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001102<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001103
1104<p>With a remote OBR, several uploads may occur at the same time.
1105However, the remote OBR is centralized in one file, so concurrent
1106modification must be avoided. To achieve this, the plug-in implements a
1107locking system. Each time the plug-in tries to modify the file it sets
1108a file based lock. If it can't take the lock, it will wait and retry.
1109After 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>
1110
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001111<h2><a name="ApacheFelixMavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001112
1113<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>
1114<div class="code"><div class="codeContent">
1115<pre class="code-xml"><span class="code-tag">&lt;build&gt;</span>
1116 <span class="code-tag">&lt;extensions&gt;</span>
1117 <span class="code-tag">&lt;extension&gt;</span>
1118 <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.wagon<span class="code-tag">&lt;/groupId&gt;</span>
1119 <span class="code-tag">&lt;artifactId&gt;</span>wagon-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
1120 <span class="code-tag">&lt;version&gt;</span>1.0-alpha-6<span class="code-tag">&lt;/version&gt;</span>
1121 <span class="code-tag">&lt;/extension&gt;</span>
1122 <span class="code-tag">&lt;/extensions&gt;</span>
1123<span class="code-tag">&lt;/build&gt;</span></pre>
1124</div></div>
1125
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001126<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 +00001127
1128<p>The description of the bundle comes from three different sources:</p>
1129<ul>
1130 <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li>
1131 <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li>
1132 <li>obr.xml : this file contains customized description and capabilities for the bundle</li>
1133</ul>
1134
1135
1136<p>These sources are merged together using the following precedence:</p>
1137<div class="preformatted"><div class="preformattedContent">
1138<pre>Bindex
1139| (overrides)
1140pom.xml
1141| (overrides)
1142obr.xml
1143</pre>
1144</div></div>
1145<p>A warning message is displayed when existing information is overridden.</p>
1146
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001147<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Knownissues&amp;limitations"></a>Known issues &amp; limitations</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001148
1149<ol>
1150 <li>obr.xml (file given by the user to add properties not found
1151by Bindex) must be correct, because the plug-in does not check its
1152syntax.</li>
1153</ol>
1154
1155
Stuart McCullochdd89cdb2008-05-03 08:13:09 +00001156<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Feedback"></a>Feedback</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +00001157
Stuart McCullochc9b81e12009-02-26 21:29:51 +00001158<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="" width="13" align="absmiddle" border="0" 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="" width="13" align="absmiddle" border="0" height="12"></sup></a></span>.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +00001159 </div>
Stuart McCullochb4212cc2008-08-05 06:36:05 +00001160 </body></html>