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