【发布时间】:2019-11-12 15:20:07
【问题描述】:
我创建了一个非常基本的 JavaFX 应用程序
// Viewer.java
package crossjavafx;
public class Viewer {
public static void main(String[] args) {
MainViewer.main(args);
}
}
// MainViewer.java
package crossjavafx;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainViewer extends Application {
@Override
public void start(Stage stage) {
try {
System.out.println("Hello from Viewer");
Group root = new Group();
Scene scene = new Scene(root, 400, 300);
stage.setTitle("Hello");
stage.setScene(scene);
stage.show();
} catch (final Exception e) {
System.exit(1);
}
}
public static void main(String args[]){
launch(args);
}
}
还有简单的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>crossjavafx</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我在 Ubuntu 16.04 上使用 mvn 构建了它,并且:
./java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
我还安装了 openjfx 和 libopenjfx 软件包:
libopenjfx-java/xenial,xenial,now 8u60-b27-4 all [installed]
libopenjfx-jni/xenial,now 8u60-b27-4 amd64 [installed,automatic]
openjfx/xenial,now 8u60-b27-4 amd64 [installed]
应用程序构建成功,但启动失败。该过程在打印“来自查看器的您好”之前挂起。我开始了:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp crossjavafx-0.1.0-SNAPSHOT.jar crossjavafx.Viewer
我没有问题以相同的方式启动非 javafx 应用程序构建,即使从同一个 JAR 调用它的类,所以我想我的 JavaFX 安装有问题。
我还尝试使用 Java 8 Oracle SDK 构建并运行它,结果相同。我的 JavaFX 安装中是否缺少任何我忘记的内容?
编辑
我已经构建并尝试使用 Java 8 Oracle 运行它,打印堆栈跟踪。我得到了:
Hello from Viewer
Framebuffer object format is unsupported by the video hardware. (GL_FRAMEBUFFER_UNSUPPORTED)(FBO - 820)
Error creating framebuffer object with TexID 1)
[VGL] ERROR: OpenGL error 0x0502
[VGL] ERROR: in readPixels--
[VGL] 475: Could not Read Pixels
【问题讨论】:
-
catch (final Exception e)你确定你没有陷入这种情况吗?因为如果有异常,看看 what 异常是值得的。确保在退出之前将e.printStackTrace()放入catch正文中。 -
好吧,如果这是一个例外,我想我会以代码 1 退出。我会按照你的建议仔细检查,不幸的是我今天不能这样做。