Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 2 | <html><head><title>Apache Felix - Maven Bundle Plugin (BND)</title> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | <link rel="stylesheet" href="maven-bundle-plugin-bnd_files/site.css" type="text/css" media="all"> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 8 | <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head><body> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 9 | <div class="title"><div class="logo"><a href="http://felix.apache.org/site/index.html"><img alt="Apache Felix" src="maven-bundle-plugin-bnd_files/logo.png" border="0"></a></div><div class="header"><a href="http://www.apache.org/"><img alt="Apache" src="maven-bundle-plugin-bnd_files/apache.png" border="0"></a></div></div> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 10 | <div class="menu"> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 11 | <ul> |
| 12 | <li><a href="http://felix.apache.org/site/index.html" title="Index">home</a></li> |
| 13 | <li><a href="http://felix.apache.org/site/news.html" title="news">news</a></li> |
| 14 | <li><a href="http://felix.apache.org/site/status.html" title="status">status</a></li> |
| 15 | <li><a href="http://felix.apache.org/site/license.html" title="license">license</a></li> |
| 16 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li> |
| 17 | <li><a href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</a></li> |
| 18 | <li><a href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</a></li> |
| 19 | <li><span class="nobr"><a href="http://cwiki.apache.org/confluence/x/O-" title="Visit page outside Confluence" rel="nofollow">wiki<sup><img class="rendericon" src="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li> |
| 20 | <li><a href="http://felix.apache.org/site/committers.html" title="committers">committers</a></li> |
| 21 | <li><a href="http://felix.apache.org/site/faq.html" title="faq">faq</a></li> |
| 22 | <li><a href="http://felix.apache.org/site/roadmap.html" title="roadmap">roadmap</a></li> |
| 23 | <li><a href="http://felix.apache.org/site/sourcecode.html" title="sourcecode">source code</a></li> |
| 24 | <li><a href="http://felix.apache.org/site/codingstandards.html" title="codingstandards">coding standards</a></li> |
| 25 | <li><a href="http://felix.apache.org/site/issuetracking.html" title="issuetracking">issue tracking</a></li> |
| 26 | <li><a href="http://felix.apache.org/site/dependencies.html" title="dependencies">dependencies</a></li> |
| 27 | <li><span class="nobr"><a href="http://www.apache.org/" title="Visit page outside Confluence" rel="nofollow">apache software foundation<sup><img class="rendericon" src="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li> |
| 28 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li> |
| 29 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span></li> |
| 30 | </ul> </div> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 31 | <div class="main"> |
| 32 | <h1><a name="MavenBundlePlugin(BND)-BundlePluginforMaven"></a>Bundle Plugin for Maven</h1> |
| 33 | |
| 34 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> |
| 35 | tool from Peter Kriens. The way BND works is by treating your project |
| 36 | as a big collection of classes (e.g., project code, dependencies, and |
| 37 | the class path). The way you create a bundle with BND is to tell it the |
| 38 | content of the bundle's JAR file as a subset of the available classes. |
| 39 | This plugin wraps BND to make it work specifically with the Maven 2 |
| 40 | project structure and to provide it with reasonable default behavior |
| 41 | for Maven 2 projects.</p> |
| 42 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 43 | <p>Since the 1.4.0 release, this plugin also aims to automate OBR (OSGi |
| 44 | Bundle Repository) management. It helps manage a local OBR for your |
| 45 | local Maven repository, and also supports remote OBRs for bundle |
| 46 | distribution. The plug-in automatically computes bundle capabilities |
| 47 | and requirements, using a combination of Bindex and Maven metadata.</p> |
| 48 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 49 | <p><a name="MavenBundlePlugin(BND)-simpleexample"></a></p> |
| 50 | |
| 51 | <h1><a name="MavenBundlePlugin(BND)-SimpleExample"></a>Simple Example</h1> |
| 52 | |
| 53 | <p>Rather than going straight to a detailed list of plugin features, we |
| 54 | will first look at a simple example of how to use the plugin to give an |
| 55 | immediate flavor. A detailed "<a href="#MavenBundlePlugin%2528BND%2529-howto" title="how-to on Maven Bundle Plugin (BND)">how to</a>" will follow.</p> |
| 56 | |
| 57 | <p>Assume that we have a simple bundle project that has a pubic API package an several implementation packages, such as:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 58 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 59 | <div class="preformatted"><div class="preformattedContent"> |
| 60 | <pre>org.foo.myproject.api |
| 61 | org.foo.myproject.impl1 |
| 62 | org.foo.myproject.impl2 |
| 63 | ... |
| 64 | </pre> |
| 65 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 66 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 67 | <p>If we also assume that we have a bundle activator in one of the implementation packages, then the <tt><plugins></tt> section of the POM file for this bundle project would look like this:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 68 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 69 | <div class="preformatted"><div class="preformattedContent"> |
| 70 | <pre>... |
| 71 | <plugins> |
| 72 | <plugin> |
| 73 | <groupId>org.apache.felix</groupId> |
| 74 | <artifactId>maven-bundle-plugin</artifactId> |
| 75 | <extensions>true</extensions> |
| 76 | <configuration> |
| 77 | <instructions> |
| 78 | <Export-Package>org.foo.myproject.api</Export-Package> |
| 79 | <Private-Package>org.foo.myproject.*</Private-Package> |
| 80 | <Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator> |
| 81 | </instructions> |
| 82 | </configuration> |
| 83 | </plugin> |
| 84 | </plugins> |
| 85 | ... |
| 86 | </pre> |
| 87 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 88 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 89 | <p>The <tt><Export-Package></tt> and <tt><Private-Package></tt> instructions tell the plugin about the contents of the resulting bundle JAR file. The <tt><Export-Package></tt> instruction tells the plugin which of the available packages to copy into the bundle <b>and</b> export, while the <tt><Private-Package></tt> instruction indicates which of the available packages to copy into the bundle <b>but not</b> |
| 90 | export. If the two sets overlap, as they do in the case, then the |
| 91 | export takes precedence. Since we did not specify any values for any |
| 92 | other bundle manifest headers, they will assume default values which |
| 93 | are described <a href="#MavenBundlePlugin%2528BND%2529-defaultbehavior" title="default-behavior on Maven Bundle Plugin (BND)">below</a>. One specific behavior to highlight is that the plugin generates the <tt>Import-Package</tt> |
| 94 | bundle manifest header based on the contents of the bundle, which means |
| 95 | that you generally do not ever need to explicitly specify it yourself. |
| 96 | That's it.</p> |
| 97 | |
| 98 | <h1><a name="MavenBundlePlugin(BND)-Features"></a>Features</h1> |
| 99 | |
| 100 | <p>The BND library underlying the plugin defines instructions to direct |
| 101 | its behavior. For this Maven plugin, these instructions are issued in |
| 102 | the plugin configuration section of the POM file, as was illustrated <a href="#MavenBundlePlugin%2528BND%2529-simpleexample" title="simple-example on Maven Bundle Plugin (BND)">above</a>. BND recognizes three types of instructions:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 103 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 104 | <ol> |
| 105 | <li><em>Manifest headers</em> - Any instruction that starts with |
| 106 | a capital letter will appear in the resulting bundle's manifest file; |
| 107 | the value for the header will either be copied, augmented, or generated |
| 108 | by BND depending on the instruction.</li> |
| 109 | <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> |
| 110 | <li><em>Directives</em> |
| 111 | - Any instruction starting with a '-' character is considered to be a |
| 112 | directive that informs BND to perform some special processing and is |
| 113 | not copied to the manifest.</li> |
| 114 | </ol> |
| 115 | |
| 116 | |
| 117 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p> |
| 118 | |
| 119 | <p><a name="MavenBundlePlugin(BND)-instructions"></a></p> |
| 120 | |
| 121 | <h2><a name="MavenBundlePlugin(BND)-Instructions"></a>Instructions</h2> |
| 122 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 123 | <h3><a name="MavenBundlePlugin(BND)-{{<ExportPackage>}}"></a><tt><Export-Package></tt></h3> |
| 124 | |
| 125 | <p>The <tt><Export-Package></tt> instruction is a list of |
| 126 | packages for the bundle to export. These packages are copied into the |
| 127 | resulting bundle JAR file from the available classes (i.e., project |
| 128 | classes, dependencies, and class path); thus, it is possible to include |
| 129 | classes into your bundle that are not associated with source files in |
| 130 | your project. <tt><Export-Package></tt> can be specified with |
| 131 | package patterns using the '*' wildcard. Also, it is possible to |
| 132 | exclude packages using negation by starting the package pattern with |
| 133 | '!'. Thus, non-negated patterns indicate which of the available |
| 134 | packages to include in the bundle, whereas negated patterns indicate |
| 135 | which should not be included in the bundle.</p> |
| 136 | |
| 137 | <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> |
| 138 | |
| 139 | <p>Following standard OSGi R4 syntax, package patterns can include both |
| 140 | directives and attributes, which will be copied appropriately into the |
| 141 | generated Export-Package manifest header. Besides explicitly listing |
| 142 | package version attributes, BND will also determine package versions by |
| 143 | examining the source JAR file or from <tt>packageinfo</tt> files in the package directory.</p> |
| 144 | |
| 145 | <h3><a name="MavenBundlePlugin(BND)-{{<PrivatePackage>}}"></a><tt><Private-Package></tt></h3> |
| 146 | |
| 147 | <p>The <tt><Private-Package></tt> instruction is similar in every way to the <tt><Export-Package></tt> instruction, except for the fact that these packages will <b>not</b> |
| 148 | be exported by the bundle. If a package is selected by both the export |
| 149 | and private package headers, then the export takes precedence.</p> |
| 150 | |
| 151 | <h3><a name="MavenBundlePlugin(BND)-{{<IncludeResource>}}"></a><tt><Include-Resource></tt></h3> |
| 152 | |
| 153 | <p>The <tt><Include-Resource></tt> instruction is a list of |
| 154 | arbitrary resources that should be copied into the bundle JAR file. The |
| 155 | specified resources are declared as clauses that can have the following |
| 156 | forms:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 157 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 158 | <div class="preformatted"><div class="preformattedContent"> |
| 159 | <pre>clause ::= assignment | inline | simple |
| 160 | assignment ::= PATH '=' PATH |
| 161 | simple ::= PATH |
| 162 | inline ::= '@' PATH |
| 163 | </pre> |
| 164 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 165 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 166 | <p>For the <tt><Include-Resource></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> |
| 167 | form will place the resource in the bundle JAR with only the file name, |
| 168 | i.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> |
| 169 | points to a directory, the entire directory hierarchy is copied into |
| 170 | the resulting bundle JAR file relative to the specified directory. If a |
| 171 | specific resource must be placed into a subdirectory of the bundle jar, |
| 172 | then use the <tt>assignment</tt> form, where the first path is the the |
| 173 | destination path (including file name if the resource is a file) and |
| 174 | the 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> |
| 175 | |
| 176 | <p>If a resource clause is specified inside of "{ ... }" brackets, then |
| 177 | variable substitution will be performed on the resource, where |
| 178 | variables in the resources are denoted with "${ ... }" syntax.</p> |
| 179 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 180 | <p>By default the bundle plugin converts the project's Maven resource directories into a single <tt><Include-Resource></tt> instruction. If you specify your own <tt><Include-Resource></tt> instruction, this will replace the generated one. To include the generated list of Maven resources in your own <tt><Include-Resource></tt> instruction just add {<tt>maven-resources</tt>} to the list and it will be expanded automatically.</p> |
| 181 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 182 | <h3><a name="MavenBundlePlugin(BND)-{{<ImportPackage>}}"></a><tt><Import-Package></tt></h3> |
| 183 | |
| 184 | <p>The <tt><Import-Package></tt> instruction is a list of |
| 185 | packages that are required by the bundle's contained packages. The |
| 186 | default for this header is "*", resulting in importing all referred |
| 187 | packages. This header rarely has to be explicitly specified. However, |
| 188 | in certain cases when there is an unwanted import, such an import can |
| 189 | be removed by using a negation package pattern. The package patterns |
| 190 | work in the same way as for <tt><Export-Package></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> |
| 191 | |
| 192 | <p><a name="MavenBundlePlugin(BND)-defaultbehavior"></a></p> |
| 193 | |
| 194 | <h2><a name="MavenBundlePlugin(BND)-DefaultBehavior"></a>Default Behavior</h2> |
| 195 | |
| 196 | <p>To use this plugin, very little information is required by BND. As |
| 197 | part of the Maven integration, the plugin tries to set reasonable |
| 198 | defaults for various instructions. For example:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 199 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 200 | <ul> |
| 201 | <li><tt><Bundle-SymbolicName></tt> is assumed to be "<tt>${groupId}.${artifactId</tt>}".</li> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 202 | <li><tt><Export-Package></tt> is assumed to be "<tt><Bundle-SymbolicName>.*</tt>", unless <tt><Private-Package></tt> is specified, then <tt><Export-Package></tt> is assumed to be empty.</li> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 203 | <li><tt><Private-Package></tt> is assumed to be empty by default.</li> |
| 204 | <li><tt><Import-Package></tt> is assumed to be "<tt>*</tt>", which imports everything referred to by the bundle content, but not contained in the bundle.</li> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 205 | <li><tt><Include-Resource></tt> is generated from the project's Maven resources, typically "<tt>src/main/resources/</tt>", |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 206 | which will copy the specified project directory hierarchy into the |
| 207 | resulting bundle JAR file, mirroring standard Maven behavior.</li> |
| 208 | <li><tt><Bundle-Version></tt> is assumed to be "<tt>${pom.version</tt>}" with '-' character separator of the qualifier replaced with a '.' character.</li> |
| 209 | <li><tt><Bundle-Name></tt> is assumed to be "<tt>${pom.name</tt>}".</li> |
| 210 | <li><tt><Bundle-Description></tt> is assumed to be "<tt>${pom.description</tt>}".</li> |
| 211 | <li><tt><Bundle-License></tt> is assumed to be "<tt>${pom.licenses</tt>}".</li> |
| 212 | <li><tt><Bundle-Vendor></tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li> |
| 213 | <li><tt><Bundle-DocURL></tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li> |
| 214 | </ul> |
| 215 | |
| 216 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 217 | <p>Since the plugin creates bundles for OSGi R4, it hard-codes <tt>Bundle-ManifestVersion</tt> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 218 | to be '2'. Additionally, it generates imports for every export to |
| 219 | ensure package substitutability, which is very important when working |
| 220 | with collaborating services. It is possible to override any of these |
| 221 | values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p> |
| 222 | |
| 223 | <p><a name="MavenBundlePlugin(BND)-howto"></a></p> |
| 224 | |
| 225 | <h1><a name="MavenBundlePlugin(BND)-Detailed"HowTo""></a>Detailed "How To"</h1> |
| 226 | |
| 227 | <h2><a name="MavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2> |
| 228 | |
| 229 | <p>The first step in the process of using the plugin is downloading and |
| 230 | installing the latest version of the Maven2 runtime. The latest Maven2 |
| 231 | release and instuctions for getting started with Maven2 can be found at |
| 232 | the <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p> |
| 233 | |
| 234 | <h2><a name="MavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2> |
| 235 | |
| 236 | <p>To use the maven-bundle-plugin, you first need to add the plugin and |
| 237 | some appropriate plugin configuration to your bundle project's POM. |
| 238 | Below is an example of a simple OSGi bundle POM for Maven2:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 239 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 240 | <div class="preformatted"><div class="preformattedContent"> |
| 241 | <pre><project> |
| 242 | <modelVersion>4.0.0</modelVersion> |
| 243 | <groupId>my-osgi-bundles</groupId> |
| 244 | <artifactId>examplebundle</artifactId> |
| 245 | <packaging>bundle</packaging> <!-- (1) --> |
| 246 | <version>1.0</version> |
| 247 | <name>Example Bundle</name> |
| 248 | <dependencies> |
| 249 | <dependency> |
| 250 | <groupId>org.apache.felix</groupId> |
| 251 | <artifactId>org.osgi.core</artifactId> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 252 | <version>1.0.0</version> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 253 | </dependency> |
| 254 | </dependencies> |
| 255 | <build> |
| 256 | <plugins> |
| 257 | <plugin> <!-- (2) START --> |
| 258 | <groupId>org.apache.felix</groupId> |
| 259 | <artifactId>maven-bundle-plugin</artifactId> |
| 260 | <extensions>true</extensions> |
| 261 | <configuration> |
| 262 | <instructions> |
| 263 | <Export-Package>com.my.company.api</Export-Package> |
| 264 | <Private-Package>com.my.company.*</Private-Package> |
| 265 | <Bundle-Activator>com.my.company.Activator</Bundle-Activator> |
| 266 | </instructions> |
| 267 | </configuration> |
| 268 | </plugin> <!-- (2) END --> |
| 269 | </plugins> |
| 270 | </build> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 271 | </project> |
| 272 | </pre> |
| 273 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 274 | |
| 275 | <p>There are two main things to note: (1) the <tt><packaging></tt> |
| 276 | specifier must be "bundle" and (2) the plugin and configuration must be |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 277 | specified (the configuration section is where you will issue |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 278 | instructions to the plugin).</p> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 279 | |
| 280 | <h2><a name="MavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2> |
| 281 | |
| 282 | <p>Consider this more real-world example using Felix' Log Service |
| 283 | implementation. The Log Service project is comprised of a single |
| 284 | package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on |
| 285 | the core OSGi interfaces as well as a dependency on the compendium OSGi |
| 286 | interfaces for the specific log service interfaces. The following is |
| 287 | its POM file:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 288 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 289 | <div class="preformatted"><div class="preformattedContent"> |
| 290 | <pre><project> |
| 291 | <modelVersion>4.0.0</modelVersion> |
| 292 | <groupId>org.apache.felix</groupId> |
| 293 | <artifactId>org.apache.felix.log</artifactId> |
| 294 | <packaging>bundle</packaging> |
| 295 | <name>Apache Felix Log Service</name> |
| 296 | <version>0.8.0-SNAPSHOT</version> |
| 297 | <description> |
| 298 | This bundle provides an implementation of the OSGi R4 Log service. |
| 299 | </description> |
| 300 | <dependencies> |
| 301 | <dependency> |
| 302 | <groupId>${pom.groupId}</groupId> |
| 303 | <artifactId>org.osgi.core</artifactId> |
| 304 | <version>0.8.0-incubator</version> |
| 305 | </dependency> |
| 306 | <dependency> |
| 307 | <groupId>${pom.groupId}</groupId> |
| 308 | <artifactId>org.osgi.compendium</artifactId> |
| 309 | <version>0.9.0-incubator-SNAPSHOT</version> |
| 310 | </dependency> |
| 311 | </dependencies> |
| 312 | <build> |
| 313 | <plugins> |
| 314 | <plugin> |
| 315 | <groupId>org.apache.felix</groupId> |
| 316 | <artifactId>maven-bundle-plugin</artifactId> |
| 317 | <extensions>true</extensions> |
| 318 | <configuration> |
| 319 | <instructions> |
| 320 | <Export-Package>org.osgi.service.log</Export-Package> |
| 321 | <Private-Package>org.apache.felix.log.impl</Private-Package> |
| 322 | <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> |
| 323 | <Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator> |
| 324 | <Export-Service>org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService</Export-Service> |
| 325 | </instructions> |
| 326 | </configuration> |
| 327 | </plugin> |
| 328 | </plugins> |
| 329 | </build> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 330 | </project> |
| 331 | </pre> |
| 332 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 333 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 334 | <p>Notice that the <tt><Export-Package></tt> instruction |
| 335 | specifies that the bundle exports the Log Service package, even though |
| 336 | this package is not contained in the bundle project. By declaring this, |
| 337 | the plugin will copy the Log Service package into the resulting bundle |
| 338 | JAR file. This is useful in this case because now the bundle can |
| 339 | resolve without having to download the entire compendium bundle. The |
| 340 | resulting manifest for the Log Service bundle looks like this (notice |
| 341 | how the imports/exports automatically have version information |
| 342 | associated with them, which was obtained from packageinfo files in the |
| 343 | source packages):</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 344 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 345 | <div class="preformatted"><div class="preformattedContent"> |
| 346 | <pre>Manifest-Version: 1 |
| 347 | Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt |
| 348 | Bundle-Activator: org.apache.felix.log.impl.Activator |
| 349 | Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v |
| 350 | ersion=1.3 |
| 351 | Include-Resource: src/main/resources |
| 352 | Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version= |
| 353 | 1.3 |
| 354 | Bundle-Version: 0.8.0.SNAPSHOT |
| 355 | Bundle-Name: Apache Felix Log Service |
| 356 | Bundle-Description: This bundle provides an implementation of the OSGi |
| 357 | R4 Log service. |
| 358 | Private-Package: org.apache.felix.log.impl |
| 359 | Bundle-ManifestVersion: 2 |
| 360 | Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L |
| 361 | ogReaderService |
| 362 | Bundle-SymbolicName: org.apache.felix.log |
| 363 | </pre> |
| 364 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 365 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 366 | <p>The resulting bundle JAR file has the following content (notice how |
| 367 | the LICENSE and NOTICE files were automatically copied from the <tt>src/main/resources/</tt> directory of the project):</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 368 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 369 | <div class="preformatted"><div class="preformattedContent"> |
| 370 | <pre>META-INF/MANIFEST.MF |
| 371 | LICENSE |
| 372 | META-INF/ |
| 373 | META-INF/maven/ |
| 374 | META-INF/maven/org.apache.felix/ |
| 375 | META-INF/maven/org.apache.felix/org.apache.felix.log/ |
| 376 | META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties |
| 377 | META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml |
| 378 | NOTICE |
| 379 | org/ |
| 380 | org/apache/ |
| 381 | org/apache/felix/ |
| 382 | org/apache/felix/log/ |
| 383 | org/apache/felix/log/impl/ |
| 384 | org/apache/felix/log/impl/Activator.class |
| 385 | org/apache/felix/log/impl/Log.class |
| 386 | org/apache/felix/log/impl/LogEntryImpl.class |
| 387 | org/apache/felix/log/impl/LogException.class |
| 388 | org/apache/felix/log/impl/LogListenerThread.class |
| 389 | org/apache/felix/log/impl/LogNode.class |
| 390 | org/apache/felix/log/impl/LogNodeEnumeration.class |
| 391 | org/apache/felix/log/impl/LogReaderServiceFactory.class |
| 392 | org/apache/felix/log/impl/LogReaderServiceImpl.class |
| 393 | org/apache/felix/log/impl/LogServiceFactory.class |
| 394 | org/apache/felix/log/impl/LogServiceImpl.class |
| 395 | org/osgi/ |
| 396 | org/osgi/service/ |
| 397 | org/osgi/service/log/ |
| 398 | org/osgi/service/log/LogEntry.class |
| 399 | org/osgi/service/log/LogListener.class |
| 400 | org/osgi/service/log/LogReaderService.class |
| 401 | org/osgi/service/log/LogService.class |
| 402 | org/osgi/service/log/package.html |
| 403 | org/osgi/service/log/packageinfo |
| 404 | </pre> |
| 405 | </div></div> |
| 406 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 407 | <h2><a name="MavenBundlePlugin(BND)-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype"></a>Adding OSGi metadata to existing projects without changing the packaging type</h2> |
| 408 | |
| 409 | <p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br> |
| 410 | you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br> |
| 411 | add this manifest to the final artifact. For example:</p> |
| 412 | |
| 413 | <div class="code"><div class="codeContent"> |
| 414 | <pre class="code-xml"><span class="code-tag"><plugin></span> |
| 415 | <span class="code-tag"><artifactId></span>maven-jar-plugin<span class="code-tag"></artifactId></span> |
| 416 | <span class="code-tag"><configuration></span> |
| 417 | <span class="code-tag"><archive></span> |
| 418 | <span class="code-tag"><manifestFile></span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag"></manifestFile></span> |
| 419 | <span class="code-tag"></archive></span> |
| 420 | <span class="code-tag"></configuration></span> |
| 421 | <span class="code-tag"></plugin></span> |
| 422 | <span class="code-tag"><plugin></span> |
| 423 | <span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 424 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 425 | <span class="code-tag"><executions></span> |
| 426 | <span class="code-tag"><execution></span> |
| 427 | <span class="code-tag"><id></span>bundle-manifest<span class="code-tag"></id></span> |
| 428 | <span class="code-tag"><phase></span>process-classes<span class="code-tag"></phase></span> |
| 429 | <span class="code-tag"><goals></span> |
| 430 | <span class="code-tag"><goal></span>manifest<span class="code-tag"></goal></span> |
| 431 | <span class="code-tag"></goals></span> |
| 432 | <span class="code-tag"></execution></span> |
| 433 | <span class="code-tag"></executions></span> |
| 434 | <span class="code-tag"></plugin></span></pre> |
| 435 | </div></div> |
| 436 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 437 | <h2><a name="MavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2> |
| 438 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 439 | <p>The plugin is hosted at the Apache Felix project. The following |
| 440 | steps describe how to build and install the plugin into your local |
| 441 | Maven2 repository.</p> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 442 | |
| 443 | <p>Using the SVN client of your choice, checkout the maven-bundle-plugin project.</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 444 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 445 | <div class="preformatted"><div class="preformattedContent"> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 446 | <pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 447 | </pre> |
| 448 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 449 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 450 | <p>Using Maven2, build and install the maven-bundle-plugin by issuing |
| 451 | the following Maven2 command in the project directory that was created |
| 452 | as a result of the previous step.</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 453 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 454 | <div class="preformatted"><div class="preformattedContent"> |
| 455 | <pre>$ mvn install |
| 456 | </pre> |
| 457 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 458 | |
| 459 | <h1><a name="MavenBundlePlugin(BND)-Goals"></a>Goals</h1> |
| 460 | |
| 461 | <p>The maven-bundle-plugin also provides additional functionality via |
| 462 | some Maven goals. Command-line execution of a goal is performed as |
| 463 | follows:</p> |
| 464 | |
| 465 | <div class="preformatted"><div class="preformattedContent"> |
| 466 | <pre>mvn org.apache.felix:maven-bundle-plugin:GOAL |
| 467 | </pre> |
| 468 | </div></div> |
| 469 | |
| 470 | <p>Where GOAL is one of the following:</p> |
| 471 | |
| 472 | <ul> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 473 | <li><b><tt>bundle</tt></b> - build an OSGi bundle jar for the current project<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 474 | configuration options: |
| 475 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 476 | <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li> |
| 477 | <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 478 | <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 McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 479 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 480 | <li><em><tt>classifier</tt></em> attach bundle to the project using the given classifier</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 481 | </ul> |
| 482 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 483 | </ul> |
| 484 | |
| 485 | |
| 486 | <ul> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 487 | <li><b><tt>bundleall</tt></b> - build OSGi bundle jars for all transitive dependencies<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 488 | configuration options: |
| 489 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 490 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 491 | </ul> |
| 492 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 493 | </ul> |
| 494 | |
| 495 | |
| 496 | <ul> |
| 497 | <li><b><tt>wrap</tt></b> - as above, but limited to the first level of dependencies<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 498 | configuration options: |
| 499 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 500 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 501 | </ul> |
| 502 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 503 | </ul> |
| 504 | |
| 505 | |
| 506 | <ul> |
| 507 | <li><b><tt>manifest</tt></b> - create an OSGi manifest for the current project<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 508 | configuration options: |
| 509 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 510 | <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li> |
| 511 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 512 | </ul> |
| 513 | </li> |
| 514 | </ul> |
| 515 | |
| 516 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 517 | <ul> |
| 518 | <li><b><tt>install</tt></b> - adds the current bundle project to the local OBR<br> |
| 519 | configuration options: |
| 520 | <ul> |
| 521 | <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em><local-maven-repository></em><tt>/repository.xml</tt></li> |
| 522 | </ul> |
| 523 | </li> |
| 524 | </ul> |
| 525 | |
| 526 | |
| 527 | <p>More GOALs are available in the <b>1.4.0</b> release:</p> |
| 528 | |
| 529 | <ul> |
| 530 | <li><b><tt>ant</tt></b> - create an Ant build script to rebuild the bundle</li> |
| 531 | </ul> |
| 532 | |
| 533 | |
| 534 | <ul> |
| 535 | <li><b><tt>install-file</tt></b> - adds a local bundle file to the local OBR<br> |
| 536 | configuration options: |
| 537 | <ul> |
| 538 | <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em><local-maven-repository></em><tt>/repository.xml</tt></li> |
| 539 | <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li> |
| 540 | <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li> |
| 541 | <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li> |
| 542 | <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li> |
| 543 | <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li> |
| 544 | <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li> |
| 545 | <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li> |
| 546 | <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li> |
| 547 | </ul> |
| 548 | </li> |
| 549 | </ul> |
| 550 | |
| 551 | |
| 552 | <ul> |
| 553 | <li><b><tt>deploy</tt></b> - adds the current bundle project to a remote OBR<br> |
| 554 | configuration options: |
| 555 | <ul> |
| 556 | <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li> |
| 557 | <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li> |
| 558 | <li><em><tt>altDeploymentRepository</tt></em> alternative remote repository, <em>id::layout::url</em></li> |
| 559 | <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li> |
| 560 | </ul> |
| 561 | </li> |
| 562 | </ul> |
| 563 | |
| 564 | |
| 565 | <ul> |
| 566 | <li><b><tt>deploy-file</tt></b> - adds a local bundle file to a remote OBR<br> |
| 567 | configuration options: |
| 568 | <ul> |
| 569 | <li><em><tt>remoteOBR</tt></em> name of remote OBR, defaults to an empty string</li> |
| 570 | <li><em><tt>obrRepository</tt></em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li> |
| 571 | <li><em><tt>repositoryId</tt></em> optional repository id, used to lookup authentication settings</li> |
| 572 | <li><em><tt>url</tt></em> remote repository transport URL, like |
| 573 | <div class="preformatted"><div class="preformattedContent"> |
| 574 | <pre>scpexe://host/path/to/obr |
| 575 | </pre> |
| 576 | </div></div></li> |
| 577 | <li><em><tt>bundleUrl</tt></em> public URL of deployed bundle, like |
| 578 | <div class="preformatted"><div class="preformattedContent"> |
| 579 | <pre>http://www.foo.org/bundles/foo.jar |
| 580 | </pre> |
| 581 | </div></div></li> |
| 582 | <li><em><tt>groupId</tt></em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li> |
| 583 | <li><em><tt>artifactId</tt></em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li> |
| 584 | <li><em><tt>version</tt></em> Maven version for the bundle, taken from <em>pomFile</em> if given</li> |
| 585 | <li><em><tt>packaging</tt></em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li> |
| 586 | <li><em><tt>classifier</tt></em> Maven classifier type, defaults to none</li> |
| 587 | <li><em><tt>pomFile</tt></em> optional Pom file describing the bundle</li> |
| 588 | <li><em><tt>file</tt></em> bundle file, defaults to the bundle from the local Maven repository</li> |
| 589 | <li><em><tt>obrXml</tt></em> optional additional properties for the bundle</li> |
| 590 | <li><em><tt>ignoreLock</tt></em> ignore remote locking when updating the OBR</li> |
| 591 | </ul> |
| 592 | </li> |
| 593 | </ul> |
| 594 | |
| 595 | |
| 596 | <ul> |
| 597 | <li><b><tt>clean</tt></b> - cleans the local OBR, removing missing bundles<br> |
| 598 | configuration options: |
| 599 | <ul> |
| 600 | <li><em><tt>obrRepository</tt></em> path to local OBR, defaults to <em><local-maven-repository></em><tt>/repository.xml</tt></li> |
| 601 | </ul> |
| 602 | </li> |
| 603 | </ul> |
| 604 | |
| 605 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 606 | <p>There are also new instructions available from the underlying BND |
| 607 | tool, 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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span>.</p> |
| 608 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 609 | <p>The default goal <b><tt>bundle</tt></b> will be initialized by setting the <packaging> entry to "bundle".</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 610 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 611 | <h1><a name="MavenBundlePlugin(BND)-Thefollowingfeaturesareonlyavailablefromversion1.2.0onwards"></a>The following features are only available from version 1.2.0 onwards</h1> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 612 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 613 | <h2><a name="MavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 614 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 615 | <p>The Maven Bundle Plugin supports embedding of selected project dependencies inside the bundle by using the <tt><Embed-Dependency></tt> instruction:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 616 | |
| 617 | <div class="code"><div class="codeContent"> |
| 618 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>dependencies<span class="code-tag"></Embed-Dependency></span></pre> |
| 619 | </div></div> |
| 620 | |
| 621 | <p>where:</p> |
| 622 | |
| 623 | <div class="preformatted"><div class="preformattedContent"> |
| 624 | <pre>dependencies ::= clause ( ',' clause ) * |
| 625 | clause ::= MATCH ( ';' attr '=' MATCH | ';inline=true' ) |
| 626 | attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier' |
| 627 | MATCH ::= <globbed regular expressions> |
| 628 | </pre> |
| 629 | </div></div> |
| 630 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 631 | <p>The plugin uses the <tt><Embed-Dependency></tt> instruction to transform the project dependencies into <tt><Include-Resource></tt> and <tt><Bundle-ClassPath></tt> |
| 632 | clauses, which are then appended to the current set of instructions and |
| 633 | passed onto BND. If you want the embedded dependencies to be at the |
| 634 | start or middle of <tt><Include-Resource></tt> or <tt><Bundle-ClassPath></tt> then you can use {<tt>maven-dependencies</tt>}, which will automatically expand to the relevant clauses.</p> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 635 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 636 | <p>some examples:</p> |
| 637 | |
| 638 | <div class="code"><div class="codeContent"> |
| 639 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>*;scope=compile|runtime<span class="code-tag"></Embed-Dependency></span> |
| 640 | |
| 641 | <span class="code-tag"><Embed-Dependency></span>junit;scope=test<span class="code-tag"></Embed-Dependency></span> |
| 642 | |
| 643 | <span class="code-tag"><Embed-Dependency></span>aopalliance;scope=!test;inline=true<span class="code-tag"></Embed-Dependency></span></pre> |
| 644 | </div></div> |
| 645 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 646 | <p>examples of using {<tt>maven-dependencies</tt>}:</p> |
| 647 | |
| 648 | <div class="code"><div class="codeContent"> |
| 649 | <pre class="code-xml"><span class="code-tag"><Include-Resource></span> |
| 650 | {maven-resources}, {maven-dependencies}, |
| 651 | org/foo/Example.class=target/classes/org/foo/Example.class |
| 652 | <span class="code-tag"></Include-Resource></span> |
| 653 | |
| 654 | <span class="code-tag"><Bundle-ClassPath></span>.,{maven-dependencies},some.jar<span class="code-tag"></Bundle-ClassPath></span></pre> |
| 655 | </div></div> |
| 656 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 657 | <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 McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 658 | |
| 659 | <ul> |
| 660 | <li><tt><Embed-StripVersion>true</Embed-StripVersion></tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li> |
| 661 | <li><tt><Embed-StripGroup>false</Embed-StripGroup></tt> - adds the groupId as a subdirectory (ie. <em>groupId/artifactId-version.jar</em>)</li> |
| 662 | <li><tt><Embed-Directory>directory</Embed-Directory></tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li> |
| 663 | </ul> |
| 664 | |
| 665 | |
| 666 | <p>Normally the plugin only checks direct dependencies, but this can be |
| 667 | changed to include the complete set of transitive dependencies with the |
| 668 | following option:</p> |
| 669 | |
| 670 | <div class="code"><div class="codeContent"> |
| 671 | <pre class="code-xml"><span class="code-tag"><Embed-Transitive></span>true<span class="code-tag"></Embed-Transitive></span></pre> |
| 672 | </div></div> |
| 673 | |
| 674 | <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> |
| 675 | |
| 676 | <div class="code"><div class="codeContent"> |
| 677 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>*;scope=compile|runtime;inline=true<span class="code-tag"></Embed-Dependency></span></pre> |
| 678 | </div></div> |
| 679 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 680 | <h3><a name="MavenBundlePlugin(BND)-EmbedDependencyandExportPackage"></a>Embed-Dependency and Export-Package</h3> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 681 | |
| 682 | <p>If you embed a dependency with <tt><Embed-Dependency></tt>, and your <tt><Export-Package></tt> or <tt><Private-Package></tt> instructions match packages inside the embedded jar, you will see some duplication inside the bundle. This is because the <tt><Export-Package></tt> and <tt><Private-Package></tt> |
| 683 | instructions will result in classes being inlined in the bundle, even |
| 684 | though they also exist inside the embedded jar. If you want to export |
| 685 | packages from an embedded dependency without such duplication then you |
| 686 | can either inline the dependency, or use a new BND instruction called <tt><_exportcontents></tt>.</p> |
| 687 | |
| 688 | <p><tt><_exportcontents></tt> behaves just like Export-Package, except it doesn't change the content of the bundle, just what content should be exported.</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 689 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 690 | <h2><a name="MavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 691 | |
| 692 | <p>The latest Maven Bundle Plugin automatically updates the local OBR |
| 693 | repository.xml file during the install phase, using a default location |
| 694 | of:</p> |
| 695 | |
| 696 | <div class="code"><div class="codeContent"> |
| 697 | <pre class="code-java"><LOCAL-MAVEN-REPOSITORY>/repository.xml</pre> |
| 698 | </div></div> |
| 699 | |
| 700 | <p>You can configure the location of the OBR repository by using the command line:</p> |
| 701 | |
| 702 | <div class="code"><div class="codeContent"> |
| 703 | <pre class="code-java">mvn clean install -DobrRepository=<PATH_TO_OBR></pre> |
| 704 | </div></div> |
| 705 | |
| 706 | <p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p> |
| 707 | |
| 708 | <div class="code"><div class="codeContent"> |
| 709 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 710 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 711 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 712 | <span class="code-tag"><configuration></span> |
| 713 | <span class="code-tag"><obrRepository></span>PATH_TO_OBR<span class="code-tag"></obrRepository></span> |
| 714 | <span class="code-tag"><instructions></span> |
| 715 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 716 | <span class="code-tag"></instructions></span> |
| 717 | <span class="code-tag"></configuration></span></pre> |
| 718 | </div></div> |
| 719 | |
| 720 | <p>to disable OBR installation set the obrRepository to NONE, for example:</p> |
| 721 | |
| 722 | <div class="code"><div class="codeContent"> |
| 723 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 724 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 725 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 726 | <span class="code-tag"><configuration></span> |
| 727 | <span class="code-tag"><obrRepository></span>NONE<span class="code-tag"></obrRepository></span> |
| 728 | <span class="code-tag"><instructions></span> |
| 729 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 730 | <span class="code-tag"></instructions></span> |
| 731 | <span class="code-tag"></configuration></span></pre> |
| 732 | </div></div> |
| 733 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 734 | <h2><a name="MavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 735 | |
| 736 | <p>It is possible to configure the Maven Bundle Plugin to put the |
| 737 | bundle manifest where Eclipse/PDE expects it, and use the Maven |
| 738 | Dependency Plugin to arrange for any embedded dependencies to appear in |
| 739 | a local directory that matches the Bundle-ClassPath entries. Here is an |
| 740 | example POM that does this:</p> |
| 741 | |
| 742 | <div class="preformatted"><div class="preformattedContent"> |
| 743 | <pre><project> |
| 744 | |
| 745 | <properties> |
| 746 | <bundle.symbolicName>org.example</bundle.symbolicName> |
| 747 | <bundle.namespace>org.example</bundle.namespace> |
| 748 | </properties> |
| 749 | |
| 750 | <modelVersion>4.0.0</modelVersion> |
| 751 | <groupId>examples</groupId> |
| 752 | <artifactId>org.example</artifactId> |
| 753 | <version>1.0-SNAPSHOT</version> |
| 754 | |
| 755 | <name>${bundle.symbolicName} [${bundle.namespace}]</name> |
| 756 | |
| 757 | <packaging>bundle</packaging> |
| 758 | |
| 759 | <build> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 760 | <resources> |
| 761 | <resource> |
| 762 | <directory>src/main/resources</directory> |
| 763 | </resource> |
| 764 | <resource> |
| 765 | <directory>.</directory> |
| 766 | <includes> |
| 767 | <include>plugin.xml</include> |
| 768 | </includes> |
| 769 | </resource> |
| 770 | </resources> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 771 | <plugins> |
| 772 | <plugin> |
| 773 | <groupId>org.apache.felix</groupId> |
| 774 | <artifactId>maven-bundle-plugin</artifactId> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 775 | <version>1.2.1</version> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 776 | <extensions>true</extensions> |
| 777 | <!-- |
| 778 | the following instructions build a simple set of public/private classes into an OSGi bundle |
| 779 | --> |
| 780 | <configuration> |
| 781 | <manifestLocation>META-INF</manifestLocation> |
| 782 | <instructions> |
| 783 | <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> |
| 784 | <Bundle-Version>${pom.version}</Bundle-Version> |
| 785 | <!-- |
| 786 | assume public classes are in the top package, and private classes are under ".internal" |
| 787 | --> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 788 | <Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"</Export-Package> |
| 789 | <Private-Package>${bundle.namespace}.internal.*</Private-Package> |
| 790 | <Bundle-Activator>${bundle.namespace}.internal.ExampleActivator</Bundle-Activator> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 791 | <!-- |
| 792 | embed compile/runtime dependencies using path that matches the copied dependency folder |
| 793 | --> |
| 794 | <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> |
| 795 | <Embed-Directory>target/dependency</Embed-Directory> |
| 796 | <Embed-StripGroup>true</Embed-StripGroup> |
| 797 | </instructions> |
| 798 | </configuration> |
| 799 | </plugin> |
| 800 | <plugin> |
| 801 | <artifactId>maven-dependency-plugin</artifactId> |
| 802 | <executions> |
| 803 | <execution> |
| 804 | <id>copy-dependencies</id> |
| 805 | <phase>package</phase> |
| 806 | <goals> |
| 807 | <goal>copy-dependencies</goal> |
| 808 | </goals> |
| 809 | </execution> |
| 810 | </executions> |
| 811 | </plugin> |
| 812 | </plugins> |
| 813 | </build> |
| 814 | |
| 815 | <dependencies> |
| 816 | <dependency> |
| 817 | <groupId>org.osgi</groupId> |
| 818 | <artifactId>osgi_R4_core</artifactId> |
| 819 | <version>1.0</version> |
| 820 | <scope>provided</scope> |
| 821 | <optional>true</optional> |
| 822 | </dependency> |
| 823 | <dependency> |
| 824 | <groupId>org.osgi</groupId> |
| 825 | <artifactId>osgi_R4_compendium</artifactId> |
| 826 | <version>1.0</version> |
| 827 | <scope>provided</scope> |
| 828 | <optional>true</optional> |
| 829 | </dependency> |
| 830 | <dependency> |
| 831 | <groupId>junit</groupId> |
| 832 | <artifactId>junit</artifactId> |
| 833 | <version>3.8.1</version> |
| 834 | <scope>compile</scope> |
| 835 | <optional>true</optional> |
| 836 | </dependency> |
| 837 | </dependencies> |
| 838 | |
| 839 | </project> |
| 840 | </pre> |
| 841 | </div></div> |
| 842 | |
| 843 | <p>To generate the Eclipse metadata use:</p> |
| 844 | |
| 845 | <div class="code"><div class="codeContent"> |
| 846 | <pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre> |
| 847 | </div></div> |
| 848 | |
| 849 | <p>and you should now be able to import this as an existing Eclipse project.</p> |
| 850 | |
| 851 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> and then tweaked to demonstrate using the Maven Dependency Plugin to handle embedded jars in Eclipse.</p> |
| 852 | |
| 853 | <p>With the original Pax-Construct generated POM you would simply use:</p> |
| 854 | |
| 855 | <div class="code"><div class="codeContent"> |
| 856 | <pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre> |
| 857 | </div></div> |
| 858 | |
| 859 | <p>to create the appropriate Eclipse files and manifest, and also |
| 860 | handle any embedded entries. The pax:eclipse goal extends |
| 861 | eclipse:eclipse, and supports the same parameters.</p> |
| 862 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 863 | <h2><a name="MavenBundlePlugin(BND)-Unpackingbundlecontentsto'target/classes'"></a>Unpacking bundle contents to 'target/classes'</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 864 | |
| 865 | <p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>, |
| 866 | for example when you embed the classes from another jar. This can |
| 867 | sometimes cause unforeseen problems in Maven, as it will use the output |
| 868 | directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p> |
| 869 | |
| 870 | <p>The easiest way to get around this Maven 'feature' is to unpack the |
| 871 | contents of the bundle to the output directory after the packaging |
| 872 | step, so the additional classes will be found where Maven expects them. |
| 873 | Thankfully there is now an easy option to do this in the bundle-plugin:</p> |
| 874 | |
| 875 | <div class="code"><div class="codeContent"> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 876 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 877 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 878 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 879 | <span class="code-tag"><configuration></span> |
| 880 | <span class="code-tag"><unpackBundle></span>true<span class="code-tag"></unpackBundle></span> |
| 881 | <span class="code-tag"><instructions></span> |
| 882 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 883 | <span class="code-tag"></instructions></span> |
| 884 | <span class="code-tag"></configuration></span></pre> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 885 | </div></div> |
| 886 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 887 | <h2><a name="MavenBundlePlugin(BND)-UsinganexistingMANIFEST.MFfile"></a>Using an existing MANIFEST.MF file</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 888 | |
| 889 | <p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p> |
| 890 | |
| 891 | <div class="code"><div class="codeContent"> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame] | 892 | <pre class="code-xml"><span class="code-tag"><_include></span>src/main/resources/META-INF/MANIFEST.MF<span class="code-tag"></_include></span> |
| 893 | <span class="code-tag"><Export-Package></span>org.example.*<span class="code-tag"></Export-Package></span></pre> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 894 | </div></div> |
| 895 | |
| 896 | <p>Bnd will use it when calculating the bundle contents, and will also |
| 897 | copy across all manifest attributes starting with a capital letter.<br> |
| 898 | As shown in the above example, you could use this to include a non-OSGi |
| 899 | manifest which you then customize with extra OSGi attributes.</p> |
| 900 | |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 901 | <h1><a name="MavenBundlePlugin(BND)-Thefollowingfeaturesareonlyavailablefromversion1.4.0onwards"></a>The following features are only available from version 1.4.0 onwards</h1> |
| 902 | |
| 903 | <h2><a name="MavenBundlePlugin(BND)-bundle:ant"></a>bundle:ant</h2> |
| 904 | |
| 905 | <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> |
| 906 | |
| 907 | <p>The customized Ant script uses the BND tool to rebuild the bundle, |
| 908 | so any source changes should be reflected in the (re)generated manifest.</p> |
| 909 | |
| 910 | <p>Example:</p> |
| 911 | <div class="preformatted"><div class="preformattedContent"> |
| 912 | <pre>mvn ant:ant bundle:ant |
| 913 | |
| 914 | ant clean package |
| 915 | </pre> |
| 916 | </div></div> |
| 917 | |
| 918 | <h2><a name="MavenBundlePlugin(BND)-bundle:installfile"></a>bundle:install-file</h2> |
| 919 | |
| 920 | <p>The <b>install-file</b> goal updates the local OBR with the details of a bundle from the local filesystem.</p> |
| 921 | |
| 922 | <p>configuration:</p> |
| 923 | <ul> |
| 924 | <li><em>obrRepository</em> path to local OBR, defaults to <em><local-maven-repository></em><tt>/repository.xml</tt></li> |
| 925 | <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li> |
| 926 | <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li> |
| 927 | <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li> |
| 928 | <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li> |
| 929 | <li><em>classifier</em> Maven classifier type, defaults to none</li> |
| 930 | <li><em>pomFile</em> optional Pom file describing the bundle</li> |
| 931 | <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li> |
| 932 | <li><em>obrXml</em> optional additional properties for the bundle</li> |
| 933 | </ul> |
| 934 | |
| 935 | |
| 936 | <p>Example:</p> |
| 937 | <div class="preformatted"><div class="preformattedContent"> |
| 938 | <pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:install-file \ |
| 939 | -DpomFile=myPom.xml -Dfile=foo-1.0.jar |
| 940 | </pre> |
| 941 | </div></div> |
| 942 | |
| 943 | <h2><a name="MavenBundlePlugin(BND)-bundle:deploy"></a>bundle:deploy</h2> |
| 944 | |
| 945 | <p>The <b>deploy goal</b> updates the remote OBR with the details of |
| 946 | the deployed bundle from the local Maven repository. The remote OBR is |
| 947 | found by querying the <tt><distributionManagement></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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> for more details about these particular settings.</p> |
| 948 | |
| 949 | <p>(If the project has an <tt>obr.xml</tt> file somewhere in its resources, then it will be automatically detected and applied.)</p> |
| 950 | |
| 951 | <p>configuration:</p> |
| 952 | <ul> |
| 953 | <li><em>remoteOBR</em> name of remote OBR, defaults to NONE (which means no remote OBR deployment)</li> |
| 954 | <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li> |
| 955 | <li><em>altDeploymentRepository</em> alternative remote repository, <em>id::layout::url</em></li> |
| 956 | <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li> |
| 957 | </ul> |
| 958 | |
| 959 | |
| 960 | <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> |
| 961 | |
| 962 | <h2><a name="MavenBundlePlugin(BND)-bundle:deployfile"></a>bundle:deploy-file</h2> |
| 963 | |
| 964 | <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="maven-bundle-plugin-bnd_files/linkext7.gif" alt="" align="absmiddle" border="0" height="7" width="7"></sup></a></span> for more details about these particular settings.</p> |
| 965 | |
| 966 | <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> |
| 967 | |
| 968 | <p>configuration:</p> |
| 969 | <ul> |
| 970 | <li><em>remoteOBR</em> name of remote OBR, defaults to an empty string</li> |
| 971 | <li><em>obrRepository</em> used when the remoteOBR name is blank, defaults to <tt>repository.xml</tt></li> |
| 972 | <li><em>repositoryId</em> optional repository id, used to lookup authentication settings</li> |
| 973 | <li><em>url</em> remote repository transport URL, like |
| 974 | <div class="preformatted"><div class="preformattedContent"> |
| 975 | <pre>scpexe://host/path/to/obr |
| 976 | </pre> |
| 977 | </div></div></li> |
| 978 | <li><em>bundleUrl</em> public URL of deployed bundle, like |
| 979 | <div class="preformatted"><div class="preformattedContent"> |
| 980 | <pre>http://www.foo.org/bundles/foo.jar |
| 981 | </pre> |
| 982 | </div></div></li> |
| 983 | <li><em>groupId</em> Maven groupId for the bundle, taken from <em>pomFile</em> if given</li> |
| 984 | <li><em>artifactId</em> Maven artifactId for the bundle, taken from <em>pomFile</em> if given</li> |
| 985 | <li><em>version</em> Maven version for the bundle, taken from <em>pomFile</em> if given</li> |
| 986 | <li><em>packaging</em> Maven packaging type for the bundle, taken from <em>pomFile</em> if given</li> |
| 987 | <li><em>classifier</em> Maven classifier type, defaults to none</li> |
| 988 | <li><em>pomFile</em> optional Pom file describing the bundle</li> |
| 989 | <li><em>file</em> bundle file, defaults to the bundle from the local Maven repository</li> |
| 990 | <li><em>obrXml</em> optional additional properties for the bundle</li> |
| 991 | <li><em>ignoreLock</em> ignore remote locking when updating the OBR</li> |
| 992 | </ul> |
| 993 | |
| 994 | |
| 995 | <p>Example:</p> |
| 996 | <div class="preformatted"><div class="preformattedContent"> |
| 997 | <pre>mvn org.apache.felix:maven-bundle-plugin:1.4.0:deploy-file \ |
| 998 | -DpomFile=myPom.xml -Dfile=foo-1.0.jar -Durl=file:/tmp/example/OBR \ |
| 999 | -DbundleUrl=http://www.foo.org/bundles/foo.jar |
| 1000 | </pre> |
| 1001 | </div></div> |
| 1002 | |
| 1003 | <h2><a name="MavenBundlePlugin(BND)-bundle:clean"></a>bundle:clean</h2> |
| 1004 | |
| 1005 | <p>Sometimes you would like to clean your local OBR because it contains |
| 1006 | bundles that are no longer in your local Maven repository. This case |
| 1007 | often occurs when artifacts were deleted manually. The |
| 1008 | maven-bundle-plugin provides a simple goal to check for missing |
| 1009 | bundles, and remove them from the local OBR.</p> |
| 1010 | |
| 1011 | <p>configuration:</p> |
| 1012 | <ul> |
| 1013 | <li><em>obrRepository</em> path to local OBR, defaults to <em><local-maven-repository></em><tt>/repository.xml</tt></li> |
| 1014 | </ul> |
| 1015 | |
| 1016 | |
| 1017 | <p>Example:</p> |
| 1018 | <div class="preformatted"><div class="preformattedContent"> |
| 1019 | <pre>mvn bundle:clean |
| 1020 | </pre> |
| 1021 | </div></div> |
| 1022 | |
| 1023 | <h2><a name="MavenBundlePlugin(BND)-Concurrentupdates"></a>Concurrent updates</h2> |
| 1024 | |
| 1025 | <p>With a remote OBR, several uploads may occur at the same time. |
| 1026 | However, the remote OBR is centralized in one file, so concurrent |
| 1027 | modification must be avoided. To achieve this, the plug-in implements a |
| 1028 | locking system. Each time the plug-in tries to modify the file it sets |
| 1029 | a file based lock. If it can't take the lock, it will wait and retry. |
| 1030 | After 3 attempts the upload process fails. To bypass this lock add <tt>-DignoreLock</tt> to the command-line (or add <tt><ignoreLock>true<ignoreLock></tt> to the configuration section of your Pom).</p> |
| 1031 | |
| 1032 | <h2><a name="MavenBundlePlugin(BND)-FTPprotocol"></a>FTP protocol</h2> |
| 1033 | |
| 1034 | <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> |
| 1035 | <div class="code"><div class="codeContent"> |
| 1036 | <pre class="code-xml"><span class="code-tag"><build></span> |
| 1037 | <span class="code-tag"><extensions></span> |
| 1038 | <span class="code-tag"><extension></span> |
| 1039 | <span class="code-tag"><groupId></span>org.apache.maven.wagon<span class="code-tag"></groupId></span> |
| 1040 | <span class="code-tag"><artifactId></span>wagon-ftp<span class="code-tag"></artifactId></span> |
| 1041 | <span class="code-tag"><version></span>1.0-alpha-6<span class="code-tag"></version></span> |
| 1042 | <span class="code-tag"></extension></span> |
| 1043 | <span class="code-tag"></extensions></span> |
| 1044 | <span class="code-tag"></build></span></pre> |
| 1045 | </div></div> |
| 1046 | |
| 1047 | <h2><a name="MavenBundlePlugin(BND)-Howtheplugincomputesthedescriptionofthebundle"></a>How the plug-in computes the description of the bundle</h2> |
| 1048 | |
| 1049 | <p>The description of the bundle comes from three different sources:</p> |
| 1050 | <ul> |
| 1051 | <li>Bindex : Bindex is a tool that analyzes a bundle manifest to generate OBR description</li> |
| 1052 | <li>pom.xml : by analyzing the pom file, various information is collected (symbolic name ...)</li> |
| 1053 | <li>obr.xml : this file contains customized description and capabilities for the bundle</li> |
| 1054 | </ul> |
| 1055 | |
| 1056 | |
| 1057 | <p>These sources are merged together using the following precedence:</p> |
| 1058 | <div class="preformatted"><div class="preformattedContent"> |
| 1059 | <pre>Bindex |
| 1060 | | (overrides) |
| 1061 | pom.xml |
| 1062 | | (overrides) |
| 1063 | obr.xml |
| 1064 | </pre> |
| 1065 | </div></div> |
| 1066 | <p>A warning message is displayed when existing information is overridden.</p> |
| 1067 | |
| 1068 | <h2><a name="MavenBundlePlugin(BND)-Knownissues&limitations"></a>Known issues & limitations</h2> |
| 1069 | |
| 1070 | <ol> |
| 1071 | <li>obr.xml (file given by the user to add properties not found |
| 1072 | by Bindex) must be correct, because the plug-in does not check its |
| 1073 | syntax.</li> |
| 1074 | </ol> |
| 1075 | |
| 1076 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 1077 | <h1><a name="MavenBundlePlugin(BND)-Feedback"></a>Feedback</h1> |
| 1078 | |
| 1079 | <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="maven-bundle-plugin-bnd_files/mail_small.gif" alt="" align="absmiddle" border="0" height="12" width="13"></sup></a></span>; after subscribing, email questions or feedback to <span class="nobr"><a href="mailto:users@felix.apache.org" title="Send mail to users@felix.apache.org" rel="nofollow">users@felix.apache.org<sup><img class="rendericon" src="maven-bundle-plugin-bnd_files/mail_small.gif" alt="" align="absmiddle" border="0" height="12" width="13"></sup></a></span>.</p> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 1080 | </div> |
Stuart McCulloch | 0340ae4 | 2008-02-22 11:27:18 +0000 | [diff] [blame^] | 1081 | </body></html> |