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

£可爱£侵袭症+ 提交于 2019-11-29 08:18:08

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

The complete list of modules is available here. http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html

It lists 73 modules which will make up the Java Class Library. For each, there is a list of packages included and a list of other modules it depends on.

Given a class that doesn't get loaded one can search for the start of the package name on that site, in order to determine the module to depend on.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!