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 | |
| 43 | <p><a name="MavenBundlePlugin(BND)-simpleexample"></a></p> |
| 44 | |
| 45 | <h1><a name="MavenBundlePlugin(BND)-SimpleExample"></a>Simple Example</h1> |
| 46 | |
| 47 | <p>Rather than going straight to a detailed list of plugin features, we |
| 48 | will first look at a simple example of how to use the plugin to give an |
| 49 | immediate flavor. A detailed "<a href="#MavenBundlePlugin%2528BND%2529-howto" title="how-to on Maven Bundle Plugin (BND)">how to</a>" will follow.</p> |
| 50 | |
| 51 | <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] | 52 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 53 | <div class="preformatted"><div class="preformattedContent"> |
| 54 | <pre>org.foo.myproject.api |
| 55 | org.foo.myproject.impl1 |
| 56 | org.foo.myproject.impl2 |
| 57 | ... |
| 58 | </pre> |
| 59 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 60 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 61 | <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] | 62 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 63 | <div class="preformatted"><div class="preformattedContent"> |
| 64 | <pre>... |
| 65 | <plugins> |
| 66 | <plugin> |
| 67 | <groupId>org.apache.felix</groupId> |
| 68 | <artifactId>maven-bundle-plugin</artifactId> |
| 69 | <extensions>true</extensions> |
| 70 | <configuration> |
| 71 | <instructions> |
| 72 | <Export-Package>org.foo.myproject.api</Export-Package> |
| 73 | <Private-Package>org.foo.myproject.*</Private-Package> |
| 74 | <Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator> |
| 75 | </instructions> |
| 76 | </configuration> |
| 77 | </plugin> |
| 78 | </plugins> |
| 79 | ... |
| 80 | </pre> |
| 81 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 82 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 83 | <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> |
| 84 | export. If the two sets overlap, as they do in the case, then the |
| 85 | export takes precedence. Since we did not specify any values for any |
| 86 | other bundle manifest headers, they will assume default values which |
| 87 | 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> |
| 88 | bundle manifest header based on the contents of the bundle, which means |
| 89 | that you generally do not ever need to explicitly specify it yourself. |
| 90 | That's it.</p> |
| 91 | |
| 92 | <h1><a name="MavenBundlePlugin(BND)-Features"></a>Features</h1> |
| 93 | |
| 94 | <p>The BND library underlying the plugin defines instructions to direct |
| 95 | its behavior. For this Maven plugin, these instructions are issued in |
| 96 | 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] | 97 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 98 | <ol> |
| 99 | <li><em>Manifest headers</em> - Any instruction that starts with |
| 100 | a capital letter will appear in the resulting bundle's manifest file; |
| 101 | the value for the header will either be copied, augmented, or generated |
| 102 | by BND depending on the instruction.</li> |
| 103 | <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> |
| 104 | <li><em>Directives</em> |
| 105 | - Any instruction starting with a '-' character is considered to be a |
| 106 | directive that informs BND to perform some special processing and is |
| 107 | not copied to the manifest.</li> |
| 108 | </ol> |
| 109 | |
| 110 | |
| 111 | <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> |
| 112 | |
| 113 | <p><a name="MavenBundlePlugin(BND)-instructions"></a></p> |
| 114 | |
| 115 | <h2><a name="MavenBundlePlugin(BND)-Instructions"></a>Instructions</h2> |
| 116 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 117 | <h3><a name="MavenBundlePlugin(BND)-{{<ExportPackage>}}"></a><tt><Export-Package></tt></h3> |
| 118 | |
| 119 | <p>The <tt><Export-Package></tt> instruction is a list of |
| 120 | packages for the bundle to export. These packages are copied into the |
| 121 | resulting bundle JAR file from the available classes (i.e., project |
| 122 | classes, dependencies, and class path); thus, it is possible to include |
| 123 | classes into your bundle that are not associated with source files in |
| 124 | your project. <tt><Export-Package></tt> can be specified with |
| 125 | package patterns using the '*' wildcard. Also, it is possible to |
| 126 | exclude packages using negation by starting the package pattern with |
| 127 | '!'. Thus, non-negated patterns indicate which of the available |
| 128 | packages to include in the bundle, whereas negated patterns indicate |
| 129 | which should not be included in the bundle.</p> |
| 130 | |
| 131 | <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> |
| 132 | |
| 133 | <p>Following standard OSGi R4 syntax, package patterns can include both |
| 134 | directives and attributes, which will be copied appropriately into the |
| 135 | generated Export-Package manifest header. Besides explicitly listing |
| 136 | package version attributes, BND will also determine package versions by |
| 137 | examining the source JAR file or from <tt>packageinfo</tt> files in the package directory.</p> |
| 138 | |
| 139 | <h3><a name="MavenBundlePlugin(BND)-{{<PrivatePackage>}}"></a><tt><Private-Package></tt></h3> |
| 140 | |
| 141 | <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> |
| 142 | be exported by the bundle. If a package is selected by both the export |
| 143 | and private package headers, then the export takes precedence.</p> |
| 144 | |
| 145 | <h3><a name="MavenBundlePlugin(BND)-{{<IncludeResource>}}"></a><tt><Include-Resource></tt></h3> |
| 146 | |
| 147 | <p>The <tt><Include-Resource></tt> instruction is a list of |
| 148 | arbitrary resources that should be copied into the bundle JAR file. The |
| 149 | specified resources are declared as clauses that can have the following |
| 150 | forms:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 151 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 152 | <div class="preformatted"><div class="preformattedContent"> |
| 153 | <pre>clause ::= assignment | inline | simple |
| 154 | assignment ::= PATH '=' PATH |
| 155 | simple ::= PATH |
| 156 | inline ::= '@' PATH |
| 157 | </pre> |
| 158 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 159 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 160 | <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> |
| 161 | form will place the resource in the bundle JAR with only the file name, |
| 162 | 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> |
| 163 | points to a directory, the entire directory hierarchy is copied into |
| 164 | the resulting bundle JAR file relative to the specified directory. If a |
| 165 | specific resource must be placed into a subdirectory of the bundle jar, |
| 166 | then use the <tt>assignment</tt> form, where the first path is the the |
| 167 | destination path (including file name if the resource is a file) and |
| 168 | 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> |
| 169 | |
| 170 | <p>If a resource clause is specified inside of "{ ... }" brackets, then |
| 171 | variable substitution will be performed on the resource, where |
| 172 | variables in the resources are denoted with "${ ... }" syntax.</p> |
| 173 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 174 | <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> |
| 175 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 176 | <h3><a name="MavenBundlePlugin(BND)-{{<ImportPackage>}}"></a><tt><Import-Package></tt></h3> |
| 177 | |
| 178 | <p>The <tt><Import-Package></tt> instruction is a list of |
| 179 | packages that are required by the bundle's contained packages. The |
| 180 | default for this header is "*", resulting in importing all referred |
| 181 | packages. This header rarely has to be explicitly specified. However, |
| 182 | in certain cases when there is an unwanted import, such an import can |
| 183 | be removed by using a negation package pattern. The package patterns |
| 184 | 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> |
| 185 | |
| 186 | <p><a name="MavenBundlePlugin(BND)-defaultbehavior"></a></p> |
| 187 | |
| 188 | <h2><a name="MavenBundlePlugin(BND)-DefaultBehavior"></a>Default Behavior</h2> |
| 189 | |
| 190 | <p>To use this plugin, very little information is required by BND. As |
| 191 | part of the Maven integration, the plugin tries to set reasonable |
| 192 | defaults for various instructions. For example:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 193 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 194 | <ul> |
| 195 | <li><tt><Bundle-SymbolicName></tt> is assumed to be "<tt>${groupId}.${artifactId</tt>}".</li> |
| 196 | <li><tt><Export-Package></tt> is assumed to be "<tt>${groupId}.${artifactId}.*</tt>", unless <tt><Private-Package></tt> is specified, then <tt><Export-Package></tt> is assumed to be empty.</li> |
| 197 | <li><tt><Private-Package></tt> is assumed to be empty by default.</li> |
| 198 | <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] | 199 | <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] | 200 | which will copy the specified project directory hierarchy into the |
| 201 | resulting bundle JAR file, mirroring standard Maven behavior.</li> |
| 202 | <li><tt><Bundle-Version></tt> is assumed to be "<tt>${pom.version</tt>}" with '-' character separator of the qualifier replaced with a '.' character.</li> |
| 203 | <li><tt><Bundle-Name></tt> is assumed to be "<tt>${pom.name</tt>}".</li> |
| 204 | <li><tt><Bundle-Description></tt> is assumed to be "<tt>${pom.description</tt>}".</li> |
| 205 | <li><tt><Bundle-License></tt> is assumed to be "<tt>${pom.licenses</tt>}".</li> |
| 206 | <li><tt><Bundle-Vendor></tt> is assumed to be "<tt>${pom.organization.name</tt>}".</li> |
| 207 | <li><tt><Bundle-DocURL></tt> is assumed to be "<tt>${pom.organization.url</tt>}".</li> |
| 208 | </ul> |
| 209 | |
| 210 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 211 | <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] | 212 | to be '2'. Additionally, it generates imports for every export to |
| 213 | ensure package substitutability, which is very important when working |
| 214 | with collaborating services. It is possible to override any of these |
| 215 | values (except <tt>Bundle-ManifestVersion</tt>) just by specifying the desired value in the plugin configuration section of the POM file.</p> |
| 216 | |
| 217 | <p><a name="MavenBundlePlugin(BND)-howto"></a></p> |
| 218 | |
| 219 | <h1><a name="MavenBundlePlugin(BND)-Detailed"HowTo""></a>Detailed "How To"</h1> |
| 220 | |
| 221 | <h2><a name="MavenBundlePlugin(BND)-GetMaven2"></a>Get Maven2</h2> |
| 222 | |
| 223 | <p>The first step in the process of using the plugin is downloading and |
| 224 | installing the latest version of the Maven2 runtime. The latest Maven2 |
| 225 | release and instuctions for getting started with Maven2 can be found at |
| 226 | 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> |
| 227 | |
| 228 | <h2><a name="MavenBundlePlugin(BND)-UsingthePlugin"></a>Using the Plugin</h2> |
| 229 | |
| 230 | <p>To use the maven-bundle-plugin, you first need to add the plugin and |
| 231 | some appropriate plugin configuration to your bundle project's POM. |
| 232 | 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] | 233 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 234 | <div class="preformatted"><div class="preformattedContent"> |
| 235 | <pre><project> |
| 236 | <modelVersion>4.0.0</modelVersion> |
| 237 | <groupId>my-osgi-bundles</groupId> |
| 238 | <artifactId>examplebundle</artifactId> |
| 239 | <packaging>bundle</packaging> <!-- (1) --> |
| 240 | <version>1.0</version> |
| 241 | <name>Example Bundle</name> |
| 242 | <dependencies> |
| 243 | <dependency> |
| 244 | <groupId>org.apache.felix</groupId> |
| 245 | <artifactId>org.osgi.core</artifactId> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 246 | <version>1.0.0</version> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 247 | </dependency> |
| 248 | </dependencies> |
| 249 | <build> |
| 250 | <plugins> |
| 251 | <plugin> <!-- (2) START --> |
| 252 | <groupId>org.apache.felix</groupId> |
| 253 | <artifactId>maven-bundle-plugin</artifactId> |
| 254 | <extensions>true</extensions> |
| 255 | <configuration> |
| 256 | <instructions> |
| 257 | <Export-Package>com.my.company.api</Export-Package> |
| 258 | <Private-Package>com.my.company.*</Private-Package> |
| 259 | <Bundle-Activator>com.my.company.Activator</Bundle-Activator> |
| 260 | </instructions> |
| 261 | </configuration> |
| 262 | </plugin> <!-- (2) END --> |
| 263 | </plugins> |
| 264 | </build> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 265 | </project> |
| 266 | </pre> |
| 267 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 268 | |
| 269 | <p>There are two main things to note: (1) the <tt><packaging></tt> |
| 270 | specifier must be "bundle" and (2) the plugin and configuration must be |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 271 | specified (the configuration section is where you will issue |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 272 | instructions to the plugin).</p> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 273 | |
| 274 | <h2><a name="MavenBundlePlugin(BND)-RealWorldExample"></a>Real-World Example</h2> |
| 275 | |
| 276 | <p>Consider this more real-world example using Felix' Log Service |
| 277 | implementation. The Log Service project is comprised of a single |
| 278 | package: <tt>org.apache.felix.log.impl</tt>. It has a dependency on |
| 279 | the core OSGi interfaces as well as a dependency on the compendium OSGi |
| 280 | interfaces for the specific log service interfaces. The following is |
| 281 | its POM file:</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 282 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 283 | <div class="preformatted"><div class="preformattedContent"> |
| 284 | <pre><project> |
| 285 | <modelVersion>4.0.0</modelVersion> |
| 286 | <groupId>org.apache.felix</groupId> |
| 287 | <artifactId>org.apache.felix.log</artifactId> |
| 288 | <packaging>bundle</packaging> |
| 289 | <name>Apache Felix Log Service</name> |
| 290 | <version>0.8.0-SNAPSHOT</version> |
| 291 | <description> |
| 292 | This bundle provides an implementation of the OSGi R4 Log service. |
| 293 | </description> |
| 294 | <dependencies> |
| 295 | <dependency> |
| 296 | <groupId>${pom.groupId}</groupId> |
| 297 | <artifactId>org.osgi.core</artifactId> |
| 298 | <version>0.8.0-incubator</version> |
| 299 | </dependency> |
| 300 | <dependency> |
| 301 | <groupId>${pom.groupId}</groupId> |
| 302 | <artifactId>org.osgi.compendium</artifactId> |
| 303 | <version>0.9.0-incubator-SNAPSHOT</version> |
| 304 | </dependency> |
| 305 | </dependencies> |
| 306 | <build> |
| 307 | <plugins> |
| 308 | <plugin> |
| 309 | <groupId>org.apache.felix</groupId> |
| 310 | <artifactId>maven-bundle-plugin</artifactId> |
| 311 | <extensions>true</extensions> |
| 312 | <configuration> |
| 313 | <instructions> |
| 314 | <Export-Package>org.osgi.service.log</Export-Package> |
| 315 | <Private-Package>org.apache.felix.log.impl</Private-Package> |
| 316 | <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> |
| 317 | <Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator> |
| 318 | <Export-Service>org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService</Export-Service> |
| 319 | </instructions> |
| 320 | </configuration> |
| 321 | </plugin> |
| 322 | </plugins> |
| 323 | </build> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 324 | </project> |
| 325 | </pre> |
| 326 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 327 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 328 | <p>Notice that the <tt><Export-Package></tt> instruction |
| 329 | specifies that the bundle exports the Log Service package, even though |
| 330 | this package is not contained in the bundle project. By declaring this, |
| 331 | the plugin will copy the Log Service package into the resulting bundle |
| 332 | JAR file. This is useful in this case because now the bundle can |
| 333 | resolve without having to download the entire compendium bundle. The |
| 334 | resulting manifest for the Log Service bundle looks like this (notice |
| 335 | how the imports/exports automatically have version information |
| 336 | associated with them, which was obtained from packageinfo files in the |
| 337 | source packages):</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 338 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 339 | <div class="preformatted"><div class="preformattedContent"> |
| 340 | <pre>Manifest-Version: 1 |
| 341 | Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt |
| 342 | Bundle-Activator: org.apache.felix.log.impl.Activator |
| 343 | Import-Package: org.osgi.framework;version=1.3, org.osgi.service.log;v |
| 344 | ersion=1.3 |
| 345 | Include-Resource: src/main/resources |
| 346 | Export-Package: org.osgi.service.log;uses:=org.osgi.framework;version= |
| 347 | 1.3 |
| 348 | Bundle-Version: 0.8.0.SNAPSHOT |
| 349 | Bundle-Name: Apache Felix Log Service |
| 350 | Bundle-Description: This bundle provides an implementation of the OSGi |
| 351 | R4 Log service. |
| 352 | Private-Package: org.apache.felix.log.impl |
| 353 | Bundle-ManifestVersion: 2 |
| 354 | Export-Service: org.osgi.service.log.LogService,org.osgi.service.log.L |
| 355 | ogReaderService |
| 356 | Bundle-SymbolicName: org.apache.felix.log |
| 357 | </pre> |
| 358 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 359 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 360 | <p>The resulting bundle JAR file has the following content (notice how |
| 361 | 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] | 362 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 363 | <div class="preformatted"><div class="preformattedContent"> |
| 364 | <pre>META-INF/MANIFEST.MF |
| 365 | LICENSE |
| 366 | META-INF/ |
| 367 | META-INF/maven/ |
| 368 | META-INF/maven/org.apache.felix/ |
| 369 | META-INF/maven/org.apache.felix/org.apache.felix.log/ |
| 370 | META-INF/maven/org.apache.felix/org.apache.felix.log/pom.properties |
| 371 | META-INF/maven/org.apache.felix/org.apache.felix.log/pom.xml |
| 372 | NOTICE |
| 373 | org/ |
| 374 | org/apache/ |
| 375 | org/apache/felix/ |
| 376 | org/apache/felix/log/ |
| 377 | org/apache/felix/log/impl/ |
| 378 | org/apache/felix/log/impl/Activator.class |
| 379 | org/apache/felix/log/impl/Log.class |
| 380 | org/apache/felix/log/impl/LogEntryImpl.class |
| 381 | org/apache/felix/log/impl/LogException.class |
| 382 | org/apache/felix/log/impl/LogListenerThread.class |
| 383 | org/apache/felix/log/impl/LogNode.class |
| 384 | org/apache/felix/log/impl/LogNodeEnumeration.class |
| 385 | org/apache/felix/log/impl/LogReaderServiceFactory.class |
| 386 | org/apache/felix/log/impl/LogReaderServiceImpl.class |
| 387 | org/apache/felix/log/impl/LogServiceFactory.class |
| 388 | org/apache/felix/log/impl/LogServiceImpl.class |
| 389 | org/osgi/ |
| 390 | org/osgi/service/ |
| 391 | org/osgi/service/log/ |
| 392 | org/osgi/service/log/LogEntry.class |
| 393 | org/osgi/service/log/LogListener.class |
| 394 | org/osgi/service/log/LogReaderService.class |
| 395 | org/osgi/service/log/LogService.class |
| 396 | org/osgi/service/log/package.html |
| 397 | org/osgi/service/log/packageinfo |
| 398 | </pre> |
| 399 | </div></div> |
| 400 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 401 | <h2><a name="MavenBundlePlugin(BND)-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype"></a>Adding OSGi metadata to existing projects without changing the packaging type</h2> |
| 402 | |
| 403 | <p>If you want to keep your project packaging type (for example "jar") but would like to add OSGi metadata<br> |
| 404 | you can use the manifest goal to generate a bundle manifest. The maven-jar-plugin can then be used to<br> |
| 405 | add this manifest to the final artifact. For example:</p> |
| 406 | |
| 407 | <div class="code"><div class="codeContent"> |
| 408 | <pre class="code-xml"><span class="code-tag"><plugin></span> |
| 409 | <span class="code-tag"><artifactId></span>maven-jar-plugin<span class="code-tag"></artifactId></span> |
| 410 | <span class="code-tag"><configuration></span> |
| 411 | <span class="code-tag"><archive></span> |
| 412 | <span class="code-tag"><manifestFile></span>${project.build.outputDirectory}/META-INF/MANIFEST.MF<span class="code-tag"></manifestFile></span> |
| 413 | <span class="code-tag"></archive></span> |
| 414 | <span class="code-tag"></configuration></span> |
| 415 | <span class="code-tag"></plugin></span> |
| 416 | <span class="code-tag"><plugin></span> |
| 417 | <span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 418 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 419 | <span class="code-tag"><executions></span> |
| 420 | <span class="code-tag"><execution></span> |
| 421 | <span class="code-tag"><id></span>bundle-manifest<span class="code-tag"></id></span> |
| 422 | <span class="code-tag"><phase></span>process-classes<span class="code-tag"></phase></span> |
| 423 | <span class="code-tag"><goals></span> |
| 424 | <span class="code-tag"><goal></span>manifest<span class="code-tag"></goal></span> |
| 425 | <span class="code-tag"></goals></span> |
| 426 | <span class="code-tag"></execution></span> |
| 427 | <span class="code-tag"></executions></span> |
| 428 | <span class="code-tag"></plugin></span></pre> |
| 429 | </div></div> |
| 430 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 431 | <h2><a name="MavenBundlePlugin(BND)-BuildingthePlugin"></a>Building the Plugin</h2> |
| 432 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 433 | <p>The plugin is hosted at the Apache Felix project. The following |
| 434 | steps describe how to build and install the plugin into your local |
| 435 | Maven2 repository.</p> |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 436 | |
| 437 | <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] | 438 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 439 | <div class="preformatted"><div class="preformattedContent"> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 440 | <pre>$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 441 | </pre> |
| 442 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 443 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 444 | <p>Using Maven2, build and install the maven-bundle-plugin by issuing |
| 445 | the following Maven2 command in the project directory that was created |
| 446 | as a result of the previous step.</p> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 447 | |
Karl Pauls | f87ac14 | 2007-07-06 22:36:17 +0000 | [diff] [blame] | 448 | <div class="preformatted"><div class="preformattedContent"> |
| 449 | <pre>$ mvn install |
| 450 | </pre> |
| 451 | </div></div> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 452 | |
| 453 | <h1><a name="MavenBundlePlugin(BND)-Goals"></a>Goals</h1> |
| 454 | |
| 455 | <p>The maven-bundle-plugin also provides additional functionality via |
| 456 | some Maven goals. Command-line execution of a goal is performed as |
| 457 | follows:</p> |
| 458 | |
| 459 | <div class="preformatted"><div class="preformattedContent"> |
| 460 | <pre>mvn org.apache.felix:maven-bundle-plugin:GOAL |
| 461 | </pre> |
| 462 | </div></div> |
| 463 | |
| 464 | <p>Where GOAL is one of the following:</p> |
| 465 | |
| 466 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 467 | <li><b><tt>bundle</tt></b> - build an OSGi bundle jar<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 468 | configuration options: |
| 469 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 470 | <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li> |
| 471 | <li><em><tt>unpackBundle</tt></em> unpack bundle contents to output directory, defaults to false</li> |
| 472 | <li><em><tt>excludeDependencies</tt></em> exclude all dependencies from the classpath passed to Bnd, defaults to false</li> |
| 473 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 474 | </ul> |
| 475 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 476 | </ul> |
| 477 | |
| 478 | |
| 479 | <ul> |
| 480 | <li><b><tt>bundleall</tt></b> - build an OSGi bundle jar for all transitive dependencies<br> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 481 | configuration options: |
| 482 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 483 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 484 | </ul> |
| 485 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 486 | </ul> |
| 487 | |
| 488 | |
| 489 | <ul> |
| 490 | <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] | 491 | configuration options: |
| 492 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 493 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 494 | </ul> |
| 495 | </li> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 496 | </ul> |
| 497 | |
| 498 | |
| 499 | <ul> |
| 500 | <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] | 501 | configuration options: |
| 502 | <ul> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 503 | <li><em><tt>manifestLocation</tt></em> defaults to ${project.build.outputDirectory}/META-INF</li> |
| 504 | <li><em><tt>supportedProjectTypes</tt></em> defaults to "jar","bundle"</li> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 505 | </ul> |
| 506 | </li> |
| 507 | </ul> |
| 508 | |
| 509 | |
| 510 | <p>There are also new instructions available from the underlying BND |
| 511 | 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> |
| 512 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 513 | <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] | 514 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 515 | <h1><a name="MavenBundlePlugin(BND)-Thefollowingfeaturesareonlyavailableinversionsafter1.0.0"></a>The following features are only available in versions after 1.0.0</h1> |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 516 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 517 | <h2><a name="MavenBundlePlugin(BND)-Embeddingdependencies"></a>Embedding dependencies</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 518 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 519 | <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] | 520 | |
| 521 | <div class="code"><div class="codeContent"> |
| 522 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>dependencies<span class="code-tag"></Embed-Dependency></span></pre> |
| 523 | </div></div> |
| 524 | |
| 525 | <p>where:</p> |
| 526 | |
| 527 | <div class="preformatted"><div class="preformattedContent"> |
| 528 | <pre>dependencies ::= clause ( ',' clause ) * |
| 529 | clause ::= MATCH ( ';' attr '=' MATCH | ';inline=true' ) |
| 530 | attr ::= 'groupId' | 'artifactId' | 'version' | 'scope' | 'type' | 'classifier' |
| 531 | MATCH ::= <globbed regular expressions> |
| 532 | </pre> |
| 533 | </div></div> |
| 534 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 535 | <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> clauses, which are then appended to the current set of instructions and passed onto BND.</p> |
| 536 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 537 | <p>some examples:</p> |
| 538 | |
| 539 | <div class="code"><div class="codeContent"> |
| 540 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>*;scope=compile|runtime<span class="code-tag"></Embed-Dependency></span> |
| 541 | |
| 542 | <span class="code-tag"><Embed-Dependency></span>junit;scope=test<span class="code-tag"></Embed-Dependency></span> |
| 543 | |
| 544 | <span class="code-tag"><Embed-Dependency></span>aopalliance;scope=!test;inline=true<span class="code-tag"></Embed-Dependency></span></pre> |
| 545 | </div></div> |
| 546 | |
Stuart McCulloch | 7c961f5 | 2008-01-02 08:56:07 +0000 | [diff] [blame] | 547 | <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] | 548 | |
| 549 | <ul> |
| 550 | <li><tt><Embed-StripVersion>true</Embed-StripVersion></tt> - removes the version from the file (ie. <em>artifactId.jar</em>)</li> |
| 551 | <li><tt><Embed-StripGroup>false</Embed-StripGroup></tt> - adds the groupId as a subdirectory (ie. <em>groupId/artifactId-version.jar</em>)</li> |
| 552 | <li><tt><Embed-Directory>directory</Embed-Directory></tt> - adds a subdirectory (ie. <em>directory/artifactId-version.jar</em>)</li> |
| 553 | </ul> |
| 554 | |
| 555 | |
| 556 | <p>Normally the plugin only checks direct dependencies, but this can be |
| 557 | changed to include the complete set of transitive dependencies with the |
| 558 | following option:</p> |
| 559 | |
| 560 | <div class="code"><div class="codeContent"> |
| 561 | <pre class="code-xml"><span class="code-tag"><Embed-Transitive></span>true<span class="code-tag"></Embed-Transitive></span></pre> |
| 562 | </div></div> |
| 563 | |
| 564 | <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> |
| 565 | |
| 566 | <div class="code"><div class="codeContent"> |
| 567 | <pre class="code-xml"><span class="code-tag"><Embed-Dependency></span>*;scope=compile|runtime;inline=true<span class="code-tag"></Embed-Dependency></span></pre> |
| 568 | </div></div> |
| 569 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 570 | <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] | 571 | |
| 572 | <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> |
| 573 | instructions will result in classes being inlined in the bundle, even |
| 574 | though they also exist inside the embedded jar. If you want to export |
| 575 | packages from an embedded dependency without such duplication then you |
| 576 | can either inline the dependency, or use a new BND instruction called <tt><_exportcontents></tt>.</p> |
| 577 | |
| 578 | <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] | 579 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 580 | <h2><a name="MavenBundlePlugin(BND)-OBRintegration"></a>OBR integration</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 581 | |
| 582 | <p>The latest Maven Bundle Plugin automatically updates the local OBR |
| 583 | repository.xml file during the install phase, using a default location |
| 584 | of:</p> |
| 585 | |
| 586 | <div class="code"><div class="codeContent"> |
| 587 | <pre class="code-java"><LOCAL-MAVEN-REPOSITORY>/repository.xml</pre> |
| 588 | </div></div> |
| 589 | |
| 590 | <p>You can configure the location of the OBR repository by using the command line:</p> |
| 591 | |
| 592 | <div class="code"><div class="codeContent"> |
| 593 | <pre class="code-java">mvn clean install -DobrRepository=<PATH_TO_OBR></pre> |
| 594 | </div></div> |
| 595 | |
| 596 | <p>or in the configuration section for the maven-bundle-plugin in your Maven POM:</p> |
| 597 | |
| 598 | <div class="code"><div class="codeContent"> |
| 599 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 600 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 601 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 602 | <span class="code-tag"><configuration></span> |
| 603 | <span class="code-tag"><obrRepository></span>PATH_TO_OBR<span class="code-tag"></obrRepository></span> |
| 604 | <span class="code-tag"><instructions></span> |
| 605 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 606 | <span class="code-tag"></instructions></span> |
| 607 | <span class="code-tag"></configuration></span></pre> |
| 608 | </div></div> |
| 609 | |
| 610 | <p>to disable OBR installation set the obrRepository to NONE, for example:</p> |
| 611 | |
| 612 | <div class="code"><div class="codeContent"> |
| 613 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 614 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 615 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 616 | <span class="code-tag"><configuration></span> |
| 617 | <span class="code-tag"><obrRepository></span>NONE<span class="code-tag"></obrRepository></span> |
| 618 | <span class="code-tag"><instructions></span> |
| 619 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 620 | <span class="code-tag"></instructions></span> |
| 621 | <span class="code-tag"></configuration></span></pre> |
| 622 | </div></div> |
| 623 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 624 | <h2><a name="MavenBundlePlugin(BND)-Eclipse/PDEintegration"></a>Eclipse/PDE integration</h2> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 625 | |
| 626 | <p>It is possible to configure the Maven Bundle Plugin to put the |
| 627 | bundle manifest where Eclipse/PDE expects it, and use the Maven |
| 628 | Dependency Plugin to arrange for any embedded dependencies to appear in |
| 629 | a local directory that matches the Bundle-ClassPath entries. Here is an |
| 630 | example POM that does this:</p> |
| 631 | |
| 632 | <div class="preformatted"><div class="preformattedContent"> |
| 633 | <pre><project> |
| 634 | |
| 635 | <properties> |
| 636 | <bundle.symbolicName>org.example</bundle.symbolicName> |
| 637 | <bundle.namespace>org.example</bundle.namespace> |
| 638 | </properties> |
| 639 | |
| 640 | <modelVersion>4.0.0</modelVersion> |
| 641 | <groupId>examples</groupId> |
| 642 | <artifactId>org.example</artifactId> |
| 643 | <version>1.0-SNAPSHOT</version> |
| 644 | |
| 645 | <name>${bundle.symbolicName} [${bundle.namespace}]</name> |
| 646 | |
| 647 | <packaging>bundle</packaging> |
| 648 | |
| 649 | <build> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 650 | <resources> |
| 651 | <resource> |
| 652 | <directory>src/main/resources</directory> |
| 653 | </resource> |
| 654 | <resource> |
| 655 | <directory>.</directory> |
| 656 | <includes> |
| 657 | <include>plugin.xml</include> |
| 658 | </includes> |
| 659 | </resource> |
| 660 | </resources> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 661 | <plugins> |
| 662 | <plugin> |
| 663 | <groupId>org.apache.felix</groupId> |
| 664 | <artifactId>maven-bundle-plugin</artifactId> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 665 | <version>1.2.0</version> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 666 | <extensions>true</extensions> |
| 667 | <!-- |
| 668 | the following instructions build a simple set of public/private classes into an OSGi bundle |
| 669 | --> |
| 670 | <configuration> |
| 671 | <manifestLocation>META-INF</manifestLocation> |
| 672 | <instructions> |
| 673 | <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> |
| 674 | <Bundle-Version>${pom.version}</Bundle-Version> |
| 675 | <!-- |
| 676 | assume public classes are in the top package, and private classes are under ".internal" |
| 677 | --> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 678 | <Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"</Export-Package> |
| 679 | <Private-Package>${bundle.namespace}.internal.*</Private-Package> |
| 680 | <Bundle-Activator>${bundle.namespace}.internal.ExampleActivator</Bundle-Activator> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 681 | <!-- |
| 682 | embed compile/runtime dependencies using path that matches the copied dependency folder |
| 683 | --> |
| 684 | <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> |
| 685 | <Embed-Directory>target/dependency</Embed-Directory> |
| 686 | <Embed-StripGroup>true</Embed-StripGroup> |
| 687 | </instructions> |
| 688 | </configuration> |
| 689 | </plugin> |
| 690 | <plugin> |
| 691 | <artifactId>maven-dependency-plugin</artifactId> |
| 692 | <executions> |
| 693 | <execution> |
| 694 | <id>copy-dependencies</id> |
| 695 | <phase>package</phase> |
| 696 | <goals> |
| 697 | <goal>copy-dependencies</goal> |
| 698 | </goals> |
| 699 | </execution> |
| 700 | </executions> |
| 701 | </plugin> |
| 702 | </plugins> |
| 703 | </build> |
| 704 | |
| 705 | <dependencies> |
| 706 | <dependency> |
| 707 | <groupId>org.osgi</groupId> |
| 708 | <artifactId>osgi_R4_core</artifactId> |
| 709 | <version>1.0</version> |
| 710 | <scope>provided</scope> |
| 711 | <optional>true</optional> |
| 712 | </dependency> |
| 713 | <dependency> |
| 714 | <groupId>org.osgi</groupId> |
| 715 | <artifactId>osgi_R4_compendium</artifactId> |
| 716 | <version>1.0</version> |
| 717 | <scope>provided</scope> |
| 718 | <optional>true</optional> |
| 719 | </dependency> |
| 720 | <dependency> |
| 721 | <groupId>junit</groupId> |
| 722 | <artifactId>junit</artifactId> |
| 723 | <version>3.8.1</version> |
| 724 | <scope>compile</scope> |
| 725 | <optional>true</optional> |
| 726 | </dependency> |
| 727 | </dependencies> |
| 728 | |
| 729 | </project> |
| 730 | </pre> |
| 731 | </div></div> |
| 732 | |
| 733 | <p>To generate the Eclipse metadata use:</p> |
| 734 | |
| 735 | <div class="code"><div class="codeContent"> |
| 736 | <pre class="code-java">mvn clean <span class="code-keyword">package</span> eclipse:eclipse -Declipse.pde install</pre> |
| 737 | </div></div> |
| 738 | |
| 739 | <p>and you should now be able to import this as an existing Eclipse project.</p> |
| 740 | |
| 741 | <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> |
| 742 | |
| 743 | <p>With the original Pax-Construct generated POM you would simply use:</p> |
| 744 | |
| 745 | <div class="code"><div class="codeContent"> |
| 746 | <pre class="code-java">mvn clean <span class="code-keyword">package</span> pax:eclipse</pre> |
| 747 | </div></div> |
| 748 | |
| 749 | <p>to create the appropriate Eclipse files and manifest, and also |
| 750 | handle any embedded entries. The pax:eclipse goal extends |
| 751 | eclipse:eclipse, and supports the same parameters.</p> |
| 752 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 753 | <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] | 754 | |
| 755 | <p>Once in a while you may create a bundle which contains additional classes to the ones compiled from <tt>src/main/java</tt>, |
| 756 | for example when you embed the classes from another jar. This can |
| 757 | sometimes cause unforeseen problems in Maven, as it will use the output |
| 758 | directory (<tt>target/classes</tt>) rather than the final bundle, when compiling against projects in the same reactor (ie. the same build).</p> |
| 759 | |
| 760 | <p>The easiest way to get around this Maven 'feature' is to unpack the |
| 761 | contents of the bundle to the output directory after the packaging |
| 762 | step, so the additional classes will be found where Maven expects them. |
| 763 | Thankfully there is now an easy option to do this in the bundle-plugin:</p> |
| 764 | |
| 765 | <div class="code"><div class="codeContent"> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 766 | <pre class="code-xml"><span class="code-tag"><groupId></span>org.apache.felix<span class="code-tag"></groupId></span> |
| 767 | <span class="code-tag"><artifactId></span>maven-bundle-plugin<span class="code-tag"></artifactId></span> |
| 768 | <span class="code-tag"><extensions></span>true<span class="code-tag"></extensions></span> |
| 769 | <span class="code-tag"><configuration></span> |
| 770 | <span class="code-tag"><unpackBundle></span>true<span class="code-tag"></unpackBundle></span> |
| 771 | <span class="code-tag"><instructions></span> |
| 772 | <span class="code-tag"><span class="code-comment"><!-- bnd instructions --></span></span> |
| 773 | <span class="code-tag"></instructions></span> |
| 774 | <span class="code-tag"></configuration></span></pre> |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 775 | </div></div> |
| 776 | |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 777 | <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] | 778 | |
| 779 | <p>If you have an existing manifest, you can add this to the Bnd instructions, like so:</p> |
| 780 | |
| 781 | <div class="code"><div class="codeContent"> |
Stuart McCulloch | dd4ae5f | 2008-02-05 12:38:46 +0000 | [diff] [blame^] | 782 | <pre class="code-xml"><span class="code-tag"><_include></span>src/main/resources/META-INF/MANIFEST.MF<span class="code-tag"></_include></span> |
| 783 | <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] | 784 | </div></div> |
| 785 | |
| 786 | <p>Bnd will use it when calculating the bundle contents, and will also |
| 787 | copy across all manifest attributes starting with a capital letter.<br> |
| 788 | As shown in the above example, you could use this to include a non-OSGi |
| 789 | manifest which you then customize with extra OSGi attributes.</p> |
| 790 | |
| 791 | <h1><a name="MavenBundlePlugin(BND)-Feedback"></a>Feedback</h1> |
| 792 | |
| 793 | <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] | 794 | </div> |
| 795 | |
Stuart McCulloch | 93de649 | 2007-12-16 15:59:05 +0000 | [diff] [blame] | 796 | </body></html> |