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