James Green
James Green

Reputation: 125

Could not find javafx-archetype-fxml in central Intellij JavaFX-Maven project

I'm following this under the "JavaFX and Intellij" installing non-modular maven.

I input pretty much everything the same (I'm using version 15 of java, so 15.0.2) I enter the exact same ids, I put "15.0.2" for javafx-version, and I have tried both "javafx-archetype-simple" and "javafx-archetype-fxml" and both give me the error:

Could not find artifact org.javafx:javafx-archetype-fxml:pom:0.0.6 in central (https://repo.maven.apache.org/maven2)

And the following "pom.xml (<project_name>)":

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>test1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>

</project>

From the videos I've also seen on installing this, this is way too short. alongside the project structure itself being wrong. With the <project_name> directory only containing ".idea", "pom.xml" and "<project_name>.iml" files/folders.

I don't understand what I'm doing wrong. I'm pretty sure I don't need to have JavaFX installed right (though I do somewhere)

Upvotes: 1

Views: 472

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 339502

Use latest version of IntelliJ

As commented, be sure you are using the latest version of IntelliJ.

The IntelliJ IDE is a vast and rich tool, under continual development, with constantly improving features and fixes.

Tip: IntelliJ gives away the JetBrains Toolbox applet to automatically discover and install new versions, and optionally, pre-release versions.

Use IntelliJ template

I recommend using the JavaFX project template built into IntelliJ.

See Create a new JavaFX project. Choose File > New > Project > JavaFX.

screenshot of File New Project JavaFX dialog box

This produces a Maven-driven project (or Gradle-driven, your choice) using the OpenJFX libraries that implement JavaFX. Upon creation, wait a minute while various libraries are downloaded and configured.

You said:

I don't understand what I'm doing wrong. I'm pretty sure I don't need to have JavaFX installed right (though I do somewhere)

As commented, there is indeed a separately downloadable collection of OpenJFX libraries. But I have never done that.

Instead, I recommend letting a dependency management tool (Maven or Gradle) handle fetching the OpenJFX libraries from a Maven repository. The dependency tool then makes those libraries available to your project for building and bundling with your final app. Switching to later versions is much easier through the dependency tool rather than having to manually download fresh copies, and manually install into your project.

An alternative is using an edition of a JDK that comes bundled with a copy of the OpenJFX libraries. At least two vendors provide such an edition of their JDK distributions: ZuluFX by Azul Systems, and LibericaFX by Bellsoft.

Example POM

Here is an example POM generated by the JavaFX template in IntelliJ.

<?xml version="1.0" encoding="UTF-8"?>
<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>work.basil.example</groupId>
    <artifactId>ExFxForEclipse</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>ExFxForEclipse</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.10.3</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>22.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>22.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>22</source>
                    <target>22</target>
                </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>work.basil.example.exfxforeclipse/work.basil.example.exfxforeclipse.HelloApplication</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>

Upvotes: 1

Related Questions