5

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?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • 3
    Try adding `--add-exports=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED` to compiler arguments – user11153 Nov 13 '17 at 11:24
  • @user11153 might be embarassing but .. where exactly do I add compiler arguments? – kleopatra Nov 13 '17 at 11:27
  • 2
    Well, the internal APIs pertaining to [`com.sun.*` has been removed in Java9](https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-F7696E02-A1FB-4D5A-B1F2-89E7007D4096). Would be good to see what exactly is your use case in order to get to an answer of how you should migrate. – Naman Nov 13 '17 at 11:31
  • @user11153 thanks for the link - but ... it seems to be about activating a flag, not about adding a compile-time argument .. what am I missing? – kleopatra Nov 13 '17 at 11:38
  • @nullpointer verified that it's not the jdk9, it's Eclipse not allowing me to access the internal classes ... – kleopatra Nov 13 '17 at 12:50
  • 1
    @kleopatra Just for an improvement in the question title, shall the question now be something like *How to add compiler args in Eclipse oxygen?* ;) The answer*s* to this anyway point in the same direction anyway. Cleaning up the rest of the comments. – Naman Nov 13 '17 at 13:24

3 Answers3

10
  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

howlger
  • 31,050
  • 11
  • 59
  • 99
  • @nullpointer I started writing my answer before the other one was published and I have not deleted my answer, because it tells what to add in contrast to the other answer. – howlger Nov 13 '17 at 13:29
  • Maybe. I will delete my answer as soon as it does not add value. Maybe you can also find a duplicate with a more detailed answer. – howlger Nov 13 '17 at 13:44
  • 1
    Well, actuall your answer is slightly wrong. You don't have to check the checkbox (2.1) because you are not patching an existing module here. You just add one more (already existing) package to the list of exported packages. – mipa Nov 13 '17 at 14:10
  • @mipa Thank you for the clarification. – howlger Nov 13 '17 at 14:48
  • Googling "eclipse java 9 javafx Button disableProperty error red squiggly" led me here, mostly out of desperation, but it inspired me to solve my problem (I think). ¬.¬ Eclipse. – JohnL4 Mar 20 '18 at 02:26
4

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.

mipa
  • 10,369
  • 2
  • 16
  • 35
4

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.

wzberger
  • 923
  • 6
  • 15