|
| 1 | +--- |
| 2 | +title: Creating the Initial Project |
| 3 | +summary: Setup the project with DOM4J and make an initial cut |
| 4 | +layout: prev-next-collection |
| 5 | +--- |
| 6 | + |
| 7 | +In this tutorial we will wrap [DOM4J]. This JAR is available on Maven Central. The latest versions are actually OSGi enabled but there are variations around without manifest headers. It is chose because its dependencies are not too awful. It also depends on a number of external libraries that each also have dependencies, ad nauseum. |
| 8 | + |
| 9 | +> ##### WARNING |
| 10 | +> |
| 11 | +> The work we do in this tutorial **is not for use in a real bundle**. The resulting bundle is not tested an might not work. The only goal is to show the forces at play when you wrap a bundle. |
| 12 | +{: .block-warning } |
| 13 | + |
| 14 | +## Dependencies of DOM4J |
| 15 | + |
| 16 | +Below you see the dependency graph of revision 1.6.1. For an average Maven project this actually looks quite good. (The graph shows all Maven dependencies, this is in general a bit too wide since test and compile dependencies are not transitive.) However, if a project does not stop at the maximum number of shown dependencies (>1000) then it is generally a 'good' sign. |
| 17 | + |
| 18 | +{: width="70%" } |
| 19 | + |
| 20 | +On Maven Central you can see this in the [Dependencies tab](https://central.sonatype.com/artifact/dom4j/dom4j/1.6.1/dependencies). |
| 21 | + |
| 22 | +After we created the project, we'll drag the top version vignette on the `bnd.bnd` build tab to add it as a dependency. |
| 23 | + |
| 24 | +## Creating Project |
| 25 | + |
| 26 | +In Bndtools create a project `osgi.enroute.examples.wrapping.dom4j.adapter`. It is of course fine to call it differently but make sure you call make the extension `adapter` or `provider`. This extension triggers the correct template with the OSGi enRoute templates, which you should obviously use. |
| 27 | + |
| 28 | +After the creation, you can delete the source code in the `src` and `test` source folders; we won't use it. (Add a `.gitignore` file in the `src` folder so that it is not ignored as an empty directory by Git.) |
| 29 | + |
| 30 | +## Adding DOM4J |
| 31 | + |
| 32 | +First, add the Maven GAV coordinates, i.e. `dom4j:dom4j:1.6.1` to your repository in bndtools (e.g. [MavenBndRepository](https://bnd.bndtools.org/plugins/maven.html)) |
| 33 | + |
| 34 | +Then double click on the `bnd.bnd` file in your project and select the `Build` tab. Now drag the domj bundle from the Repository Browserto the `Build` tab's `Build Path` list and drop it. Alternatively you can achieve the same by using the `+` Button of the `Build Path` list. |
| 35 | + |
| 36 | +Then, click on the `Source` tab. The `-buildpath` looks then like: |
| 37 | + |
| 38 | + -buildpath: \ |
| 39 | + dom4j:dom4j;version='1.6' |
| 40 | + |
| 41 | +## Version & Description |
| 42 | + |
| 43 | +In general you use the version of the JAR you're wrapping. Since we're wrapping 1.6.1 we make that our own version. It is also a good idea to add a small description of what you are doing. So you should replace the Bundle-Version and Bundle-Description headers. Adding a Bundle-Copyright and Bundle-Vendor cannot harm: |
| 44 | + |
| 45 | + Bundle-Version: 1.6.1.${tstamp} |
| 46 | + Bundle-Description: Wraps DOM4J for OSGi, including the primary dependencies |
| 47 | + Bundle-Copyright: OSGi enRoute |
| 48 | + Bundle-Vendor: OSGi Alliance |
| 49 | + |
| 50 | +## Build Path |
| 51 | + |
| 52 | +If you save the `bnd.bnd` file then the DOM4J JAR is added to your _build path_. We can inspect the contents by |
| 53 | +looking in the Eclipse Class Path container. This is the little bookshelf with the title: `Bnd Bundle Path`. The little arrow on the left allows you to open the container to see the contents. Also open the `dom4j-1.6.1` member of this container. |
| 54 | + |
| 55 | +{: width="70%" } |
| 56 | + |
| 57 | +## Exporting |
| 58 | + |
| 59 | +Inspecting the list of packages inside the `dom4j-1.6.1` JAR shows that all package names start with `org.dom4j`. We therefore start by exporting these packages. The easiest way to do this to stay in the `Source` tab and add the text: |
| 60 | + |
| 61 | + Export-Package: org.dom4j.* |
| 62 | + |
| 63 | +This will export all packages on the `-buildpath` that start with `org.dom4j`! |
| 64 | + |
| 65 | +## The Bundle |
| 66 | + |
| 67 | +We've actually generated the bundle now. If you look in the folder `generated` then you'll find the JAR . Opening this JAR in the JAR Editor that is included with Bndtools will show you the manifest. (The `Print` tab is a little more readable.) This manifest looks (slightly reformatted) like: |
| 68 | + |
| 69 | + [MANIFEST osgi.enroute.examples.wrapping.dom4j.adapter.jar] |
| 70 | + Bnd-LastModified 1458829936934 |
| 71 | + Bundle-Copyright OSGi enRoute |
| 72 | + Bundle-Description Wraps DOM4J for OSGi, including |
| 73 | + the primary dependencies |
| 74 | + Bundle-ManifestVersion 2 |
| 75 | + Bundle-Name osgi.enroute.examples.wrapping.dom4j.adapter |
| 76 | + Bundle-SymbolicName osgi.enroute.examples.wrapping.dom4j.adapter |
| 77 | + Bundle-Vendor OSGi Alliance |
| 78 | + Bundle-Version 1.6.1.201603241432 |
| 79 | + Created-By 1.8.0_25 (Oracle Corporation) |
| 80 | + Import-Package com.sun.msv.datatype, |
| 81 | + com.sun.msv.datatype.xsd, |
| 82 | + javax.swing.table, |
| 83 | + javax.swing.tree, |
| 84 | + javax.xml.namespace, |
| 85 | + javax.xml.parsers, |
| 86 | + javax.xml.stream, |
| 87 | + javax.xml.stream.events, |
| 88 | + javax.xml.stream.util, |
| 89 | + javax.xml.transform.sax, |
| 90 | + org.gjt.xpp, |
| 91 | + org.jaxen,org.jaxen.dom4j, |
| 92 | + org.jaxen.pattern, |
| 93 | + org.jaxen.saxpath, |
| 94 | + org.relaxng.datatype, |
| 95 | + org.w3c.dom, |
| 96 | + org.xml.sax, |
| 97 | + org.xml.sax.ext, |
| 98 | + org.xml.sax.helpers, |
| 99 | + org.xmlpull.v1 |
| 100 | + Manifest-Version 1.0 |
| 101 | + Private-Package org.dom4j.rule.pattern, |
| 102 | + org.dom4j.swing, |
| 103 | + org.dom4j.tree, |
| 104 | + org.dom4j.dtd, |
| 105 | + org.dom4j.util, |
| 106 | + org.dom4j.xpp, |
| 107 | + org.dom4j, |
| 108 | + org.dom4j.bean, |
| 109 | + org.dom4j.datatype, |
| 110 | + org.dom4j.rule, |
| 111 | + org.dom4j.io, |
| 112 | + org.dom4j.xpath |
| 113 | + Require-Capability osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.3))" |
| 114 | + Tool Bnd-3.2.0.201603172351-SNAPSHOT |
| 115 | + |
| 116 | +Obviously we succeeded in including the `org.dom4j` packages but we got a few imports that are not in the JVM like `org.jaxen`, `org.gjt.xpp`, and `org.relaxng`. |
| 117 | + |
| 118 | + |
| 119 | +[DOM4J]: http://jpm4j.org/#!/p/org.jdom/jdom |
| 120 | +[JPM4J]: http://jpm4j.org/ |
| 121 | +[-conditionalpackage]: http://bnd.bndtools.org/instructions/conditionalpackage.html |
| 122 | +[blog]: http://njbartlett.name/2014/05/26/static-linking.html |
| 123 | +[133 Service Loader Mediator Specification]: http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html |
| 124 | +[semanticaly versioned]: http://bnd.bndtools.org/chapters/170-versioning.html |
| 125 | +[135.3 osgi.contract Namespace]: http://blog.osgi.org/2013/08/osgi-contracts-wonkish.html |
| 126 | +[BSD style license]: http://dom4j.sourceforge.net/dom4j-1.6.1/license.html |
| 127 | +[supernodes of small worlds]: https://en.wikipedia.org/wiki/Small-world_network |
| 128 | +[OSGiSemVer]: https://www.osgi.org/wp-content/uploads/SemanticVersioning.pdf |
| 129 | +[osgi.enroute.examples.wrapping.dom4j.adapter]: https://github.com/osgi/osgi.enroute.examples/tree/485624f6cb66df91f668d6eb9a5c8e491312c8c4/osgi.enroute.examples.wrapping.dom4j.adapter |
0 commit comments