6

I have to use java.xml.ws* components in my project but because it's deprecated and will be removed soon I want to use replacement for these components. So I added this dependency to my project's pom file:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-ri</artifactId>
    <version>2.3.0</version>
    <type>pom</type>
</dependency>

This is my module configuration:

module x.y.z {
    requires kotlin.stdlib;
    requires spring.boot;
    requires spring.boot.autoconfigure;
    requires spring.context;
    requires cxf.core;
    requires cxf.rt.frontend.jaxws;
    requires java.xml.ws;
}

But there is an error:

enter image description here

What does it mean and how to fix it so I can use my dependency above instead of java.xml.ws from jdk?

ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
nllsdfx
  • 900
  • 14
  • 30

2 Answers2

5

Just use Java 11 :) There is no javax.xml.ws module there, so no conflict.

As for Java 10, the easiest workaround is to change the scope of jaxws-ri to runtime:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-ri</artifactId>
    <version>2.3.0</version>
    <scope>runtime</scope>
</dependency>
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
3

By adding requires java.xml.ws you tell the module system that you depend in the deprecated Java EE module java.xml.ws, which it will then resolve and make available. At the same time there seems to be a module of the same name on the module path. (Maybe a JAR pulled in by jaxws-ri?)

Although, come to think of it, I would have expected a compiler message complaining of duplicate modules... It looks like the error (is it compiler or runtime?) comes from an IDE. What happens if you run the build with Maven?

Anyways, if you are willing to start with Java 11, you could give that a try. The Java EE modules are removed, so there is no chance of a platform module interfering. I'm not sure whether it is possible to add a java.* module on the module path, though.

If it is not or you prefer to stick to Java 10, you should take a look at upgreadable modules and the --upgrade-module-path option. That way you can use the JARs that provide the JAX WS API to replace the platform module.

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
  • There is no issue with putting java.* modules on the module path. However, you are right that something is fishy in the original question as the `requires java.xml.ws` will cause the java.xml.ws in the run-time image to be resolved, the version on the module path will be ignored. So I think I'd like to hear more to explain the strange error. – Alan Bateman May 20 '18 at 18:27