Why can't I import sun packages?
Asked Answered
C

1

5

I downloaded java 9 from https://jdk9.java.net and installed it on my Windows 10 machine.
Java 9 has jshell, which I can use to evaluate and learn java programming.
Some examples import sun packages, such as sun.audio.* etc. But, in jshell, every time I try to import any sun package, it says the sun package does not exist.

Some applications do not work with java 9. Perhaps there are incompatibilities?

Covert answered 28/10, 2016 at 21:32 Comment(0)
H
10

It seems that this is related to how Java 9 tries to support encapsulation for real, in contrast to how it was done in the past. It could have happened that your internal classes were exposed to consumers, because your the public API used those internal classes. Sun internal packages had a similar issue.

There are three topics in the modularity story for Java 9:

  • Modularize the JDK and JRE
  • Hide platform internals (e.g. sun.misc)
  • A module system for application developers

http://paulbakker.io/java/java-9-modularity/

For your specific case, the sun internal modules are not available for import by default and that is a good thing.

That said, modules can be added to JShell thanks to a fix.

There should be "add modules" support as well as "add exports" and "module path", to allow people to explore their own modular code. https://bugs.openjdk.java.net/browse/JDK-8166649

You want to track that bug ticket to see when this fix is available. It was just resolved 4 days ago.

Hooks answered 29/10, 2016 at 6:48 Comment(1)
Good investigation! The fix should be available in JDK 9 early access builds on jdk9.java.net by the end of next week.Macknair

© 2022 - 2024 — McMap. All rights reserved.