gpt4 book ai didi

java - 升级到 Java 11 JavaFX 令人头疼

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:23 25 4
gpt4 key购买 nike

今天我安装了 JDK 11,但我所有的 JavaFX 东西都乱了套。公平地说,甲骨文可以为所欲为。我正试图让我的项目恢复到可运行状态,这是我第一次遇到这种模块化的东西,所以不知道到底发生了什么。

我已经设法将库作为 Maven 中的依赖项导入(尽管它无法在某些库的 Maven 中找到版本 11,我最终使用 11-ea+19 用于 javafx-controls 等 - 无论如何。 .),所以我的代码可以很好地编译这些依赖项:

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11-ea+25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11-ea+19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11-ea+19</version>
</dependency>

是的,我需要它们。

所以现在我希望运行程序但是没有!我们在运行时遇到错误:

Error: JavaFX runtime components are missing, and are required to run this application

好吧,人们似乎总是遇到这个问题,因为他们没有添加“模块”。唯一的问题是发帖的人没有使用 Maven,而是下载了存储在他们 PC 某处的 JavaFX SDK。 Maven 是否以巧妙的方式下载这些,还是我必须做同样的事情并下载一个单独的 SDK?然后从那里添加模块?!这对我来说看起来有点劣质......

我真正想知道的是我应该把什么作为我的 --module-path 以便我可以 --add-modules=javafx.controls,javafx.fxml, javafx.media,javafx.swing

为我沮丧的语气道歉。那些日子之一。

编辑:这是我的整个 pom.xml

    <?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cricket</groupId>
<artifactId>CricketFX</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11-ea+25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11-ea+19</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>

<!-- for timezones -->
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.3</version>
</dependency>


<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>com.netflix.rxjava</groupId>
<artifactId>rxjava-apache-http</artifactId>
<version>0.20.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.madgag/animated-gif-lib -->
<dependency>
<groupId>com.madgag</groupId>
<artifactId>animated-gif-lib</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jcodec/jcodec -->
<dependency>
<groupId>org.jcodec</groupId>
<artifactId>jcodec</artifactId>
<version>0.2.3</version>
</dependency>
<dependency>
<groupId>org.jcodec</groupId>
<artifactId>jcodec-javase</artifactId>
<version>0.2.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>application.gui.AppStarter</mainClass>
</configuration>
</plugin>

</plugins>
</build>


</project>

exec-maven-plugin 找不到版本 1.6.0,但我可以在 maven 网站的中央仓库中清楚地看到它。到底是什么..尝试获取 javafx 库的版本 11 时出现同样的问题。

编辑:已解决:我的 Maven 设置明显有问题,现在使用 maven-exec-plugin 版本 1.4.0 并且一切正常。

最佳答案

请先把11-ea+19全部去掉,把11我不知道为什么你找不到这个版本。例如,请参见此处:https://mvnrepository.com/artifact/org.openjfx/javafx-controls/11

请将此插件添加到 maven pom.xml:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>

然后执行:

mvn compile exec:java

这在 eclipse 中是项目上的右键 -> Run As -> Maven build ...并为目标添加:

compile exec:java

您还可以查看示例:https://openjfx.io/openjfx-docs/#maven

希望能帮到你。顺便说一下,这只会在 Eclipse 中启动您的应用程序。我仍然不知道如何创建可执行 jar 以及向后兼容的 jar。

编码愉快!

关于java - 升级到 Java 11 JavaFX 令人头疼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52894903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com