小编gui*_*lum的帖子

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

我切换到ubuntu 18.04.其中java 10默认为jvm

现在我使用javafx的应用程序无法再编译了.

 cannot find symbol
[ERROR]   symbol:   class ObservableMap
Run Code Online (Sandbox Code Playgroud)

我尝试将参数添加到maven-compiler-plugin以加载javafx.graphics模块.

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgs>
                    <arg>--add-modules</arg>
                    <arg>javafx.graphics</arg>
                </compilerArgs>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

结果:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] module not found: javafx.graphics
Run Code Online (Sandbox Code Playgroud)

当然,java --list-modules | grep fx什么都不返回.

我花了10多个小时试图解决这个问题.

TL:DR我应该怎么做用Java 10编译我的JavaFX模块?

最小项目:

/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>
Run Code Online (Sandbox Code Playgroud)

/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);
    } …
Run Code Online (Sandbox Code Playgroud)

java ubuntu javafx java-10

2
推荐指数
1
解决办法
3175
查看次数

标签 统计

java ×1

java-10 ×1

javafx ×1

ubuntu ×1