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