我创建了一个非常基本的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>
我已经使用mvn和在Ubuntu 16.04上构建了它:
./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]
该应用程序已成功构建,但无法启动。在打印“来自Viewer的Hello”之前,该过程挂起。我开始了:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp crossjavafx-0.1.0-snAPSHOT.jar crossjavafx.Viewer
即使从相同的JAR调用其类,我也可以用相同的方式启动非javafx应用程序构建,因此,我想我的JavaFX安装有问题。
我还尝试构建它并使用Java 8 Oracle SDK运行,结果相同。我的JavaFX安装中遗忘了什么吗?
修改
我已经构建并尝试使用Java 8 Oracle运行它,并打印stacktrace。我得到了:
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