Skip to content

jakarta.mail-api-2.1.0.jar does not work in OSGi environment #629

@mnlipp

Description

@mnlipp

Describe the bug
An attempt has been made to solve service loader problems in an OSGi environment with org.glassfish.hk2.osgi-resource-locator.

The presence of the required class org.glassfish.hk2.osgiresourcelocator.ServiceLoader is detected with the code

    private static boolean isOsgi() {
        try {
            Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
            return true;
        } catch (ClassNotFoundException ignored) {
        }
        return false;
    }

In order for this to work, class org.glassfish.hk2.osgiresourcelocator.ServiceLoader must be in the bundle's classpath (jar becomes "bundle" in OSGi). But the required import is missng in MANIFEST.MF and therefore the provider services are not found.

How it should be
For comparison: jakarta.activation-api-2.1.0.jar has in its MANIFEST.MF the line:

DynamicImport-Package: org.glassfish.hk2.osgiresourcelocator

which ensures that the class org.glassfish.hk2.osgiresourcelocator.ServiceLoader is in the classpath and the Class.forName is successful.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy jakarta.mail-api-2.1.0.jar in an OSGi enviroment
  2. Attempt to use the IMAP provider

Expected behavior
Provider should be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions