Intellij无法使用OpenJDK 11识别javafx 11 [英] Intellij can't recognize javafx 11 with OpenJDK 11

查看:1604
本文介绍了Intellij无法使用OpenJDK 11识别javafx 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法让Intellj识别javafx包。使用新的javafx项目,使用OpenJDK 11,在尝试构建项目时,Intellij无法识别javafx软件包。



我已导入来自maven仓库的openjfx:javafx-base-11



我看过其他问题,解决方案似乎包括检查字节码是在正确的水平(我的是),项目语言是正确的(我的是)。



任何人都有任何想法?









编辑:



错误:



解决方案

如评论中所述,



您会注意到Maven为您管理所需的依赖项:它将为javafx.controls添加javafx.base和javafx.graphics,但最重要的是,将根据您的平台添加所需的分类器。就我而言,Mac。



这就是为什么你的罐子 org.openjfx:javafx-controls:11 empty ,因为有三种可能的分类器(windows,linux和mac平台),它们包含所有类和本机实现。



以防万一您仍然想要转到.m2仓库并手动从那里获取依赖项,请确保选择正确的(例如 .m2 / repository / org / openjfx / javafx-controls / 11 / javafx -controls-11-mac.jar


  1. 替换默认的maven插件与来自此处的人一起。


  2. 运行 mvn编译exec:java ,它应该可以工作。


Gradle项目的类似工作,详见此处


Having trouble getting Intellj to recognize javafx packages. With a new javafx project, with OpenJDK 11, when trying to build the project Intellij can't recognize the javafx packages.

I've imported openjfx:javafx-base-11 from the maven repo.

I've looked at other questions, and the solutions seem to range from checking the bytecode is at the right level (mine is), project language is correct (mine is).

Anyone have any ideas?

edit:

error:

解决方案

As mentioned in the comments, the Starting Guide is the place to start with Java 11 and JavaFX 11.

The key to work as you did before Java 11 is to understand that:

  • JavaFX 11 is not part of the JDK anymore
  • You can get it in different flavors, either as an SDK or as regular dependencies (maven/gradle).
  • You will need to include it to the module path of your project, even if your project is not modular.

JavaFX project

If you create a regular JavaFX default project in IntelliJ (without Maven or Gradle) I'd suggest you download the SDK from here. Note that there are jmods as well, but for a non modular project the SDK is preferred.

These are the easy steps to run the default project:

  1. Create a JavaFX project
  2. Set JDK 11 (point to your local Java 11 ea version)
  3. Add the JavaFX 11 SDK as a library. The URL could be something like /Users/<user>/Downloads/javafx-sdk-11/lib/. Once you do this you will notice that the JavaFX classes are now recognized in the editor.

  1. Before you run the default project, you just need to add these to the VM options:

    --module-path /Users/<user>/Downloads/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.fxml

  2. Run

Maven

If you create a Maven project, you can easily add the required dependency:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>

  1. Create a Maven project with JavaFX archetype
  2. Set JDK 11 (point to your local Java 11 ea version)
  3. Add the JavaFX 11 dependencies.

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

Once you do this you will notice that the JavaFX classes are now recognized in the editor.

You will notice that Maven manages the required dependencies for you: it will add javafx.base and javafx.graphics for javafx.controls, but most important, will add the required classifier based on your platform. In my case, Mac.

This is why your jars org.openjfx:javafx-controls:11 are empty, because there are three possible classifiers (windows, linux and mac platforms), that contain all the classes and the native implementation.

In case you still want to go to your .m2 repo and take the dependencies from there manually, make sure you pick the right one (for instance .m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-mac.jar)

  1. Replace default maven plugins with those from here.

  2. Run mvn compile exec:java, and it should work.

Similar works as well for Gradle projects, as explained in detail here.

这篇关于Intellij无法使用OpenJDK 11识别javafx 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆