首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用maven和Java 17启动JavaFX应用程序

使用maven和Java 17启动JavaFX应用程序
EN

Stack Overflow用户
提问于 2021-10-22 12:06:42
回答 1查看 2.1K关注 0票数 1

我的系统:

  • 有多个jdks (1.8,16,17)
  • 有IntelliJ的Maven
  • 是windows 10机器

我想用maven启动我的JavaFX应用程序。为此,我在插件菜单中使用javafx:run按钮。

然后,我得到了关于我的jdk的错误,在一个太低的级别上(它告诉我我试图用我的jdk-8来执行我的主要方法),这不是真的,因为每个jdk-specification都设置为jdk-17

请不要给我发任何关于其他帖子的链接。我已经试过了,那里的步骤对我没有效果。

,这是我得到的错误

  • Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

代码语言:javascript
复制
- Yes I already tried to change IntelliJs jdks, the JAVA\_HOME variable and the run configs of maven itself

  • 有时也会从maven那里得到一个错误,告诉我在maven存储库中没有JavaFX版本17 (但是我的工作场所的maven回购)。是否有办法将maven-repo更改为默认maven网站?

,这是我的pom.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>M226a_miniproject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>17</release>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <executable>C:/Users/[user.name]/.jdks/openjdk-17/bin/javac</executable>
                    <compilerVersion>1.3</compilerVersion>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <configuration>
                    <mainClass>ch.package.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.1</version>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>17.0.0.1</version>
            <type>pom</type>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-graphics -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>17.0.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.0.1</version>
        </dependency>
    </dependencies>
</project>

也许第二个插件中的<version>0.0.8</version>有什么问题吗?

另外: JRE不识别类文件的错误是没有意义的,因为甚至我的maven也在使用我的jdk-17的自定义路径。

编辑:更新的pom.xml

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-27 07:58:19

(修复了我的Ubuntu20.04机器上的问题,但错误是相同的)

问题是,我只将jdk-17下载到IntelliJ中。

我只是通过运行sudo apt install openjdk-17-jdk来安装jdk-17,它安装jdk和

sudo update-alternatives --config java,它更新最新jdk的intex (我认为)。

最后一步是重新启动IntelliJ,我准备好了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69676622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档