Class ServiceProviderBuildItem


  • public final class ServiceProviderBuildItem
    extends MultiBuildItem
    Represents a Service Provider registration. When processed, it embeds the service interface descriptor (META-INF/services/...) in the native image and registers the classes returned by providers() for reflection (instantiation only).
    • Constructor Detail

      • ServiceProviderBuildItem

        public ServiceProviderBuildItem​(String serviceInterfaceClassName,
                                        String... providerClassNames)
        Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
        Parameters:
        serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
        providerClassNames - the list of provider class names that must already be mentioned in the file
      • ServiceProviderBuildItem

        public ServiceProviderBuildItem​(String serviceInterfaceClassName,
                                        Collection<String> providers)
        Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
        Parameters:
        serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
        providers - a collection of provider class names that must already be mentioned in the file
      • ServiceProviderBuildItem

        public ServiceProviderBuildItem​(String serviceInterfaceClassName,
                                        List<String> providers)
        Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only) of the specified provider classes. Note that the service interface descriptor file has to exist and match the list of specified provider class names.
        Parameters:
        serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
        providers - the list of provider class names that must already be mentioned in the file
    • Method Detail

      • allProviders

        public static ServiceProviderBuildItem allProviders​(String serviceInterfaceClassName,
                                                            Path serviceInterfaceDescriptorFile)
                                                     throws IOException
        Creates and returns a ServiceProviderBuildItem for the serviceInterfaceClassName by including all the providers that are listed in the service interface descriptor file.
        Parameters:
        serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
        serviceInterfaceDescriptorFile - the path to the service interface descriptor file
        Returns:
        Throws:
        IOException
      • allProvidersFromClassPath

        public static ServiceProviderBuildItem allProvidersFromClassPath​(String serviceInterfaceClassName)
        Creates and returns a new ServiceProviderBuildItem for the given serviceInterfaceClassName by including all the providers that are listed in service interface descriptor files "META-INF/services/" + serviceInterfaceClassName findable in the Context Class Loader of the current thread.
        Parameters:
        serviceInterfaceClassName - the interface whose service interface descriptor file we want to embed
        Returns:
        a new ServiceProviderBuildItem
        Throws:
        RuntimeException - wrapping any IOExceptions thrown when accessing class path resources
      • providers

        public List<String> providers()
        Returns:
        a immutable List of provider class names
      • serviceDescriptorFile

        public String serviceDescriptorFile()
        Returns:
        the resource path for the service descriptor file