5

I have recently migrated from Java 8 to Java 11. for jax.ws

I had to add following external dependency to my pom.xml as it's no longer available in Java 11. However, I came across some argument that com.sun.* package classes should not be used and should be avoided if possible. So is it sun.* or com.sun.*? If latter is true as well, what would be the best possible replacement for this?

One more thing, this dependency is not directly used by my code but it's referred by one of my other dependencies.

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.10</version>
    </dependency>
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Sagar
  • 5,315
  • 6
  • 37
  • 66
  • 3
    The 'Note on `sun.*` packages' applies explicitly to `sun.*` only. Many classes in `com.sun.*` are explicitly documented as part of the API, such as the JNDI providers, the HTTP server, and, back in the day, JSSE. Unfortunately some IDE authors don't appear to be aware of this and cause their products to issue incorrect warnings about them. – user207421 Apr 22 '19 at 19:15
  • 4
    However not all com.sun.* packages are exposed. Many of them (like com.sun.jmx.*) are purely internal and shouldn't be used. In java 11 things are much clearer than before because these internal APIs are now encapsulated by the module system. If a com.sun.* package is a public API that can be used, it will be unconditionally exported by the module that defines it. – daniel Apr 23 '19 at 10:24

1 Answers1

7

Some com.sun.* classes are actual external API and may be used. The key is to check the official Javadoc to see if the classes you want to use are listed as API, and not marked @Deprecated or anything of that sort.

Here is the official javadoc page to check at: https://docs.oracle.com/en/java/javase/11/docs/api/index.html

In general, sun.* API refers to some of the oldest Java APIs (such as sun.misc.Unsafe) which predate the reverse-DNS package naming convention. Most of the original sun.* APIs have either been removed, promoted to official javax.* API, or renamed to the more proper com.sun.* domain.

There is nothing inherently wrong with using com.sun.* APIs, provided the API is not a JDK internal or marked for deprecation/removal.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61