Last updated Apr 25, 2024

In order to use Spring Java configuration in your P2 app, the Import-Package header in your app's META-INF/MANIFEST.MF file needs to contain the following entries:

  • org.springframework.cglib.core
  • org.springframework.cglib.proxy
  • org.springframework.cglib.reflect

There are three ways to make this happen:

Option 1 - easiest and least maintenance

  • Enable automatic package detection by including a * entry in your AMPS Import-Package instructions, and
  • Add a dependency on our helper library com.atlassian.plugins:atlassian-plugins-osgi-javaconfig (see the dependencies page)

In the scenario above, AMPS will trigger the BND tool to scan the type references in your classpath. BND will detect the Imports class in our library and its usages of the above packages, and add the necessary Import-Package entries for you.

Option 2 - simpler but brittle

Add the above packages explicitly to your AMPS Import-Package instructions. This will work, but has these drawbacks:

  • Your fellow developers may not understand the rationale for these extra entries.
  • These entries may become incorrect over time if the list of required packages changes (whereas our library will always ensure the required packages are imported).

Option 3 - copy our code

  • Enable automatic package detection by including a * entry in your AMPS Import-Package instructions, and
  • Add the following class anywhere in your app. BND will generate the required Import-Package entries because it detects binary references to the relevant packages:
1
2
// Call this class anything you like, its only purpose is to contain package references
final class SyntheticPackageImports {

    private org.springframework.cglib.reflect.FastClass fastClass;
    private org.springframework.cglib.proxy.MethodProxy methodProxy;
    private org.springframework.cglib.core.ReflectUtils reflectUtils;
}

Like Option 2, the drawbacks of this approach are:

  • you need to document this class to explain why it exists despite apparently being unused
  • this list of required packages may become out of date over time

Rate this page: