java使用jdk。内部的网http
我想使用ResponseSubscribers.ByteArraySubscriber
中的jdk.internal.net.http
。我使用openjdk11
我尝试了两件事:
一,/ 我添加了maven编译器插件导出模块
<compilerArgs>
<arg>--add-exports</arg><arg>java.net.http/jdk.internal.net.http=fr.app</arg>
</compilerArgs>
->;是的
二,/ 我创建了模块信息。爪哇
module fr.app {
requires java.net.http;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.datatype.jsr310;
exports fr.app;
exports fr.app.parser;
}
运行使用类导入jdk.internal.net.http
的junit测试时出错
fr.app.AppException: java.io.IOException: class fr.app.MyClass$BodySubscribers (in unnamed module @0x6537cf78) cannot access class jdk.internal.net.http.ResponseSubscribers$ByteArraySubscriber (in module java.net.http) because module java.net.http does not export jdk.internal.net.http to unnamed module @0x6537cf78
我理解BodySubscribers
必须仅在命名模块中导出。但我的模块名为fr.app
,对吗
# 1 楼答案
不完全是这样,当您在项目中创建了
module-info.java
时,在应用程序的执行过程中,您的实际代码似乎最终会在类路径上找到因此,您的
MyClass
位于the unnamed module中,错误如下另一方面,您提到的类似乎是打包到
java.net.http
模块的内部,不应该依赖于您的代码。您必须实现自己的订阅服务器,即使您希望获得与正在查看的代码类似的功能。因为模块无论如何都不会导出供公共使用# 2 楼答案
您不应该直接使用任何
jdk.internal.*
包中的任何类。您是否尝试过使用公共APIHttpResponse.BodySubscribers.ofByteArray()