Eclipse/Java9: how to access internal javafx packages?

Viewed 10588

My context:

  • Eclipse IDE for Java Developers, Version: Oxygen.1a Release (4.7.1a), Build id: 20171005-1200oxygen
  • jdk9.0.1
  • win10

Something simple like:

import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;

import javafx.application.Application;
import javafx.stage.Stage;

public class ImportCom extends Application {

    @Override
    public void start(Stage arg0) throws Exception {
        new LambdaMultiplePropertyChangeListenerHandler();

    }

}

won't compile due to

The type com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler is not accessible

What to do?

looks similar but now for internal classes ;) Had been compiling until patch 530 of the beta9 support but not after - so keeping that oldish oxygen as a gold treasure ...

Note: cross-posted to eclipse forum

Edit:

Just checked that the behavior of javac on the commandline:

C:\Users\kleopatra\ox-1a-64\dummy\src>\java\jdk\190-64\bin\javac first\ImportCom.java
first\ImportCom.java:3: error: package com.sun.javafx.scene.control is not visible
import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;
                           ^
  (package com.sun.javafx.scene.control is declared in module javafx.controls, which does not export it to the unnamed module)
1 error

The error is similar to the one in Eclipse. Works fine with --add-exports:

C:\Users\kleopatra\ox-1a-64\dummy\src>\java\jdk\190-64\bin\javac --add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED first\ImportCom.java

So the question boils down to: where/how to configure Eclipse such that it compiles access to internal classes just the same way as javac?

3 Answers
  1. In Project > Properties: Java Build Path, Libraries tab, select the node Modulepath/JRE System Library[JavaSE-9]/Is modular and click Edit...
  2. In the Module Properties dialog, in the Details tab, in the Added exports section click Add... and enter the following:
    • Source module: javafx.controls
    • Package: com.sun.javafx.scene.control
  3. Click OK twice to close the Add-exports configuration and the Module Properties dialogs and Apply and Close to close the Properties dialog

enter image description here

In order to solve this issue you have to add the compiler argument --add-exports=javafx.controls/com.sun.javafx.scene.control=A‌​LL-UNNAMED. This can be done in Eclipse too but I have to admit at a very hidden place.

Go to the properties of your project and then to the Java Build Path. Select Modulepath and then the JRE System library (should be java 9). Inside that you find an item "is modular". Select that. Then open "Edit" on the right and a menu will open. At the top select "Details". There you will see a table where you can add your exports. Believe it or not but it works :-) I had to clean and re-build the project though in order to really get this compiled.

Well, it's a bit hidden:

  • open Java Build Path dialog of the project
  • select Libraries tab
  • select isModular entry
  • use the Edit... button to open the module properties dialog
  • select Details tab
  • create all required entries with the Add.. button

If you have installed the Beta plugin for Java 9 support - uninstall. Make sure the latest Java 9 support plugin is installed.

Related