javaspringsource-dm-servereclipse-virgo

Resolving Virgo dependencies from bundles with jars


I'm trying to wrap a number of jars as bundles that I want other bundles to be able to depend on. With Spring dm Server, this used to be as simple as adding a jar file to a new bundle project, exporting all the classes, and ensuring the jar file was on the build and class paths.

Here's a simple, canonical example of what I'm trying to do (and where I'm failing):

Take, for instance, Joda Time, I'd like this in a bundle so I can share it as a dependency. First, I create a bundle to hold the jar:

  1. Create a new bundle project Eclipse (Indigo Java EE)
  2. Create a folder "lib" in the project root
  3. Add joda-time-1.6.1.jar to the "lib" folder
  4. Add lib/joda-time-1.6.1.jar to the build path
  5. Update src/META-INF/MANIFEST.MF to export all of the classes:

    Manifest-Version: 1.0
    Bundle-Version: 1.0.0
    Bundle-Name: joda-time
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: org.joda.time
    Bundle-ClassPath: lib/joda-time-1.6.1.jar,
     .
    Export-Package: org.joda.time,
     org.joda.time.base,
     org.joda.time.chrono,
     org.joda.time.convert,
     org.joda.time.field,
     org.joda.time.format,
     org.joda.time.tz
    

Now, we want to use this in some new bundle we've created:

  1. Create a new bundle project in Eclipse (Indigo Java EE) "MyDepTest"
  2. Edit src/META-INF/MANIFEST.MF to import org.joda.time:

    Manifest-Version: 1.0
    Bundle-Version: 1.0.0
    Bundle-Name: MyDepTest
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: com.foo.deptest
    Import-Package: org.joda.time
    Import-Bundle: org.joda.time;version="[1.0.0,1.0.0]"
    
  3. Add the org.joda.time bundle to the project references so Eclipse can resolve the depenencies

  4. Write the class:

    package com.foo.deptest;
    import org.joda.time.DateTime;
    public class SimpleDepTest {
        public SimpleDepTest (){
            DateTime dt = new DateTime();
        }
    }
    

Now, org.joda.time.DateTime should resolve, but Eclipse indicates the following error with a red underline on org.joda

The import org.joda cannot be resolved

Where have I gone wrong? How do I wrap a jar as a bundle so that I can use the classes in other bundles?


Solution

  • It turns out it's not sufficient to add the jar to the classpath, we also need to make sure it's part of the build path. This is done in the build configuration dialog:

    1. Right mouse click on project exporting dependencies
    2. Select "Properties"
    3. Select "Java Build Path"
    4. Go to the "Order and Export" tab
    5. Make sure the checkbox next to the jar is checked (this makes sure the jar itself ends up on the build path)