Page 1 of 1

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

Posted: Wed Dec 04, 2019 5:02 am
by kabanvau
Hi,

In option 1:
3. Add requires clauses for all packages contained in analytics.jar and ojdbc8.jar that are directly referred to by classes in reports.jar in its module-info.java.

But why? analytics.jar and ojdbc8.jar are automatic modules. So you have to require the two jar files in module-info.java:

requires analytics;
requires ojdbc8;

And later you can import all packages you need inside your report project. No need to require any packages in module-info.java.


Here is another example:

module-info.java

Code: Select all

module automatic {
    /* AUTOMATIC MODULE */
   /* commons-csv-1.7.jar */
    requires commons.csv;
}
Main.java

Code: Select all

package automatic.main;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import java.io.FileReader;
import java.io.IOException;
public class Main {
    public static void main(String[] args) {
        try {
            var in = new FileReader("countries.csv");
            Iterable<CSVRecord> records = CSVFormat.EXCEL.withDelimiter(';')
                    .withHeader().parse(in);
            for (CSVRecord record : records) {
                String name = record.get(1);
                System.out.println(name);
            }
            in.close();
        } catch (IOException e) {
        }
    }
}

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

Posted: Wed Dec 04, 2019 6:12 am
by admin
You are right. The option should just say requires clauses for the two modules not packages. Fixed.
thank you for your feedback!
Paul.