Timothy Bennett | 3f0cb48 | 2005-08-23 06:11:13 +0000 | [diff] [blame] | 1 | This document describes how to use the maven-osgi-plugin for Maven2. |
| 2 | |
| 3 | NOTE: This plugin is only for Maven2. It will not work with Maven 1.x versions. |
| 4 | |
| 5 | NOTE: This plugin is very immature and is a project under development. Help |
| 6 | with the development of this plugin is welcome. A development roadmap for this |
| 7 | plugin will be posted at http://issues.apache.org/jira/browse/FELIX at some |
| 8 | point in the near future. |
| 9 | |
| 10 | HOW-TO |
| 11 | ====== |
| 12 | |
| 13 | 1. Install maven-2.0-alpha-3 release on your local machine. You can download |
| 14 | a binary distro from http://maven.apache.org/maven2/download.html along with |
| 15 | some instructions for getting started with Maven2. |
| 16 | |
| 17 | 2. You'll need an interim build of Maven2's maven-archiver that I've made |
| 18 | available at: |
| 19 | |
| 20 | https://svn.apache.org/repos/asf/incubator/felix/trunk/sandbox/tbennett/maven-archiver |
| 21 | |
| 22 | I've submitted patches to the Maven team that include these modifications to |
| 23 | the maven-archiver-plugin. However, they are not scheduled to be released |
| 24 | until the maven-2.0-beta-1 release. You'll need to use this version of |
| 25 | maven-archiver until that release is available from the Maven team. |
| 26 | |
| 27 | Once you've done an SVN checkout of the maven-archiver from my sandbox, simply |
| 28 | execute the following command from the maven-archiver project root directory: |
| 29 | |
| 30 | $ m2 install |
| 31 | |
| 32 | This will build and locally install this interim version of the maven-archiver-plugin. |
| 33 | |
| 34 | 3. Perform an SVN checkout of the maven-osgi-plugin available at: |
| 35 | |
| 36 | https://svn.apache.org/repos/asf/incubator/felix/trunk/tools/maven2/maven-osgi-plugin |
| 37 | |
| 38 | Once you've done this, simply execute the following command from the |
| 39 | maven-osgi-plugin project root directory: |
| 40 | |
| 41 | $ m2 install |
| 42 | |
| 43 | This will build and locally install the maven-osgi-plugin. |
| 44 | |
| 45 | 4. You can now use the plugin with a Maven2 POM to build an OSGi bundle jar |
| 46 | artifact. An example of what a bundle's Maven2 POM might look like that uses |
| 47 | this plugin is shown below. |
| 48 | |
| 49 | After compiling your bundle using the standard Maven2 compile goal: |
| 50 | |
| 51 | $ m2 compile |
| 52 | |
| 53 | You can build the OSGi bundle artifact by issuing the following maven2 |
| 54 | command: |
| 55 | |
| 56 | $ m2 osgi:osgi-jar |
| 57 | |
| 58 | Note the definition of the maven-osgi-plugin in the <build/> section of the |
| 59 | POM, along with the specification of the custom manifest entries you'd like |
| 60 | Maven2 to include in the jar's manifest file. Currently, the only manifest |
| 61 | entries that I've added support so far are: Bundle-Activator, Bundle-Name, |
| 62 | Bundle-Description, Bundle-Version, Bundle-Vendor, Bundle-Date, |
| 63 | Bundle-UpdateLocation, Export-Package, and Metadata-Location. More support |
| 64 | will be added soon. |
| 65 | |
| 66 | The plugin also takes advantage of Maven2's <scope/> specifier for given |
| 67 | project dependency. If the scope specifier is either "compile" or |
| 68 | "runtime", the given dependency will be bundled in the root directory of |
| 69 | the jar, and it's filename added to the Bundle-Classpath entry in the jar's |
| 70 | manifest file. This is done automatically by simply setting the dependency |
| 71 | scope. In the case of the below example, the osgi-framework-1.2.jar |
| 72 | dependency that my-bundle specifies has scope of "provided". This tells |
| 73 | the maven-osgi-plugin that the OSGi container will *provide* this dependency |
| 74 | at runtime, and therefore this dependency will not need to be embedded into |
| 75 | the bundle's jar file. |
| 76 | |
| 77 | <project> |
| 78 | <modelVersion>4.0.0</modelVersion> |
| 79 | <groupId>gov.bna.jis.osgi.bundle</groupId> |
| 80 | <artifactId>my-bundle</artifactId> |
| 81 | <packaging>jar</packaging> |
| 82 | <version>1.0-SNAPSHOT</version> |
| 83 | <name>OSGi Test Bundle</name> |
| 84 | <build> |
| 85 | <plugins> |
| 86 | <plugin> |
| 87 | <groupId>org.apache.maven.plugins</groupId> |
| 88 | <artifactId>maven-osgi-plugin</artifactId> |
| 89 | <version>0.1</version> |
| 90 | <configuration> |
| 91 | <osgiManifest> |
| 92 | <bundleActivator>gov.bna.jis.osgi.bundle.Activator</bundleActivator> |
| 93 | <bundleName>My Bundle Name</bundleName> |
| 94 | <bundleDescription>My Bundle Description</bundleDescription> |
| 95 | <bundleVendor>Metro Government of Nashville-Davidson Co.</bundleVendor> |
| 96 | <bundleVersion>1.0.0</bundleVersion> |
| 97 | </osgiManifest> |
| 98 | </configuration> |
| 99 | </plugin> |
| 100 | </plugins> |
| 101 | </build> |
| 102 | <dependencies> |
| 103 | <dependency> |
| 104 | <groupId>osgi</groupId> |
| 105 | <artifactId>osgi-framework</artifactId> |
| 106 | <version>1.2</version> |
| 107 | <scope>provided</scope> |
| 108 | </dependency> |
| 109 | </dependencies> |
| 110 | </project> |
| 111 | |
| 112 | There's much more functionality to add to this plugin, but it's a start. |
| 113 | |
| 114 | -tbennett |