-1

I am trying to use the JavaFX SDK in Intellij Idea. I know that you can create a JavaFX project in intellij idea directly, through the wizard, but I need to make a current project compatible with JavaFX and I'm trying to install the library. I am new to JavaFX and I am pretty sure I'm doing something wrong during the installation. What I did to install JavaFX was:

  • downloaded the SDK
  • added the lib folder (inside the SDK) as a library to the project
  • added the following line to the VM options "--module-path /path-to/JavaFX/lib --add-modules=javafx.controls". (Of course the "path-to" was replaced with my path to the lib folder)

When I try to run my code I get this error:

error

I am using MAC OS, I tried doing the same thing on my other machine (Linux) but I had the same error.

I am new to JavaFX and pretty new to java, I saw something about some run components, I am not sure what does are. I looked to see if they are something that I need to install but I did not find any useful information about them. I am using java 18.

I could really use some help. Thank you!

  • 3
    I would not recommend you try anything other [this](https://www.jetbrains.com/help/idea/javafx.html#check-plugin) or a flow from [this](https://openjfx.io/openjfx-docs/) when trying to create `JavaFX` projects. – SedJ601 Apr 25 '22 at 17:05
  • I know, I would love to use that, but I am cloning a project from GIT that is not a javaFX project. I could move the source files to a JavaFX project but then I would not be able to use the GIT repository. If you know how to pull a project from git into an already existing project, that would be a good solution for me also. – Cristyantm97 Apr 25 '22 at 17:09
  • 1
    I would recommend creating a new project and a new repository. Maybe some of the experts will comment, but I don't think it is wise to attempt turning a non `JavaFX` project into a `JavaFX` project. – SedJ601 Apr 25 '22 at 17:14
  • Perhaps, checkout your original project from git, then create a new JavaFX project via wizard in the *same* directory, open the new project, ensure it works, then move the existing code around to fit the Maven directory structure for the new project and add the appropriate libraries as Maven dependencies, also either delete the module-info or enhance it with additional required module data, verify everything works, then check the changes back into git. I think this way you could continue to use the existing repository, preserve history and you would have a working app in the suggested format. – jewelsea Apr 25 '22 at 18:10
  • Alternately, following the Idea specific instructions at openjfx.io for creating a JavaFX project should be applicable for enhancing an existing project to add JavaFX support. If that hasn't worked for you, then likely you have made a mistake in one of the manual setup steps that that incurs. Perhaps you set [program options rather than VM arguments](https://stackoverflow.com/questions/50938383/how-to-set-jvm-arguments-in-intellij-idea), or something else like the wrong path or spaces in the path, etc. – jewelsea Apr 25 '22 at 18:14
  • 2
    When posting error messages, post the full stack traces as text, formatted as code. – jewelsea Apr 25 '22 at 18:15
  • 2
    You could check any of these [95 question](https://stackoverflow.com/search?q=QuantumRenderer%3A+no+suitable+pipeline) for info about your error. – jewelsea Apr 25 '22 at 18:17
  • Perhaps the best solution would be a *multi-module* project, with two modules: your existing code from Git and your JavaFX code. Base your JavaFX on a canonical project as advised multiple times above. Within your JavaFX code, write adapter code that calls on the separate-yet-bundled existing code. You can then import a fresh version of the existing Git code into its own module within your overall project without disturbing your JavaFX code module. – Basil Bourque Apr 25 '22 at 20:51
  • 1
    Another tip: it's rather unexpected that the project written with java 18 in mind is not JavaFX ready out of the box. Is it perhaps Java 1.8 project? Back then, JavaFX was part of JRE, so it works with intellij without any fuss. – JockX Apr 25 '22 at 21:31

1 Answers1

0

If you are using dependencies management software such as Maven you can add the JavaFX dependencies (See below).

Then execute using the following maven command clean javafx:run

 <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-base</artifactId>
        <version>${javafx.version}</version>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>${javafx.version}</version>
    </dependency>


    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>${javafx.version}</version>
    </dependency>

And using the plugin

          <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.6</version>
            <configuration>
                <mainClass>your.main.class</mainClass>
                <options>
                    <option>--add-exports</option>
                    <option>javafx.graphics/com.sun.javafx.text=ALL-UNNAMED</option>
                    <option>--add-exports</option>
                    <option>javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED</option>

                    <option>--add-opens</option>
                    <option>javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED</option>
                </options>
            </configuration>
        </plugin>
xX13ENXx
  • 1
  • 3