标题翻译
StreamSource - which module for module-info?
问题
使用 javax.xml.transform.stream.StreamSource 在一个非常简单的程序中。
使用 Eclipse 和 Java 13。
配置 Java Build Path Modulepath 包含 JRE SystemLibrary [JavaSE-13] 。
我已经在 module-info.java 中添加了 requires java.base; 。
但是仍然出现问题:Eclipse 无法编译该类:
类型 javax.xml.transform.stream.StreamSource 不可访问
我漏掉了什么?
英文翻译
Using javax.xml.transform.stream.StreamSource in a very simple program.<BR/>
Using Eclipse and Java 13.<BR/>
Configured Java Build Path Modulepath to contain JRE SystemLibrary [JavaSE-13] .<BR/>
I have added requires java.base; to module-info.java.<BR/>
But still: Eclipse cannot compile that class:<BR/>
The type javax.xml.transform.stream.StreamSource is not accessible
What do I miss?
答案1
得分: 0
根据StreamSource
的文档,该类位于java.xml
模块中:
这意味着要在你的模块中使用StreamSource
,你需要以下的module-info:
module <your-module-name> {
requires java.xml;
// 其他需要的 requires、exports、opens、uses 和 provides 指令(根据需要)
}
请注意,你不需要包括requires java.base;
,因为该模块会被每个模块隐式地要求,类似于你不需要从java.lang
包导入类一样。
英文翻译
As documented by StreamSource
, that class is in the java.xml
module:
Which means to use StreamSource
in your module you need the following module-info:
module <your-module-name> {
requires java.xml;
// other requires, exports, opens, uses, and provides directives (as needed)
}
Note you don't need to include requires java.base;
as that module is implicitly required by every module, similar to how you don't need to import classes from the java.lang
package.
专注分享java语言的经验与见解,让所有开发者获益!
评论