12

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):

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

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?
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
Thue
  • 153
  • 1
  • 1
  • 8
  • Similar: [*package javax.jnlp is declared in module java.jnlp, which is not in the module graph*](https://stackoverflow.com/q/45419935/642706) – Basil Bourque Jul 23 '18 at 00:17

1 Answers1

18

This is a result of the new Java 9 modules. The javax.xml.soap package 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.

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

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
  • 7
    Be aware that the **`--add-modules` workaround is for Java 9 and Java 10 only**. Java 11 and later removes the [Java EE](https://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition) related modules entirely from [Java SE](https://en.wikipedia.org/wiki/Java_Platform%2C_Standard_Edition), as responsibility is relocated to the [Jakarta EE](https://jakarta.ee) organization. For details, see [*JEP 320: Remove the Java EE and CORBA Modules*](http://openjdk.java.net/jeps/320) – Basil Bourque Jul 29 '18 at 02:20