3

I'm setting up a Maven project based on Java/JavaFX 11 which should be both editable in IntelliJ and Visual Studio Code.

My JDK is 11.0.3 (Windows x64) from https://adoptopenjdk.net/.

The pom.xml has a dependency for

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11.0.2</version>
</dependency>

My app can be compiled and run with "compiler:compile" and "exec:java" in IntelliJ. So step one succeeded.

Now when opening the same project in Visual Studio compiling and running does not succeed with a lot of similar error message

The package javafx.scene.chart is accessible from more than one module: <unnamed>, javafx.controls

I added a settings.json file in .vscode to point to the correct JDK directory.

 {
    "java.dependency.packagePresentation": "hierarchical",
    "java.home": "C:/Program Files/Java/jdk-11.0.3+7",
    "java.configuration.updateBuildConfiguration": "automatic"
 }

But it still seems VSC has issues with two JavaFX versions, or isn't using the correct JDK. In the "Java Dependencies" view I can see references from both "JRE System Library" and "Maven" to JavaFX. Is there a way I can exclude them from the JRE view?

Screenshots as how JavaFX references are shown in VSC:

JavaFX references from Maven

JavaFX references from JRE

6
  • 1
    Are you saying your JDK from AdoptOpenJdk contains the JavaFX modules? I don't think that is the case, JavaFX is not included. Which is exactly the distribution you have downloaded? Commented Apr 22, 2019 at 21:48
  • @JoséPereda indeed as I understand JavaFX is not a part of the JDK (except Pi-versions of Liberica, see bell-sw.com/pages/java-12.0.1). I added my distribution to the question (Windows x64) and screenshots of the dependencies in VSC. Commented Apr 23, 2019 at 6:44
  • 1
    Indeed, AdoptOpenJDK doesn't include JavaFX (I've checked on Mac and Windows), so that last screenshot is confusing (I get Maven dependencies with JavaFX and JRE System Library without JavaFX). Can you verify in the Windows Explorer that your jdk-11.0.3+7/jmods folder doesn't have the JavaFX jmods? Commented Apr 23, 2019 at 8:56
  • No fx in jmods, so you're correct. Think I have too many JDK versions on my machine which confuses VSC. Will try later on another machine. I can start and run the application if I remove the fx dependency from pom.xml. So that makes it even more confusing :-) Commented Apr 23, 2019 at 10:29
  • 1
    It looks like you have installed JDK 11 with JavaFX (you mentioned Liberica, they do have JavaFX integrated on Windows too, not only on ARM), and VSC is somehow using it? Commented Apr 23, 2019 at 10:32

1 Answer 1

2

Based on the last screenshot posted, it seems that you are using a JDK 11 that does include JavaFX.

While most of JDK distributions don't include JavaFX (OpenJDK, Oracle, AdoptOpenJDK among others), some vendors are bundling JavaFX with the JDK, like Liberica.

If you check Liberica's release notes for JDK 11.0.2:

Windows x86_64, Mac, Linux x86_64 and Linux ARMv7 distributions contain OpenJFX 11.0.2.

While this option simplifies the use of JavaFX (no need to add it to the module-path, as it is already part of it), it can be confusing if you use Maven or Gradle build tools and include the JavaFX dependencies, or if you have other JDKs installed without it.

So the fix is easy: either use JDK without JavaFX and provide it via Maven/Gradle dependencies, or use JDK with JavaFX and don't include them.

I guess the latter is the preferred option, in case you need to export/share your project, since others might not have the same setup. Also it makes it more flexible to new releases of JavaFX.

As an aside, note that you can produce your own JDK that bundles JavaFX, following the instructions at https://openjfx.io/openjfx-docs/#modular, section Custom JDK+JavaFX image.

Sign up to request clarification or add additional context in comments.

3 Comments

BTW this is all related to webtechie.be/2019/04/16/…
Yes, same issue on embedded devices: when you choose the JDK you will use, check if it contains JavaFX.
Zulu OpenJDK build can come with OpenJFX 8 or 11 as well: azul.com/downloads/zulu/zulufx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.