Page 1 of 1

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

Posted: Wed Aug 14, 2019 1:36 pm
by dongyingname

Code: Select all

module abc.myapp{   
	requires com.abc.datalayer;
}
Could some one explain why this is not the option?
I am assuming myapp.jar and datalayer.jar are in the same folder and is that why com.abc is omitted?
Why is the application module called abc.myapp while the dependency is called datalayer not abc.datalayer?

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

Posted: Wed Aug 14, 2019 4:15 pm
by admin
myapp.jar is being modularized, so, its module name can be anything that you want. From the options, it looks like it is being named abc.myapp.

datalayer.jar is not being modularized. This jar is being used as an automaric module, so, its module name will be datalayer.

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

Posted: Sat Jan 09, 2021 6:29 am
by teodorj
Note: There are two possible ways for an automatic module to get its name:
1. When an Automatic-Module-Name entry is available in the manifest, its value is the name of the automatic module.
2. Otherwise, a name is derived from the JAR filename (see the ModuleFinder JavaDoc for the derivation algorithm) -
Basically, hyphens are converted into dots and the version number part is ignored.
So, for example, if you put mysql-connector-java-8.0.11.jar on module path, its module name would be mysql.connector.java
If I am modularizing my application and dependent on other jars i.e analytics and added in module path as automatic module..

1) Can I provide automatic module name programatically in module-info.java (using ModuleDescriptor.name() method ) of my app?
2) I will just use ModuleFinder to get the name and manually add the name in my appplication's module-info.java?

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

Posted: Sat Jan 09, 2021 12:08 pm
by admin
Sometimes, a provider may want to modularize their jar in near future but hasn't completed that task. In that case, they may add a Automatic-Module-Name entry in their jar's manifest. So, if you put that jar in your module-path, it will still be an automatic module (because there will be no module-info.class file in that jar), but the name of that automatic module will be the name that the provider specified in the Automatic-Module-Name entry.

If you are modularizing your application and are dependent on third party analytics jar, you can directly add it to module-path. You don't add module-info to that jar because it is not your jar.

Regarding Module finder, it is not on for the exam. You are overthinking.

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

Posted: Sat Jan 09, 2021 1:38 pm
by teodorj
I am just thinking about the application of the concept regarding adding name in requires directive in my app's module-info(getting automatic module name of third party)

Yes this is not in exam coverage. Im just applying the theories in real project. :D

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

Posted: Sat Jan 09, 2021 9:37 pm
by admin
Name of an automatic module is always known at compile time. It is either the same as the jar file name (without the dashes and version number) or it is what is specified in Automatic-Module-Name entry in the jar's manifest.

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

Posted: Sun Oct 10, 2021 6:50 am
by floryan
datalayer will be able to access mysql classes if you simply put the mysql jar on the classpath.
It would also work, if we put the mysql jar on the module path as automatic module too, right?

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

Posted: Sun Oct 10, 2021 7:17 am
by admin
yes, automatic modules can access any class anywhere. But, of course, you don't want to put anything on module-path unless you really need to because you don't want anything to have access to everything else.