0

I created a new default JavaFX project in Windows 10 in Intellij with Maven using javafx-archetype-simple and the project seemed to create ok but there is no javafx:compile option in Maven. I'm using JavaFX 16 and JDK 17.0.1.

There's only javafx:jlink:

enter image description here

This is the pom.xml file:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.openjfx</groupId>
    <artifactId>hellofx</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>org.openjfx.App</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

It's so odd since everything else seems to have been created fine, but like this the project fails with java: package javafx.application does not exist

EDIT: The question is not a duplicate since I'm already using JDK 17.0.1.

Hasen
  • 10,054
  • 19
  • 66
  • 124
  • 1
    As in the duplicate, version 17 of JavaFX is broken in Maven, use 17.0.1 – jewelsea Dec 29 '21 at 06:58
  • @jewelsea I guess I should have been more specific about the version number - it is 17.0.1. – Hasen Dec 29 '21 at 08:16
  • @jewelsea I was following the instructions here https://openjfx.io/openjfx-docs/#maven and it says to use `javafx:compile` to verify the project. Running `maven compile` in the project folder terminal returns `'maven' is not recognized as an internal or external command,` – Hasen Dec 29 '21 at 08:18
  • Sorry, I misspelled, the execution command is just `mvn install`. – jewelsea Dec 29 '21 at 08:19
  • @jewelsea Exact same error message with `mvn install` – Hasen Dec 29 '21 at 08:20
  • But did you fix the version? The version in your question is definitely `17`, not `17.0.1`. – jewelsea Dec 29 '21 at 08:22
  • @jewelsea I followed both the video and the official documentation - thus I used the current version numbers from the documentation, I did everything as it said for 'Non-modular with Maven' – Hasen Dec 29 '21 at 08:24
  • I also advise, studying (as in performing the steps in) the [maven getting started tutorial](https://maven.apache.org/guides/getting-started/). – jewelsea Dec 29 '21 at 08:24
  • I looked at your link https://openjfx.io/openjfx-docs/#maven, unfortunately, the official documentation is wrong, it should reference 17.0.1 everywhere, as 17 is broken. – jewelsea Dec 29 '21 at 08:26
  • @jewelsea Hold on, I'm using version 17.0.1 of JDK, not Javafx. I thought that was what you were referring to.. – Hasen Dec 29 '21 at 08:26
  • @jewelsea How would you fix a current project? – Hasen Dec 29 '21 at 08:30
  • Just change `org.openjfxjavafx-controls17` to `org.openjfxjavafx-controls17.0.1` and [reimport it in Idea](https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#maven_reimport). – jewelsea Dec 29 '21 at 08:33
  • @jewelsea That answer seems to be about a fxml project, I want to create a simple project. There's no way to fix it using the method in the documentation? – Hasen Dec 29 '21 at 08:33
  • @jewelsea Changing the value to `17.0.1` is not found and shown in red. Are you sure that's the version? – Hasen Dec 29 '21 at 08:35
  • You need to reimport it . . . I provided the link . . . – jewelsea Dec 29 '21 at 08:36
  • @jewelsea Ok it's 17.0.1 now but still doesn't have the `javafx:compile` option. And `mvn install` still throws the same error message. – Hasen Dec 29 '21 at 08:40
  • @jewelsea Hmm in the linked answer it's `17.0.0.1` and not `17.0.1` - which one should it be? – Hasen Dec 29 '21 at 08:42
  • As I said, there are no javafx specific lifecycle targets, you just use standard maven lifecycle commands, if you want to use maven to compile you can do: `mvn compile`. – jewelsea Dec 29 '21 at 08:42
  • @jewelsea Well yeah as I said any command starting with `mvn` throws the same error message - `'mvn' is not recognized as an internal or external command` – Hasen Dec 29 '21 at 08:44
  • The linked answer is older, it provides 17.0.0.1 as an example at works and says to replace the version with the current latest stable version, which, as of today is 17.0.1, it links to a site and explains this. Please follow the instructions. – jewelsea Dec 29 '21 at 08:44
  • You didn't configure your maven environment as the linked maven getting started tutorial would have had you do. Study [mvn command is not recognized as an internal or external command](https://stackoverflow.com/questions/19090928/mvn-command-is-not-recognized-as-an-internal-or-external-command) – jewelsea Dec 29 '21 at 08:47
  • @jewelsea Yeah the linked answer is for the wrong version and is also for mac. Leastways it doesn't fix anything as you can see from my comment above. I have none of these problems creating a project on Mac, this is a windows specific problem. – Hasen Dec 29 '21 at 08:47
  • You are using an IDE anyway, maven is integrated in Idea, it doesn't make a difference if it is a Mac or whatever, you can just right click on maven target in the maven window and it will run. Or just create a new project using the [new JavaFX project wizard](https://www.jetbrains.com/help/idea/javafx.html). You don't need to use the Maven JavaFX plugin at all. Unless you are using it to assist with jlink I don't think it adds any added value. – jewelsea Dec 29 '21 at 08:48
  • @jewelsea That doesn't explain why `javafx:compile` is not showing in the maven options though. – Hasen Dec 29 '21 at 08:51
  • @jewelsea On my Mac I create a project in intellij idea and it has `javafx:compile` right there in maven, that's certainly a difference. No need to mess around in the terminal. The problem seems to be elsewhere. – Hasen Dec 29 '21 at 08:52
  • It doesn't show. because it doesn't exist, there is no such thing. Read the [JavaFX maven plugin documentation](https://github.com/openjfx/javafx-maven-plugin), there is nothing for `javafx:compile`. – jewelsea Dec 29 '21 at 08:52
  • @jewelsea The javafx project wizard is fxml only, I don't want to use that, that's why I was using the documentation method to create a simple project. – Hasen Dec 29 '21 at 08:53
  • You don't need to use a terminal, you can just compile and build by running the app by clicking the little green arrow (as outlined in the new JavaFX project wizard documentation I linked). Or you can click on the compile target in the maven project window as I previously noted. – jewelsea Dec 29 '21 at 08:54
  • @jewelsea No such thing? Not sure what you mean now, it says to use `javafx:compile` in the official documentation. It's also there when I create a project on mac. – Hasen Dec 29 '21 at 08:54
  • @jewelsea Lol ok yeah if I just launch it it does work now. Not sure why I was so intent to run the `javafx:compile` instead of just launching it directly. – Hasen Dec 29 '21 at 08:57
  • @jewelsea Thanks for your help and patience. :) – Hasen Dec 29 '21 at 08:59
  • `javafx:compile` was removed as an option, probably because it was redundant and not needed because you can just do `mvn compile`, readme for [0.0.5](https://github.com/openjfx/javafx-maven-plugin/tree/0.0.5) version of the plugin mentions it, but [0.0.8](https://github.com/openjfx/javafx-maven-plugin/tree/0.0.8) does not. – jewelsea Dec 29 '21 at 08:59
  • @jewelsea The documentation should really be updated to not advise using it then. That's what made me thing something was wrong in the first place. I guess it was a very recent change. – Hasen Dec 29 '21 at 09:04
  • Where does the current official documentation mention `javafx:compile`, can you provide a link? – jewelsea Dec 29 '21 at 09:07
  • @jewelsea It's in the original link I gave https://openjfx.io/openjfx-docs/#maven under '3 Run the Project'. Ok that's 'compiler:compile' not 'javafx:compile'. I didn't read it carefully and thought I saw 'javafx:compile' like I saw in the video. – Hasen Dec 29 '21 at 09:08

0 Answers0