How to get all sun.font classes in jdk9

I have my old code base that currently uses java8 .

I am moving my codebase to use jdk9-ea . But it looks like all sun.font classes are now inaccessible, as sooner than before.

error: package sun.font does not exist 

In particular, I use

  • Composite composite
  • Font2d
  • FontDesignMetrics
  • Fontmanager
  • FontManagerFactory
  • Sunfontmanager

and more..

+6
source share
1 answer

A feature of the modular system is that it allows library developers to heavily encapsulate implementation details due to new accessibility rules. In a nutshell, most types in the sun.* And com.sun.* will no longer be available. This is consistent with Sun and later by Oracle, stating that these packages are not intended for public consumption.

The workaround is to export these packages at compile time and run using the command line flag:

 --add-exports java.desktop/sun.font=ALL-UNNAMED 

This exports the sun.font package from the java.desktop module to all modules, including the unnamed module , which is the one that collects all the classes in the class path.

+8
source

Source: https://habr.com/ru/post/1013738/


All Articles