Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

java - What are the predefined modules in JDK9 or Which module do I need to fix dependency problems?

JDK9 will (probably) introduce a module system. As part of that, the Java Class Library will get modularized.

This can lead to exceptions when classes don't get found because they are in a module that isn't specified as a dependency yet.

What are the modules that will get created with the module system and what is their respective content?

Or stated differently: Given a class that doesn't get loaded, how do I find the proper module to include as a dependency?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

how do I find the proper module to include as a dependency?

Consider this spoof class:

import java.sql.DriverManager;
import java.rmi.RemoteException;

public class UserDao {
    DriverManager driverManager = null;

    public void service() throws RemoteException {
        if (true) {
            throw new RemoteException();
        }
    }
}

Let's assume that this class is compiled into user-dao.jar. The jdeps tool is the answer (using 9ea170):

jdeps --list-deps user-dao.jar
   java.base
   java.rmi
   java.sql

(Note that jdeps shipped with JDK 8 but is much more appropriate in JDK 9.)

For completeness, if you know that the code uses a specific class (e.g. java.sql.DriverManager) and you suspect a module is required (e.g. java.sql), one could confirm the module via the doc, or on the command-line (again with 9ea170):

bash$ java --describe-module java.sql
java.sql@9-ea
exports java.sql
exports javax.sql
exports javax.transaction.xa
requires java.xml transitive
requires java.base mandated
requires java.logging transitive
uses java.sql.Driver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...