gpt4 book ai didi

java - 使用 maven 在 IntelliJ IDEA 中构建 JavaFX 应用程序

转载 作者:行者123 更新时间:2023-12-04 08:47:48 25 4
gpt4 key购买 nike

我在尝试使用 maven 构建 JavaFX 应用程序时遇到了一些困难。该应用程序在 IDE 中运行良好。我运行 maven 包任务并创建 JAR 文件。问题是这个文件没有运行。我检查了包含的 list ,但没有入口点。我已经添加了它,但该文件仍然无法运行。这就是 list 现在的样子(最后一个字符串是手动添加的):

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.6.3
Built-By: Комп
Build-Jdk: 15
Main-Class: org.example.App
pom文件
<?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>org.example</groupId>
<artifactId>Refinement</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-maven-plugin -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>


</project>
并建立日志
"C:\Program Files\Java\jdk-15\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\Комп\Documents\javaProjects\Refinement "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\lib\idea_rt.jar=65494:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2020.2.2 package
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:Refinement >-----------------------
[INFO] Building Refinement 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Refinement ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Комп\Documents\javaProjects\Refinement\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Refinement ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Refinement ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Комп\Documents\javaProjects\Refinement\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Refinement ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Refinement ---
[INFO] Surefire report directory: C:\Users\Комп\Documents\javaProjects\Refinement\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.example.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.052 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Refinement ---
[INFO] Building jar: C:\Users\Комп\Documents\javaProjects\Refinement\target\Refinement-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.456 s
[INFO] Finished at: 2020-10-06T12:04:09+03:00
[INFO] ------------------------------------------------------------------------
更新
我尝试从 CLI 启动 JAR 文件并收到错误消息:
Error: Could not find or load main class org.example.App
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
也许我必须在 JAR 文件中包含 JavaFX 类?我不确定用户的机器是否会安装 JavaFX,我不想依赖于此。
我也尝试重建 pom 文件,如 Building a minimal JavaFX 11 application with Maven 文章中所示。这个新版本也抛出一个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:825)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:723)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:646)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:604)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.example.Launcher.main(Launcher.java:5)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 10 more
看起来更冗长,但在我看来,本质是一样的。
检查 PATH 变量,它指向 JavaFX lib 文件夹。

最佳答案

要开始一个新的 JavaFX 项目,最好访问这个(全新的)网站:https://start.gluon.io/ .您将获得一个包含所有文件的 ZIP 和一个 README,以便您立即开始使用。
对于基本应用程序,取消选择所有“Gluon 功能”、“CloudLink”和“附加”。
start.gluon.io selections in web interface
start.gluon.io preview
start.gluon.io downloaded ZIP

关于java - 使用 maven 在 IntelliJ IDEA 中构建 JavaFX 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64223514/

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