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?
About Question enthuware.ocpjp.ii.v11.2.3449 :
Moderator: admin
-
- Posts: 62
- Joined: Fri Aug 07, 2015 2:16 pm
- Contact:
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3449 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Fri Dec 15, 2023 4:00 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3449 :
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.
Is it correct that we must export the package with the implementation?
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;
}
-
- Site Admin
- Posts: 10090
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.ii.v11.2.3449 :
Ideally, your service interface should be in a different package.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 20 guests