blob: a79eda7972b7ca517bd98243b9c0065522d621cb [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 McCulloch5f3ddf72008-05-03 12:49:39 +00002<html><head>
Karl Paulsf87ac142007-07-06 22:36:17 +00003
4
5
Stuart McCulloch5f3ddf72008-05-03 12:49:39 +00006 <title>Apache Felix - Apache Felix Maven Bundle Plugin (BND)</title>
Stuart McCulloch3f38f732008-05-03 08:13:09 +00007 <link rel="stylesheet" href="apache-felix-maven-bundle-plugin-bnd_files/site.css" type="text/css" media="all">
Stuart McCulloch5f3ddf72008-05-03 12:49:39 +00008 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 </head><body>
Stuart McCulloch3f38f732008-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 McCulloch1bcd7952009-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 McCulloch3f38f732008-05-03 08:13:09 +000018 <li><a href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</a></li>
Stuart McCulloch1bcd7952009-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 McCulloch3f38f732008-05-03 08:13:09 +000022<!-- ApacheCon Ad -->
Stuart McCulloche23ec842008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch1bcd7952009-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 McCulloch2eb61122009-02-27 06:38:33 +000039<p><em>NOTE: test scoped dependencies are <b>not</b> included in the classpath seen by BND.</em></p>
Stuart McCulloche23ec842008-08-05 06:36:05 +000040
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 McCulloch3f38f732008-05-03 08:13:09 +000047<p><a name="ApacheFelixMavenBundlePlugin(BND)-simpleexample"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +000048
Stuart McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch1bcd7952009-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 McCulloch3f38f732008-05-03 08:13:09 +0000117<p><a name="ApacheFelixMavenBundlePlugin(BND)-instructions"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000118
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000119<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Instructions"></a>Instructions</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000120
Stuart McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-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 McCulloch3f38f732008-05-03 08:13:09 +0000190<p><a name="ApacheFelixMavenBundlePlugin(BND)-defaultbehavior"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000191
Stuart McCulloch3f38f732008-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 McCulloch1bcd7952009-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 McCulloche23ec842008-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.
Stuart McCulloch2eb61122009-02-27 06:38:33 +0000212eg. org.apache.maven:maven-core -&gt; org.apache.maven.core<br>
213The computed symbolic name is also stored in the <tt>$(maven-symbolicname)</tt> property in case you want to add attributes or directives to it.</li>
Stuart McCulloche23ec842008-08-05 06:36:05 +0000214 </ul>
215 </li>
Stuart McCulloch2eb61122009-02-27 06:38:33 +0000216 <li><tt>&lt;Export-Package&gt;</tt>
217is now assumed to be the set of packages in your local Java sources,
218excluding the default package '.' and any packages containing 'impl' or
219'internal'.<br>
220<em>(before version 2 of the bundleplugin it was based on the symbolic name)</em></li>
221 <li><tt>&lt;Private-Package&gt;</tt> is now assumed to be the set of packages in your local Java sources (note that any packages in both <tt>&lt;Export-Package&gt;</tt> and <tt>&lt;Private-Package&gt;</tt> will be exported).<br>
222<em>(before version 2 of the bundleplugin it was assumed to be empty by default)</em></li>
223 <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.<br>
224<em>Any exported packages are also imported by default, to ensure a consistent class space.</em></li>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000225 <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 +0000226which will copy the specified project directory hierarchy into the
227resulting bundle JAR file, mirroring standard Maven behavior.</li>
228 <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>
229 <li><tt>&lt;Bundle-Name&gt;</tt> is assumed to be "<tt>${pom.name</tt>}".</li>
230 <li><tt>&lt;Bundle-Description&gt;</tt> is assumed to be "<tt>${pom.description</tt>}".</li>
231 <li><tt>&lt;Bundle-License&gt;</tt> is assumed to be "<tt>${pom.licenses</tt>}".</li>
232 <li><tt>&lt;Bundle-Vendor&gt;</tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li>
233 <li><tt>&lt;Bundle-DocURL&gt;</tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li>
234</ul>
235
236
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000237<p>Since the plugin creates bundles for OSGi R4, it hard-codes <tt>Bundle-ManifestVersion</tt>
Karl Paulsf87ac142007-07-06 22:36:17 +0000238to be '2'. Additionally, it generates imports for every export to
239ensure package substitutability, which is very important when working
240with collaborating services. It is possible to override any of these
241values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p>
242
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000243<p><a name="ApacheFelixMavenBundlePlugin(BND)-howto"></a></p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000244
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000245<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Detailed&quot;HowTo&quot;"></a>Detailed "How To"</h1>
Karl Paulsf87ac142007-07-06 22:36:17 +0000246
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000247<h2><a name="ApacheFelixMavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000248
249<p>The first step in the process of using the plugin is downloading and
250installing the latest version of the Maven2 runtime. The latest Maven2
251release and instuctions for getting started with Maven2 can be found at
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000252the <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 +0000253
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000254<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000255
256<p>To use the maven-bundle-plugin, you first need to add the plugin and
257some appropriate plugin configuration to your bundle project's POM.
258Below is an example of a simple OSGi bundle POM for Maven2:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000259
Karl Paulsf87ac142007-07-06 22:36:17 +0000260<div class="preformatted"><div class="preformattedContent">
261<pre>&lt;project&gt;
262 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
263 &lt;groupId&gt;my-osgi-bundles&lt;/groupId&gt;
264 &lt;artifactId&gt;examplebundle&lt;/artifactId&gt;
265 &lt;packaging&gt;bundle&lt;/packaging&gt; &lt;!-- (1) --&gt;
266 &lt;version&gt;1.0&lt;/version&gt;
267 &lt;name&gt;Example Bundle&lt;/name&gt;
268 &lt;dependencies&gt;
269 &lt;dependency&gt;
270 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
271 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000272 &lt;version&gt;1.0.0&lt;/version&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000273 &lt;/dependency&gt;
274 &lt;/dependencies&gt;
275 &lt;build&gt;
276 &lt;plugins&gt;
277 &lt;plugin&gt; &lt;!-- (2) START --&gt;
278 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
279 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
280 &lt;extensions&gt;true&lt;/extensions&gt;
281 &lt;configuration&gt;
282 &lt;instructions&gt;
283 &lt;Export-Package&gt;com.my.company.api&lt;/Export-Package&gt;
284 &lt;Private-Package&gt;com.my.company.*&lt;/Private-Package&gt;
285 &lt;Bundle-Activator&gt;com.my.company.Activator&lt;/Bundle-Activator&gt;
286 &lt;/instructions&gt;
287 &lt;/configuration&gt;
288 &lt;/plugin&gt; &lt;!-- (2) END --&gt;
289 &lt;/plugins&gt;
290 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000291&lt;/project&gt;
292</pre>
293</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000294
295<p>There are two main things to note: (1) the <tt>&lt;packaging&gt;</tt>
296specifier must be "bundle" and (2) the plugin and configuration must be
Karl Paulsf87ac142007-07-06 22:36:17 +0000297specified (the configuration section is where you will issue
Stuart McCulloch93de6492007-12-16 15:59:05 +0000298instructions to the plugin).</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000299
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000300<h2><a name="ApacheFelixMavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000301
302<p>Consider this more real-world example using Felix' Log Service
303implementation. The Log Service project is comprised of a single
304package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on
305the core OSGi interfaces as well as a dependency on the compendium OSGi
306interfaces for the specific log service interfaces. The following is
307its POM file:</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000308
Karl Paulsf87ac142007-07-06 22:36:17 +0000309<div class="preformatted"><div class="preformattedContent">
310<pre>&lt;project&gt;
311 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
312 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
313 &lt;artifactId&gt;org.apache.felix.log&lt;/artifactId&gt;
314 &lt;packaging&gt;bundle&lt;/packaging&gt;
315 &lt;name&gt;Apache Felix Log Service&lt;/name&gt;
316 &lt;version&gt;0.8.0-SNAPSHOT&lt;/version&gt;
317 &lt;description&gt;
318 This bundle provides an implementation of the OSGi R4 Log service.
319 &lt;/description&gt;
320 &lt;dependencies&gt;
321 &lt;dependency&gt;
322 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
323 &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
324 &lt;version&gt;0.8.0-incubator&lt;/version&gt;
325 &lt;/dependency&gt;
326 &lt;dependency&gt;
327 &lt;groupId&gt;${pom.groupId}&lt;/groupId&gt;
328 &lt;artifactId&gt;org.osgi.compendium&lt;/artifactId&gt;
329 &lt;version&gt;0.9.0-incubator-SNAPSHOT&lt;/version&gt;
330 &lt;/dependency&gt;
331 &lt;/dependencies&gt;
332 &lt;build&gt;
333 &lt;plugins&gt;
334 &lt;plugin&gt;
335 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
336 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
337 &lt;extensions&gt;true&lt;/extensions&gt;
338 &lt;configuration&gt;
339 &lt;instructions&gt;
340 &lt;Export-Package&gt;org.osgi.service.log&lt;/Export-Package&gt;
341 &lt;Private-Package&gt;org.apache.felix.log.impl&lt;/Private-Package&gt;
342 &lt;Bundle-SymbolicName&gt;${pom.artifactId}&lt;/Bundle-SymbolicName&gt;
343 &lt;Bundle-Activator&gt;${pom.artifactId}.impl.Activator&lt;/Bundle-Activator&gt;
344 &lt;Export-Service&gt;org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService&lt;/Export-Service&gt;
345 &lt;/instructions&gt;
346 &lt;/configuration&gt;
347 &lt;/plugin&gt;
348 &lt;/plugins&gt;
349 &lt;/build&gt;
Karl Paulsf87ac142007-07-06 22:36:17 +0000350&lt;/project&gt;
351</pre>
352</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000353
Karl Paulsf87ac142007-07-06 22:36:17 +0000354<p>Notice that the <tt>&lt;Export-Package&gt;</tt> instruction
355specifies that the bundle exports the Log Service package, even though
356this package is not contained in the bundle project. By declaring this,
357the plugin will copy the Log Service package into the resulting bundle
358JAR file. This is useful in this case because now the bundle can
359resolve without having to download the entire compendium bundle. The
360resulting manifest for the Log Service bundle looks like this (notice
361how the imports/exports automatically have version information
362associated with them, which was obtained from packageinfo files in the
363source packages):</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000364
Karl Paulsf87ac142007-07-06 22:36:17 +0000365<div class="preformatted"><div class="preformattedContent">
366<pre>Manifest-Version: 1
367Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
368Bundle-Activator: org.apache.felix.log.impl.Activator
369Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v
370 ersion=1.3
371Include-Resource: src/main/resources
372Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version=
373 1.3
374Bundle-Version: 0.8.0.SNAPSHOT
375Bundle-Name: Apache Felix Log Service
376Bundle-Description: This bundle provides an implementation of the OSGi
377 R4 Log service.
378Private-Package: org.apache.felix.log.impl
379Bundle-ManifestVersion: 2
380Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L
381 ogReaderService
382Bundle-SymbolicName: org.apache.felix.log
383</pre>
384</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000385
Karl Paulsf87ac142007-07-06 22:36:17 +0000386<p>The resulting bundle JAR file has the following content (notice how
387the 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 +0000388
Karl Paulsf87ac142007-07-06 22:36:17 +0000389<div class="preformatted"><div class="preformattedContent">
390<pre>META-INF/MANIFEST.MF
391LICENSE
392META-INF/
393META-INF/maven/
394META-INF/maven/org.apache.felix/
395META-INF/maven/org.apache.felix/org.apache.felix.log/
396META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties
397META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml
398NOTICE
399org/
400org/apache/
401org/apache/felix/
402org/apache/felix/log/
403org/apache/felix/log/impl/
404org/apache/felix/log/impl/Activator.class
405org/apache/felix/log/impl/Log.class
406org/apache/felix/log/impl/LogEntryImpl.class
407org/apache/felix/log/impl/LogException.class
408org/apache/felix/log/impl/LogListenerThread.class
409org/apache/felix/log/impl/LogNode.class
410org/apache/felix/log/impl/LogNodeEnumeration.class
411org/apache/felix/log/impl/LogReaderServiceFactory.class
412org/apache/felix/log/impl/LogReaderServiceImpl.class
413org/apache/felix/log/impl/LogServiceFactory.class
414org/apache/felix/log/impl/LogServiceImpl.class
415org/osgi/
416org/osgi/service/
417org/osgi/service/log/
418org/osgi/service/log/LogEntry.class
419org/osgi/service/log/LogListener.class
420org/osgi/service/log/LogReaderService.class
421org/osgi/service/log/LogService.class
422org/osgi/service/log/package.html
423org/osgi/service/log/packageinfo
424</pre>
425</div></div>
426
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000427<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 +0000428
429<p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br>
430you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br>
431add this manifest to the final artifact. For example:</p>
432
433<div class="code"><div class="codeContent">
434<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
435 <span class="code-tag">&lt;artifactId&gt;</span>maven-jar-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
436 <span class="code-tag">&lt;configuration&gt;</span>
437 <span class="code-tag">&lt;archive&gt;</span>
438 <span class="code-tag">&lt;manifestFile&gt;</span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag">&lt;/manifestFile&gt;</span>
439 <span class="code-tag">&lt;/archive&gt;</span>
440 <span class="code-tag">&lt;/configuration&gt;</span>
441<span class="code-tag">&lt;/plugin&gt;</span>
442<span class="code-tag">&lt;plugin&gt;</span>
443 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
444 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
445 <span class="code-tag">&lt;executions&gt;</span>
446 <span class="code-tag">&lt;execution&gt;</span>
447 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
448 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
449 <span class="code-tag">&lt;goals&gt;</span>
450 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
451 <span class="code-tag">&lt;/goals&gt;</span>
452 <span class="code-tag">&lt;/execution&gt;</span>
453 <span class="code-tag">&lt;/executions&gt;</span>
454<span class="code-tag">&lt;/plugin&gt;</span></pre>
455</div></div>
456
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000457<p>If you want to use packaging types other than "jar" and "bundle" then you also need to enable support<br>
458for them in the bundleplugin configuration, for example if you want to use the plugin with WAR files:</p>
459
460<div class="code"><div class="codeContent">
461<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
462 <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
463 <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
464 <span class="code-tag">&lt;executions&gt;</span>
465 <span class="code-tag">&lt;execution&gt;</span>
466 <span class="code-tag">&lt;id&gt;</span>bundle-manifest<span class="code-tag">&lt;/id&gt;</span>
467 <span class="code-tag">&lt;phase&gt;</span>process-classes<span class="code-tag">&lt;/phase&gt;</span>
468 <span class="code-tag">&lt;goals&gt;</span>
469 <span class="code-tag">&lt;goal&gt;</span>manifest<span class="code-tag">&lt;/goal&gt;</span>
470 <span class="code-tag">&lt;/goals&gt;</span>
471 <span class="code-tag">&lt;/execution&gt;</span>
472 <span class="code-tag">&lt;/executions&gt;</span>
473 <span class="code-tag">&lt;configuration&gt;</span>
474 <span class="code-tag">&lt;supportedProjectTypes&gt;</span>
475 <span class="code-tag">&lt;supportedProjectType&gt;</span>jar<span class="code-tag">&lt;/supportedProjectType&gt;</span>
476 <span class="code-tag">&lt;supportedProjectType&gt;</span>bundle<span class="code-tag">&lt;/supportedProjectType&gt;</span>
477 <span class="code-tag">&lt;supportedProjectType&gt;</span>war<span class="code-tag">&lt;/supportedProjectType&gt;</span>
478 <span class="code-tag">&lt;/supportedProjectTypes&gt;</span>
479 <span class="code-tag">&lt;instructions&gt;</span>
480 <span class="code-tag"><span class="code-comment">&lt;!-- ...etc... --&gt;</span></span>
481 <span class="code-tag">&lt;/instructions&gt;</span>
482 <span class="code-tag">&lt;/configuration&gt;</span>
483<span class="code-tag">&lt;/plugin&gt;</span></pre>
484</div></div>
485
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000486<h2><a name="ApacheFelixMavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2>
Karl Paulsf87ac142007-07-06 22:36:17 +0000487
Stuart McCulloch93de6492007-12-16 15:59:05 +0000488<p>The plugin is hosted at the Apache Felix project. The following
489steps describe how to build and install the plugin into your local
490Maven2 repository.</p>
Karl Paulsf87ac142007-07-06 22:36:17 +0000491
492<p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000493
Karl Paulsf87ac142007-07-06 22:36:17 +0000494<div class="preformatted"><div class="preformattedContent">
Stuart McCulloch93de6492007-12-16 15:59:05 +0000495<pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin
Karl Paulsf87ac142007-07-06 22:36:17 +0000496</pre>
497</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000498
Karl Paulsf87ac142007-07-06 22:36:17 +0000499<p>Using Maven2, build and install the maven-bundle-plugin by issuing
500the following Maven2 command in the project directory that was created
501as a result of the previous step.</p>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000502
Karl Paulsf87ac142007-07-06 22:36:17 +0000503<div class="preformatted"><div class="preformattedContent">
504<pre>$ mvn install
505</pre>
506</div></div>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000507
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000508<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Goals"></a>Goals</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000509
510<p>The maven-bundle-plugin also provides additional functionality via
511some Maven goals. Command-line execution of a goal is performed as
512follows:</p>
513
514<div class="preformatted"><div class="preformattedContent">
515<pre>mvn org.apache.felix:maven-bundle-plugin:GOAL
516</pre>
517</div></div>
518
519<p>Where GOAL is one of the following:</p>
520
521<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000522 <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000523configuration options:
524 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000525 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
526 <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li>
Stuart McCulloch2eb61122009-02-27 06:38:33 +0000527 <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.<br>
528Version 2 of the bundleplugin now supports the same style of filter clauses in <tt>excludeDependencies</tt> as <tt>Embed-Dependency</tt>.</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000529 <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000530 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000531 </ul>
532 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000533</ul>
534
535
536<ul>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000537 <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000538configuration options:
539 <ul>
Stuart McCulloch5f3ddf72008-05-03 12:49:39 +0000540 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000541 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000542 </ul>
543 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000544</ul>
545
546
547<ul>
548 <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000549configuration options:
550 <ul>
Stuart McCulloch5f3ddf72008-05-03 12:49:39 +0000551 <li><em><tt>wrapImportPackage</tt></em> defaults to "*"</li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000552 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000553 </ul>
554 </li>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000555</ul>
556
557
558<ul>
559 <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000560configuration options:
561 <ul>
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000562 <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li>
563 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000564 </ul>
565 </li>
566</ul>
567
568
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000569<ul>
570 <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br>
571configuration options:
572 <ul>
573 <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 McCulloch1bcd7952009-02-26 21:29:51 +0000574 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000575 </ul>
576 </li>
577</ul>
578
579
580<p>More GOALs are available in the <b>1.4.0</b> release:</p>
581
582<ul>
583 <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li>
584</ul>
585
586
587<ul>
588 <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br>
589configuration options:
590 <ul>
591 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
592 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
593 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
594 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
595 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
596 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
597 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
598 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
599 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
600 </ul>
601 </li>
602</ul>
603
604
605<ul>
606 <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br>
607configuration options:
608 <ul>
609 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
610 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000611 <li><em><tt>prefixUrl</tt></em> optional public URL prefix for the remote repository</li>
612 <li><em><tt>bundleUrl</tt></em> optional public URL where the bundle has been deployed</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000613 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000614 <li><em><tt>obrDeploymentRepository</tt></em> optional OBR specific deployment repository.</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000615 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000616 <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000617 </ul>
618 </li>
619</ul>
620
621
622<ul>
623 <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br>
624configuration options:
625 <ul>
626 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li>
627 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
628 <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li>
629 <li><em><tt>url</tt></em> remote repository transport URL, like
630<div class="preformatted"><div class="preformattedContent">
631<pre>scpexe://host/path/to/obr
632</pre>
633</div></div></li>
634 <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like
635<div class="preformatted"><div class="preformattedContent">
636<pre>http://www.foo.org/bundles/foo.jar
637</pre>
638</div></div></li>
639 <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
640 <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
641 <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
642 <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
643 <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li>
644 <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li>
645 <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li>
646 <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li>
647 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
648 </ul>
649 </li>
650</ul>
651
652
653<ul>
654 <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br>
655configuration options:
656 <ul>
657 <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
658 </ul>
659 </li>
660</ul>
661
662
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000663<ul>
664 <li><b><tt>remote-clean</tt></b> - cleans a remote OBR, removing missing bundles<br>
665configuration options:
666 <ul>
667 <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote cleaning)</li>
668 <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
669 <li><em><tt>prefixUrl</tt></em> optional public URL prefix for the remote repository</li>
670 <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li>
671 <li><em><tt>obrDeploymentRepository</tt></em> optional OBR specific deployment repository.</li>
672 <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li>
673 </ul>
674 </li>
675</ul>
676
677
Stuart McCulloch93de6492007-12-16 15:59:05 +0000678<p>There are also new instructions available from the underlying BND
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000679tool, 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 +0000680
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000681<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 +0000682
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000683<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 +0000684
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000685<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000686
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000687<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 +0000688
689<div class="code"><div class="codeContent">
690<pre class="code-xml"><span class="code-tag">&lt;Embed-Dependency&gt;</span>dependencies<span class="code-tag">&lt;/Embed-Dependency&gt;</span></pre>
691</div></div>
692
693<p>where:</p>
694
695<div class="preformatted"><div class="preformattedContent">
696<pre>dependencies ::= clause ( ',' clause ) *
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000697clause ::= MATCH ( ';' attr '=' MATCH | ';inline=' inline )
Stuart McCulloch93de6492007-12-16 15:59:05 +0000698attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier'
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000699inline ::= 'true' | 'false' | PATH ( '|' PATH ) *
700MATCH ::= &lt;globbed regular expression&gt;
701PATH ::= &lt;Ant-style path expression&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000702</pre>
703</div></div>
704
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000705<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>
706clauses, which are then appended to the current set of instructions and
707passed onto BND. If you want the embedded dependencies to be at the
708start 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 +0000709
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000710<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>
711
Stuart McCulloch93de6492007-12-16 15:59:05 +0000712<p>some examples:</p>
713
714<div class="code"><div class="codeContent">
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000715<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!-- embed all compile and runtime scope dependencies --&gt;</span></span>
716<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 +0000717
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000718<span class="code-tag"><span class="code-comment">&lt;!-- embed any dependencies with artifactId junit and scope runtime --&gt;</span></span>
719<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 +0000720
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000721<span class="code-tag"><span class="code-comment">&lt;!-- inline all non-pom dependencies, except those with scope runtime --&gt;</span></span>
722<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 McCulloch3f38f732008-05-03 08:13:09 +0000723
724<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 McCulloch1bcd7952009-02-26 21:29:51 +0000725<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>
726
727<span class="code-tag"><span class="code-comment">&lt;!-- inline contents of selected folders from all dependencies --&gt;</span></span>
728<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 +0000729</div></div>
730
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000731<p>examples of using {<tt>maven-dependencies</tt>}:</p>
732
733<div class="code"><div class="codeContent">
734<pre class="code-xml"><span class="code-tag">&lt;Include-Resource&gt;</span>
735 {maven-resources}, {maven-dependencies},
736 org/foo/Example.class=target/classes/org/foo/Example.class
737<span class="code-tag">&lt;/Include-Resource&gt;</span>
738
739<span class="code-tag">&lt;Bundle-ClassPath&gt;</span>.,{maven-dependencies},some.jar<span class="code-tag">&lt;/Bundle-ClassPath&gt;</span></pre>
740</div></div>
741
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000742<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 +0000743
744<ul>
745 <li><tt>&lt;Embed-StripVersion&gt;true&lt;/Embed-StripVersion&gt;</tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li>
746 <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>
747 <li><tt>&lt;Embed-Directory&gt;directory&lt;/Embed-Directory&gt;</tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li>
748</ul>
749
750
751<p>Normally the plugin only checks direct dependencies, but this can be
752changed to include the complete set of transitive dependencies with the
753following option:</p>
754
755<div class="code"><div class="codeContent">
756<pre class="code-xml"><span class="code-tag">&lt;Embed-Transitive&gt;</span>true<span class="code-tag">&lt;/Embed-Transitive&gt;</span></pre>
757</div></div>
758
759<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>
760
761<div class="code"><div class="codeContent">
762<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>
763</div></div>
764
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000765<h3><a name="ApacheFelixMavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3>
Stuart McCulloch7c961f52008-01-02 08:56:07 +0000766
767<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>
768instructions will result in classes being inlined in the bundle, even
769though they also exist inside the embedded jar. If you want to export
770packages from an embedded dependency without such duplication then you
771can either inline the dependency, or use a new BND instruction called <tt>&lt;_exportcontents&gt;</tt>.</p>
772
773<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 +0000774
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000775<h2><a name="ApacheFelixMavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000776
777<p>The latest Maven Bundle Plugin automatically updates the local OBR
778repository.xml file during the install phase, using a default location
779of:</p>
780
781<div class="code"><div class="codeContent">
782<pre class="code-java">&lt;LOCAL-MAVEN-REPOSITORY&gt;/repository.xml</pre>
783</div></div>
784
785<p>You can configure the location of the OBR repository by using the command line:</p>
786
787<div class="code"><div class="codeContent">
788<pre class="code-java">mvn clean install -DobrRepository=&lt;PATH_TO_OBR&gt;</pre>
789</div></div>
790
791<p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p>
792
793<div class="code"><div class="codeContent">
794<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
795<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
796<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
797<span class="code-tag">&lt;configuration&gt;</span>
798 <span class="code-tag">&lt;obrRepository&gt;</span>PATH_TO_OBR<span class="code-tag">&lt;/obrRepository&gt;</span>
799 <span class="code-tag">&lt;instructions&gt;</span>
800 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
801 <span class="code-tag">&lt;/instructions&gt;</span>
802<span class="code-tag">&lt;/configuration&gt;</span></pre>
803</div></div>
804
805<p>to disable OBR installation set the obrRepository to NONE, for example:</p>
806
807<div class="code"><div class="codeContent">
808<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
809<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
810<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
811<span class="code-tag">&lt;configuration&gt;</span>
812 <span class="code-tag">&lt;obrRepository&gt;</span>NONE<span class="code-tag">&lt;/obrRepository&gt;</span>
813 <span class="code-tag">&lt;instructions&gt;</span>
814 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
815 <span class="code-tag">&lt;/instructions&gt;</span>
816<span class="code-tag">&lt;/configuration&gt;</span></pre>
817</div></div>
818
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000819<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000820
821<p>It is possible to configure the Maven Bundle Plugin to put the
822bundle manifest where Eclipse/PDE expects it, and use the Maven
823Dependency Plugin to arrange for any embedded dependencies to appear in
824a local directory that matches the Bundle-ClassPath entries. Here is an
825example POM that does this:</p>
826
827<div class="preformatted"><div class="preformattedContent">
828<pre>&lt;project&gt;
829
830 &lt;properties&gt;
831 &lt;bundle.symbolicName&gt;org.example&lt;/bundle.symbolicName&gt;
832 &lt;bundle.namespace&gt;org.example&lt;/bundle.namespace&gt;
833 &lt;/properties&gt;
834
835 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
836 &lt;groupId&gt;examples&lt;/groupId&gt;
837 &lt;artifactId&gt;org.example&lt;/artifactId&gt;
838 &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
839
840 &lt;name&gt;${bundle.symbolicName} [${bundle.namespace}]&lt;/name&gt;
841
842 &lt;packaging&gt;bundle&lt;/packaging&gt;
843
844 &lt;build&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000845 &lt;resources&gt;
846 &lt;resource&gt;
847 &lt;directory&gt;src/main/resources&lt;/directory&gt;
848 &lt;/resource&gt;
849 &lt;resource&gt;
850 &lt;directory&gt;.&lt;/directory&gt;
851 &lt;includes&gt;
852 &lt;include&gt;plugin.xml&lt;/include&gt;
853 &lt;/includes&gt;
854 &lt;/resource&gt;
855 &lt;/resources&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000856 &lt;plugins&gt;
857 &lt;plugin&gt;
858 &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
859 &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000860 &lt;version&gt;1.2.1&lt;/version&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000861 &lt;extensions&gt;true&lt;/extensions&gt;
862 &lt;!--
863 the following instructions build a simple set of public/private classes into an OSGi bundle
864 --&gt;
865 &lt;configuration&gt;
866 &lt;manifestLocation&gt;META-INF&lt;/manifestLocation&gt;
867 &lt;instructions&gt;
868 &lt;Bundle-SymbolicName&gt;${bundle.symbolicName}&lt;/Bundle-SymbolicName&gt;
869 &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
870 &lt;!--
871 assume public classes are in the top package, and private classes are under ".internal"
872 --&gt;
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000873 &lt;Export-Package&gt;!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"&lt;/Export-Package&gt;
874 &lt;Private-Package&gt;${bundle.namespace}.internal.*&lt;/Private-Package&gt;
875 &lt;Bundle-Activator&gt;${bundle.namespace}.internal.ExampleActivator&lt;/Bundle-Activator&gt;
Stuart McCulloch93de6492007-12-16 15:59:05 +0000876 &lt;!--
877 embed compile/runtime dependencies using path that matches the copied dependency folder
878 --&gt;
879 &lt;Embed-Dependency&gt;*;scope=compile|runtime;inline=false&lt;/Embed-Dependency&gt;
880 &lt;Embed-Directory&gt;target/dependency&lt;/Embed-Directory&gt;
881 &lt;Embed-StripGroup&gt;true&lt;/Embed-StripGroup&gt;
882 &lt;/instructions&gt;
883 &lt;/configuration&gt;
884 &lt;/plugin&gt;
885 &lt;plugin&gt;
886 &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
887 &lt;executions&gt;
888 &lt;execution&gt;
889 &lt;id&gt;copy-dependencies&lt;/id&gt;
890 &lt;phase&gt;package&lt;/phase&gt;
891 &lt;goals&gt;
892 &lt;goal&gt;copy-dependencies&lt;/goal&gt;
893 &lt;/goals&gt;
894 &lt;/execution&gt;
895 &lt;/executions&gt;
896 &lt;/plugin&gt;
897 &lt;/plugins&gt;
898 &lt;/build&gt;
899
900 &lt;dependencies&gt;
901 &lt;dependency&gt;
902 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
903 &lt;artifactId&gt;osgi_R4_core&lt;/artifactId&gt;
904 &lt;version&gt;1.0&lt;/version&gt;
905 &lt;scope&gt;provided&lt;/scope&gt;
906 &lt;optional&gt;true&lt;/optional&gt;
907 &lt;/dependency&gt;
908 &lt;dependency&gt;
909 &lt;groupId&gt;org.osgi&lt;/groupId&gt;
910 &lt;artifactId&gt;osgi_R4_compendium&lt;/artifactId&gt;
911 &lt;version&gt;1.0&lt;/version&gt;
912 &lt;scope&gt;provided&lt;/scope&gt;
913 &lt;optional&gt;true&lt;/optional&gt;
914 &lt;/dependency&gt;
915 &lt;dependency&gt;
916 &lt;groupId&gt;junit&lt;/groupId&gt;
917 &lt;artifactId&gt;junit&lt;/artifactId&gt;
918 &lt;version&gt;3.8.1&lt;/version&gt;
919 &lt;scope&gt;compile&lt;/scope&gt;
920 &lt;optional&gt;true&lt;/optional&gt;
921 &lt;/dependency&gt;
922 &lt;/dependencies&gt;
923
924&lt;/project&gt;
925</pre>
926</div></div>
927
928<p>To generate the Eclipse metadata use:</p>
929
930<div class="code"><div class="codeContent">
931<pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre>
932</div></div>
933
934<p>and you should now be able to import this as an existing Eclipse project.</p>
935
Stuart McCulloch1bcd7952009-02-26 21:29:51 +0000936<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 +0000937
938<p>With the original Pax-Construct generated POM you would simply use:</p>
939
940<div class="code"><div class="codeContent">
941<pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre>
942</div></div>
943
944<p>to create the appropriate Eclipse files and manifest, and also
945handle any embedded entries. The pax:eclipse goal extends
946eclipse:eclipse, and supports the same parameters.</p>
947
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000948<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000949
950<p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>,
951for example when you embed the classes from another jar. This can
952sometimes cause unforeseen problems in Maven, as it will use the output
953directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p>
954
955<p>The easiest way to get around this Maven 'feature' is to unpack the
956contents of the bundle to the output directory after the packaging
957step, so the additional classes will be found where Maven expects them.
958Thankfully there is now an easy option to do this in the bundle-plugin:</p>
959
960<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000961<pre class="code-xml"><span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
962<span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
963<span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
964<span class="code-tag">&lt;configuration&gt;</span>
965 <span class="code-tag">&lt;unpackBundle&gt;</span>true<span class="code-tag">&lt;/unpackBundle&gt;</span>
966 <span class="code-tag">&lt;instructions&gt;</span>
967 <span class="code-tag"><span class="code-comment">&lt;!-- bnd instructions --&gt;</span></span>
968 <span class="code-tag">&lt;/instructions&gt;</span>
969<span class="code-tag">&lt;/configuration&gt;</span></pre>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000970</div></div>
971
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000972<h2><a name="ApacheFelixMavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2>
Stuart McCulloch93de6492007-12-16 15:59:05 +0000973
974<p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p>
975
976<div class="code"><div class="codeContent">
Stuart McCullochdd4ae5f2008-02-05 12:38:46 +0000977<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>
978<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 +0000979</div></div>
980
981<p>Bnd will use it when calculating the bundle contents, and will also
982copy across all manifest attributes starting with a capital letter.<br>
983As shown in the above example, you could use this to include a non-OSGi
984manifest which you then customize with extra OSGi attributes.</p>
985
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000986<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 +0000987
Stuart McCulloch3f38f732008-05-03 08:13:09 +0000988<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +0000989
990<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>
991
992<p>The customized Ant script uses the BND tool to rebuild the bundle,
993so any source changes should be reflected in the (re)generated manifest.</p>
994
995<p>Example:</p>
996<div class="preformatted"><div class="preformattedContent">
997<pre>mvn ant:ant bundle:ant
998
999ant clean package
1000</pre>
1001</div></div>
1002
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001003<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001004
1005<p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p>
1006
1007<p>configuration:</p>
1008<ul>
1009 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1010 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
1011 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
1012 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
1013 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
1014 <li><em>classifier</em> Maven classifier type, defaults to none</li>
1015 <li><em>pomFile</em> optional Pom file describing the bundle</li>
1016 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
1017 <li><em>obrXml</em> optional additional properties for the bundle</li>
1018</ul>
1019
1020
1021<p>Example:</p>
1022<div class="preformatted"><div class="preformattedContent">
1023<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \
1024 -DpomFile=myPom.xml -Dfile=foo-1.0.jar
1025</pre>
1026</div></div>
1027
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001028<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001029
1030<p>The <b>deploy goal</b> updates the remote OBR with the details of
1031the deployed bundle from the local Maven repository. The remote OBR is
Stuart McCulloch1bcd7952009-02-26 21:29:51 +00001032found 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 +00001033
1034<p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p>
1035
1036<p>configuration:</p>
1037<ul>
1038 <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li>
1039 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
1040 <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li>
1041 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
1042</ul>
1043
1044
1045<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>
1046
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001047<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001048
Stuart McCulloch1bcd7952009-02-26 21:29:51 +00001049<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 +00001050
1051<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>
1052
1053<p>configuration:</p>
1054<ul>
1055 <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li>
1056 <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li>
1057 <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li>
1058 <li><em>url</em> remote repository transport URL, like
1059<div class="preformatted"><div class="preformattedContent">
1060<pre>scpexe://host/path/to/obr
1061</pre>
1062</div></div></li>
1063 <li><em>bundleUrl</em> public URL of deployed bundle, like
1064<div class="preformatted"><div class="preformattedContent">
1065<pre>http://www.foo.org/bundles/foo.jar
1066</pre>
1067</div></div></li>
1068 <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li>
1069 <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li>
1070 <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li>
1071 <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li>
1072 <li><em>classifier</em> Maven classifier type, defaults to none</li>
1073 <li><em>pomFile</em> optional Pom file describing the bundle</li>
1074 <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li>
1075 <li><em>obrXml</em> optional additional properties for the bundle</li>
1076 <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li>
1077</ul>
1078
1079
Stuart McCulloch2eb61122009-02-27 06:38:33 +00001080
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001081<p>Example:</p>
1082<div class="preformatted"><div class="preformattedContent">
1083<pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \
1084 -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \
1085 -DbundleUrl=http://www.foo.org/bundles/foo.jar
1086</pre>
1087</div></div>
1088
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001089<h2><a name="ApacheFelixMavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001090
1091<p>Sometimes you would like to clean your local OBR because it contains
1092bundles that are no longer in your local Maven repository. This case
1093often occurs when artifacts were deleted manually. The
1094maven-bundle-plugin provides a simple goal to check for missing
1095bundles, and remove them from the local OBR.</p>
1096
1097<p>configuration:</p>
1098<ul>
1099 <li><em>obrRepository</em> path to local OBR, defaults to <em>&lt;local-maven-repository&gt;</em><tt>/repository.xml</tt></li>
1100</ul>
1101
1102
1103<p>Example:</p>
1104<div class="preformatted"><div class="preformattedContent">
1105<pre>mvn bundle:clean
1106</pre>
1107</div></div>
1108
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001109<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001110
1111<p>With a remote OBR, several uploads may occur at the same time.
1112However, the remote OBR is centralized in one file, so concurrent
1113modification must be avoided. To achieve this, the plug-in implements a
1114locking system. Each time the plug-in tries to modify the file it sets
1115a file based lock. If it can't take the lock, it will wait and retry.
1116After 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>
1117
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001118<h2><a name="ApacheFelixMavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001119
1120<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>
1121<div class="code"><div class="codeContent">
1122<pre class="code-xml"><span class="code-tag">&lt;build&gt;</span>
1123 <span class="code-tag">&lt;extensions&gt;</span>
1124 <span class="code-tag">&lt;extension&gt;</span>
1125 <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.wagon<span class="code-tag">&lt;/groupId&gt;</span>
1126 <span class="code-tag">&lt;artifactId&gt;</span>wagon-ftp<span class="code-tag">&lt;/artifactId&gt;</span>
1127 <span class="code-tag">&lt;version&gt;</span>1.0-alpha-6<span class="code-tag">&lt;/version&gt;</span>
1128 <span class="code-tag">&lt;/extension&gt;</span>
1129 <span class="code-tag">&lt;/extensions&gt;</span>
1130<span class="code-tag">&lt;/build&gt;</span></pre>
1131</div></div>
1132
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001133<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 +00001134
1135<p>The description of the bundle comes from three different sources:</p>
1136<ul>
1137 <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li>
1138 <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li>
1139 <li>obr.xml : this file contains customized description and capabilities for the bundle</li>
1140</ul>
1141
1142
1143<p>These sources are merged together using the following precedence:</p>
1144<div class="preformatted"><div class="preformattedContent">
1145<pre>Bindex
1146| (overrides)
1147pom.xml
1148| (overrides)
1149obr.xml
1150</pre>
1151</div></div>
1152<p>A warning message is displayed when existing information is overridden.</p>
1153
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001154<h2><a name="ApacheFelixMavenBundlePlugin(BND)-Knownissues&amp;limitations"></a>Known issues &amp; limitations</h2>
Stuart McCulloch0340ae42008-02-22 11:27:18 +00001155
1156<ol>
1157 <li>obr.xml (file given by the user to add properties not found
1158by Bindex) must be correct, because the plug-in does not check its
1159syntax.</li>
1160</ol>
1161
1162
Stuart McCulloch3f38f732008-05-03 08:13:09 +00001163<h1><a name="ApacheFelixMavenBundlePlugin(BND)-Feedback"></a>Feedback</h1>
Stuart McCulloch93de6492007-12-16 15:59:05 +00001164
Stuart McCulloch1bcd7952009-02-26 21:29:51 +00001165<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 +00001166 </div>
Stuart McCulloche23ec842008-08-05 06:36:05 +00001167 </body></html>