简体   繁体   中英

Configure Eclipse to use OpenJFX with OpenJDK without manually adding --add-module in Run Configurations?

I have a downloaded OpenJDK 11.0.11_9 JRE and a corresponding version of OpenJFX (11.0.2). I have configured eclipse to use the downloaded JDK11 for compilation and running my project. (For various reasons I am not using the system's default JDK.)

In the project properties -> Java Build Path -> Libraries tab, I added the various javafx.jar files in the "Modulepath" section. The Module Dependencies tab shows them listed on the left side.

But when I run the project I get a NoClassDefFound error for the first javafx class it tries to load.

If I manually put "--add-modules javafx.controls,javafx.swing,javafx.media" in the VM arguments in the Run Configuration, it works, but this seems to defeat the whole point of configuring the Modules Dependencies in the build path in the first place.

What's the proper way to do this?

I recommend opening the Run Configurations for your program and selecting the Dependencies tab. Then click on the Modulepath Entries in the list of dependencies, and then the buttons Advanced... followed by Add External Folder . The folder to add is the /lib subfolder of your JavaFX JDK. Alternatively, you can add the jars from this folder directly via the Add External Jars option.

If you click the Show Command Line button before and after doing this, you will see that the javafx jars are added to the path by this act (the -p option).

As far as I am concerned, this is a workaround for a deficiency currently in Eclipse. I really don't understand why it should be necessary, if the library was successfully added to the build path. The clear expectation is that it will be automatically included in the path by the Run Configurations . (The openjfx.io documentation suggests that nothing need be done to the Run Configurations.) Also, other elements in the "Libraries" section of the build path appear in the Dependencies , so why not the javafx jars? Perhaps there is something we are doing wrong or omitting when we configure the javafx library for inclusion on the build path.

I'm going to dig further, will ask at Eclipse.org, etc. Will report back if I get more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM