[HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

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

Moderator: admin

Post Reply
nk2164
Posts: 21
Joined: Mon Sep 30, 2019 9:48 pm
Contact:

[HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

Post by nk2164 »

In this section, you talk about creating multiple modules (simpleinterest and calculator) and then executing them. I wanted to know if its possible to create a single jar file that includes both these modules and then execute them . Is that possible ?

I tried the following, but the resulting jar file only had simpleinterest class and its corresponding module-info.java

Code: Select all

jar --create --file simpleinterest.jar --main-class simpleinterest.SimpleInterestCalculator -C out/simpleinterest .
Then i tried this

Code: Select all

jar --create --file simpleinterest.jar --main-class simpleinterest.SimpleInterestCalculator -C out .
This bought in both the modules into simpleinterest.jar but i was not able to get it to run.

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

Re: [HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

Post by admin »

You can't have two modules in the same jar file. The book notes on page 402 under Packaging a module:
The only thing special about a module jar is that the name of the jar is, by convention, the same as the name of the module (with .jar extension, of course). Inside the jar file, class files must still exist in their package driven directory structure just like before. Observe that a module also has a module-info.class in its root folder. This class must be in the root folder of the module’s jar as well.
Since there is a module-info.class for each module but only one module-info.class can reside in the root of a jar, it is not possible to put two modules in the same jar.

Of course, you can create a regular jar and put all the classes in it and run it as a regular jar but you can't use module options with this jar.
If you like our products and services, please help us by posting your review here.

nk2164
Posts: 21
Joined: Mon Sep 30, 2019 9:48 pm
Contact:

Re: [HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

Post by nk2164 »

Thank you for the clarification. One last question - for packing applications into formats like EAR's WAR's etc , i can still package these multiple modular jars just like today right ? I would think this should not change.

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

Re: [HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

Post by admin »

Yes, there is no difference in the internal structure of a module jar and a regular jar. You can use a module jar just as you use a regular jar.
If you like our products and services, please help us by posting your review here.

nk2164
Posts: 21
Joined: Mon Sep 30, 2019 9:48 pm
Contact:

Re: [HD Pg 0, Sec. 16.3.1 - enabling-access-between-modules]

Post by nk2164 »

Great. Thank you so much.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests