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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10075
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

pavvel
Posts: 10
Joined: Fri Dec 15, 2023 4:00 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10075
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests