Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.3449 :

Posted: Sun Sep 08, 2019 11:31 am
by sir_Anduin@yahoo.de
I have a question regardning the META-INF/services file

does a service module have to declare it?

And how to I enforce that a service is present on the module? I mean that (my Main module==Service consumer) can access at least one Implementation of the service?

Re: About Question enthuware.ocpjp.ii.v11.2.3449 :

Posted: Tue Sep 10, 2019 10:48 pm
by admin
1. META-INF/services file is not required when you deploy a service as a module. In this case, only the provides clause in module-info is required.
META-INF/services is used for a regular , non-modular application, in which a service is loaded from classpath. (Ref. https://docs.oracle.com/en/java/javase/ ... oader.html )

2. There is no way to ensure that. Indeed, the whole point is that the service implementation should not be required for successful compilation of a service user. At run time, if the module system doesn't find any service implementation for a particular service, the application will not run.

Re: About Question enthuware.ocpjp.ii.v11.2.3449 :

Posted: Thu Apr 25, 2024 6:29 pm
by pavvel
Can someone clarify the line in this documentation: https://docs.oracle.com/en/java/javase/ ... oader.html
It says: "It is strongly recommended that the module does not export the package containing the service provider." in Deploying service providers as modules chapter.
But there is a problem here. If the module does not export the package containing the interface implementation, the other module can't import uses class. It will be a comperr.

Code: Select all

module moduleOne {
    //exports someService;
    provides someService.someInterface with someService.someInterfaceImplementationOne, someService.someInterfaceImplementationTwo;
}

Code: Select all

module moduleTwo {
    requires moduleOne;
    uses someService.someInterfaceImplementationOne;
}
Is it correct that we must export the package with the implementation?

Re: About Question enthuware.ocpjp.ii.v11.2.3449 :

Posted: Thu Apr 25, 2024 7:14 pm
by admin
Ideally, your service interface should be in a different package.