“包 javax.xml.soap 在模块 java.xml.ws 中声明,该模块不在模块图中”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46084302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:03:27  来源:igfitidea点击:

"package javax.xml.soap is declared in module java.xml.ws, which is not in the module graph"

java

提问by Thue

So I took the SOAP example at Working Soap client example, put it into a file SOAPClientSAAJ.java, and tried compiling it (Openjdk 9 on Debian):

因此,我在Working Soap client example 中采用了 SOAP 示例,将其放入文件中SOAPClientSAAJ.java,并尝试编译它(Debian 上的 Openjdk 9):

t@h ~/javatest> javac SOAPClientSAAJ.java 
SOAPClientSAAJ.java:1: error: package javax.xml.soap is not visible
import javax.xml.soap.*;
                ^
  (package javax.xml.soap is declared in module java.xml.ws, which is not in the module graph)
1 error

After Googling some, I found out that compiling and running as

谷歌搜索后,我发现编译和运行为

t@h ~/javatest> javac --add-modules java.xml.ws SOAPClientSAAJ.java
t@h ~/javatest> java --add-modules java.xml.ws SOAPClientSAAJ

works. See also this video for general background: https://www.youtube.com/watch?v=y8bpKYDrF5I&t=20m17s

作品。另请参阅此视频了解一般背景:https: //www.youtube.com/watch?v=y8bpKYDrF5I&t=20m17s

Now, questions:

现在,问题:

  1. Shouldn't the compiler automatically add the module java.xml.ws ? (since it obviously knows it is needed) Is this a bug in javax.xml.soap ?
  2. Why is the --add-modules option not documented in my man pages? (openjdk 9 in Debian)
  3. What should I write in the .java file to automatically add the java.xml.ws module?
  1. 编译器不应该自动添加模块 java.xml.ws 吗?(因为它显然知道它是需要的)这是 javax.xml.soap 中的错误吗?
  2. 为什么我的手册页中没有记录 --add-modules 选项?(Debian 中的 openjdk 9)
  3. 我应该在.java文件中写什么来自动添加java.xml.ws模块?

回答by Evan Knowles

This is a result of the new Java 9 modules. The javax.xml.soappackage is actually a Java EE package, and so now isn't visible. The current workaround is to either use the --add-modules, as you've done, or to modularize your code.

这是新的 Java 9 模块的结果。该javax.xml.soap实际上是一个 Java EE 包,因此现在不可见。当前的解决方法是使用--add-modules,就像您所做的那样,或者模块化您的代码

Modularizing your code requires restructuring it into modules, and including a module-info.javafile that specifies the modules you're using. In your case, specifying java.se.eewould give access to all the EE modules.

模块化您的代码需要将其重组为模块,并包含一个module-info.java指定您正在使用的模块的文件。在您的情况下,指定java.se.ee将提供对所有 EE 模块的访问权限。