The import javafx cannot be resolved

前端 未结 4 1104
傲寒
傲寒 2021-01-02 03:27

I installed Eclipse IDE today on my Ubuntu Linux and then installed JavaFX using \'Install New Software\' and when I created a javafx project, I got the following error in M

相关标签:
4条回答
  • 2021-01-02 04:01

    For Java Compiler 8 or above, do the following:

    1. Right-click on project
    2. Choose Build Path ----> Add Libraries

    You will then be presented with the following screenshot below:

    Make sure you have downloaded and installed a JDK 8 or above

    When you press the finish button, all Java FX errors in your code should disappear.

    Note Prerequisites:

    JDK 9 installed and tested on NetBeans 8.0.1

    0 讨论(0)
  • 2021-01-02 04:14

    Here's how to set it up on Ubuntu Linux with Maven:

    1) Install OpenJFX package, check where did it put the files.

          sudo apt install openjfx
          dpkg-query -L openjfx
    

    You might end up with version for JDK 11. In which case, either follow with installing a new OpenJDK, or set a version of OpenJFX for JDK 8.

    2) Put it to your Maven project as a system-scoped dependency.

    Note this is the lazy and not-so-nice way. Properly, you should install the jars like this:

    dpkg-query -L openjfx | grep -E '.jar$' | xargs -l -I{} \
      mvn install:install-file -Dfile="{}" -DgroupId=javafx \
        -DartifactId=$(echo $JAR | tr '.' '-') -Dversion=1.0 -Dpackaging=jar
    

    And then use it as a normal compile-scoped dependency.

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.source.level>1.8</project.source.level>
        <project.target.level>1.8</project.target.level>
    
        <javafx.dir>/usr/share/openjfx/lib</javafx.dir>
    </properties>
    
    <dependencies>
    
        <!-- JavaFx :
          sudo apt install openjfx
          dpkg-query -L openjfx
        -->
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.base.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.controls.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.fxml.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.graphics.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.media.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.swing.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${javafx.dir}/javafx.web.jar</systemPath>
        </dependency>
    
    </dependencies>
    
    0 讨论(0)
  • 2021-01-02 04:17

    According to the packages list in Ubuntu Vivid there is a package named openjfx. This should be a candidate for what you're looking for:

    JavaFX/OpenJFX 8 - Rich client application platform for Java

    You can install it via:

    sudo apt-get install openjfx
    

    It provides the following JAR files to the OpenJDK installation on Ubuntu systems:

    /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
    /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jfxswt.jar
    /usr/lib/jvm/java-8-openjdk-amd64/lib/ant-javafx.jar
    /usr/lib/jvm/java-8-openjdk-amd64/lib/javafx-mx.jar
    

    Hope this helps.

    0 讨论(0)
  • 2021-01-02 04:24

    A) Make sure that you are using a compatible JDK, like 1.8, AND

    B) configure a compatible version of Java in the Eclipse Project Facets.

    1. Right click on the Java project, select Properties
    2. Select Project Facets, find Java, set version 1.8

    For Java 11, this error also appears, as JavaFX has been removed from Java 11 and comes as standalone

    More info: https://blogs.oracle.com/java-platform-group/the-future-of-javafx-and-other-java-client-roadmap-updates

    0 讨论(0)
提交回复
热议问题