简体   繁体   English

如何使用java 10在maven中添加javafx依赖项

[英]how to add javafx dependencies in maven with java 10

I switched to ubuntu 18.04. 我切换到ubuntu 18.04。 Which has java 10 as default jvm 其中java 10默认为jvm

Now my apps that use javafx cannot compile anymore. 现在我使用javafx的应用程序无法再编译了。

 cannot find symbol
[ERROR]   symbol:   class ObservableMap

I tried to add parameters to the maven-compiler-plugin to load the javafx.graphics module. 我尝试将参数添加到maven-compiler-plugin以加载javafx.graphics模块。

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgs>
                    <arg>--add-modules</arg>
                    <arg>javafx.graphics</arg>
                </compilerArgs>
            </configuration>
        </plugin>

result : 结果:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] module not found: javafx.graphics

of course, java --list-modules | 当然,java --list-modules | grep fx returns nothing. grep fx什么都不返回。

I've spent more than 10 hours trying to figure this out. 我花了10多个小时试图解决这个问题。

TL:DR What am I supposed to do to compile my JavaFX modules with Java 10? TL:DR我应该怎么做用Java 10编译我的JavaFX模块?

minimum project : 最小项目:

/pom.xml /pom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <name>java10fx</name>

    <artifactId>java10fx</artifactId>
    <version>0.0.1</version>
    <groupId>my.test</groupId>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <release>10</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

/src/main/java/MyApp.java /src/main/java/MyApp.java

import javafx.application.Application;
import javafx.stage.Stage;

public class MyApp  extends Application{

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {}

}

error : 错误:

java10fx/src/main/java/MyApp.java:[1,26] package javafx.application does not exist

OpenJDK never contained JavaFX and from Java 11 on, neither will Oracle JDK, so JavaFX will have to become a regular dependency. OpenJDK从未包含JavaFX,也不包含Java 11,Oracle JDK也不会,因此JavaFX必须成为常规依赖项。 OpenJFX, the project behind JavaFX, has recently released an early access build of a standalone JavaFX SDK that works with Java 10 and 11, but it is not yet available on Maven Central (that is planned for the future). OpenFFX是JavaFX背后的项目,最近发布了一个与Java 10和11一起使用的独立JavaFX SDK的早期访问版本 ,但它尚未在Maven Central上提供(计划在未来使用)。

For now, you have to download the SDK manually and find a way to add it to your Maven build, for example by deploying it to your Nexus or including it in a folder in your repo. 目前,您必须手动下载SDK并找到将其添加到Maven构建的方法,例如将其部署到Nexus或将其包含在repo的文件夹中。 Once it is available on Maven Central you will be able to use it just like any other dependency. 一旦它在Maven Central上可用,您就可以像使用任何其他依赖项一样使用它。

ok so actually the issue is kinda complex. 好吧所以实际上这个问题有点复杂。

The OPENJDK version installed with ubuntu is a mix between java 10 and java 11 : the package installed is actually "openjdk-11" but the VM installed refers to itself as openjdk-10 . 与ubuntu一起安装的OPENJDK版本是java 10和java 11之间的混合:安装的软件包实际上是“openjdk-11”,但安装的VM将自身称为openjdk-10。 Just as openjdk-11 it does not provide the javafx modules. 就像openjdk-11一样,它不提供javafx模块。

The solution was to install the oracle jdk 10: 解决方案是安装oracle jdk 10:

sudo add-apt-repository ppa:linuxuprising/java
sudo apt install oracle-java10-installer

And then the minimum program I gave works. 然后我给的最小程序工作。

Also I purged everything eg sudo apt remove --purge "openjdk-11*" 我也清除了一切,例如sudo apt remove --purge“openjdk-11 *”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM