0

I've recently decided to take the plunge and start programming on Linux but the transition has been rough.

I'm currently trying to get a JavaFX program to run properly in InteliJ and I keep getting an error for Error: JavaFX runtime components are missing, and are required to run this application

I've tried several of the proposed fixes that you can find on Stack Overflow, namely this one and this one along with the walk-through on Gluon's own website but nothing that I have tried so far is working.

For a brief overview, I'm using... Java 17 (I don't remember why exactly anymore). JavaFX 19 through Maven InteliJ Idea Community & Fedora Workstation

I know for a fact that the code itself is good because it is the exact same code that I used on my windows machine and it worked fine. The only thing I've changed in regards to the code is the pom.xml file for Maven where I finally added JavaFX as a dependency while getting things ready for the new OS.

This is the pom.xml file. I'm not an expert with maven but everything does appear to be correct as best I can tell.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>LibraryDesktopApp</groupId>
    <artifactId>LibraryDesktopApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>LibraryDesktopAppProgram</name>
    <description>This is the desktop program for the library software suite.</description>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.25</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.1</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.mypackage.MyClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>LibraryDesktop/src.Main</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

These are screenshots of various configuration screens.

Libraries

enter image description here

Modules

enter image description here

Configuration

enter image description here I have tried running the program both with and without the VM arguments and neither worked.

Any help would be greatly appreciated! Thanks!

TeaDrinker
  • 199
  • 1
  • 11
  • 1
    If JavaFX is used through Maven with Idea, you don't need to install the SDK or set module path info in the runtime config. Create a [new project in Idea](https://www.jetbrains.com/help/idea/javafx.html), following those instructions and see if it works - that will assure you that you can build and run a JavaFX app from your dev environment. – jewelsea Oct 22 '22 at 00:00
  • 1
    Also for packaging, don't create an "executable jar" which places JavaFX libs on the classpath as you are doing, instead use jlink or jpackage to package the app, see the maven-javafx-plugin jlink doc. JavaFX modules should be on the module path or built into a linked image (which is what jlink does). – jewelsea Oct 22 '22 at 00:01
  • @jewelsea I forgot to mention that I have tried building and running the program without the standard arguments in the runtime config and it made no difference. I got the error regardless. I created a new JavaFX program in idea and it was able to run with no issues. – TeaDrinker Oct 23 '22 at 03:04
  • @jewelsea I admit that I'm not sure what you're talking about when you talk about "packaging." The only packaging I've worked with in InteliJ was in the "artifacts" tab but I haven't added anything there. I assumed you were talking about the the pom.xml file and removed any of its contents but that didn't change anything either. The error is still appearing. I'll look into Jlink in the meantime though and see if it can help me. – TeaDrinker Oct 23 '22 at 03:22
  • 1
    Packaging is bundling an app for distribution. Your project says you do this using the maven-jar-plugin, placing dependencies in a lib folder on the classpath. This would place the JavaFX modules on the classpath, which is not a supported configuration. – jewelsea Oct 23 '22 at 07:53
  • 1
    *”I created a new JavaFX program in idea and it was able to run with no issues.”* ->. Then gradually copy the source from your old project into the new project, testing with each small addition. After that it will either work, or, it breaks. If it breaks, then you know exactly what broke it. – jewelsea Oct 23 '22 at 07:58
  • @jewelsea Apologies for how long this comment took but I've been busy. In order to properly follow your advice, I finally decided to bite the bullet and convert the project to a properly modular setup. It took a little while but I'm no longer getting the error message. Now I'm dealing with converting file paths to the new setup and dealing with "Location is not set" error. I'll figure out in good time though. thank you for your help! – TeaDrinker Oct 26 '22 at 04:00
  • 1
    *Now I'm dealing with converting file paths to the new setup and dealing with "Location is not set" error.* -> See [Where to put resource files in JavaFX](https://edencoding.com/where-to-put-resource-files-in-javafx/) – jewelsea Oct 26 '22 at 09:55
  • @jewelsea Thanks but I already figured it out. I've still got one or two issues but I'm working through them one at a time. It turns out that making this project modular was going to be biting off more than I could chew. But the issue specific to this question is over. Thanks for your help! – TeaDrinker Oct 28 '22 at 00:02

1 Answers1

0

The entire project was converted over to a modular approach and I re-worked the pom.xml file too.

It was a bit of headache to get working but in addition to fixing my issue, the new setup is honestly much nicer than what I was dealing with before. On the off chance that someone else needs help with this same issue, I'm attaching a link to a fairly straightforward setup very similar to what I'm using. It does the job of explaining the process far better than I could.

TeaDrinker
  • 199
  • 1
  • 11