JDK9中预定义的模块是什么?或者我需要修复依赖关系的模块? [英] What are the predefined modules in JDK9 or Which module do I need to fix dependency problems?
问题描述
JDK9将(可能)引入一个模块系统.作为其一部分,Java类库将被模块化.
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?
推荐答案
我如何找到合适的模块作为依赖项?
how do I find the proper module to include as a dependency?
考虑这个欺骗类:
import java.sql.DriverManager;
import java.rmi.RemoteException;
public class UserDao {
DriverManager driverManager = null;
public void service() throws RemoteException {
if (true) {
throw new RemoteException();
}
}
}
让我们假设此类已编译为user-dao.jar
.答案是jdeps工具(使用9ea170):
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
(请注意,jdeps
随JDK 8一起提供,但在JDK 9中更合适.)
(Note that jdeps
shipped with JDK 8 but is much more appropriate in JDK 9.)
出于完整性考虑,如果您知道代码使用特定的类(例如java.sql.DriverManager
)并且怀疑需要一个模块(例如java.sql
),则可以通过
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
这篇关于JDK9中预定义的模块是什么?或者我需要修复依赖关系的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!