最近在按照javafx官网(https://openjfx.io/openjfx-docs/)“JavaFX and IntelliJ IDEA”->“Maven”,创建Maven项目时,出现如下错误:
Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.openjfx:javafx-archetype-simple:0.0.6)
最后发现是因为得需要先创建“JavaFX Maven Archetypes”。
Install archetype locally
安装archetype到本地仓库,在本地D:\git目录下,点开Git Bash Here命令行窗口,执行如下命令:
git clone -b 0.0.6 https://github.com/openjfx/javafx-maven-archetypes.git
cd javafx-maven-archetypes
mvn clean install
执行完后,在本地仓库可以看到如下目录:
https://github.com/openjfx/javafx-maven-archetypes
JavaFX Maven plugin
git clone -b 0.0.6 https://github.com/openjfx/javafx-maven-plugin.git
cd javafx-maven-plugin/
mvn clean install -Dmaven.test.skip=true
创建maven项目
选择 File -> New -> Project -> Maven 并启用 Create from archetype。如果没有JavaFX archetype选项, 选择Add archetype… ,在弹出框中进行设置groupId (org.openjfx), the artifactId (javafx-maven-archetypes), and the version (0.0.6), and press OK。
添加成功之后,可以看到javafx-maven-archetypes选项,选择0.0.6版本即可:
点击上图的Next按钮后,进行如下设置:
点击上图的Next按钮后,进入如下界面:
创建成功后目录结构如下:
运行