我正在尝试创建一个包含以下内容的跨平台JAR:
- 命令行应用程序(“工具”)
- JavaFX应用程序(“查看器”)
我遵循以下解决方案:Maven Shade JavaFX runtime components are missing 我在Windows上创建了一个JAR,可以从中运行“工具”和“查看器”。我将其复制到Linux机器上,并且由于我仍然可以这种方式运行该工具,因此Viewer挂起,甚至不打印到标准输出。
这是我的pom.xml
<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.11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.11</source>
<target>1.11</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>
简化的Tool.java:
package crossjavafx;
public class Tool {
public static void main(String[] args) {
System.out.println("Hello");
}
}
简化了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);
}
}
我正在执行两个应用程序:
java -cp crossjavafx-0.1.0-snAPSHOT.jar crossjavafx.Tool // works on win and linux
java -cp crossjavafx-0.1.0-snAPSHOT.jar crossjavafx.Viewer // works on win,hangs on linux
修改 我将下面的1.8更改为1.11。
<plugin>
<configuration>
<source>1.11</source>
<target>1.11</target>
</configuration>
</plugin>
最终,在Linux上运行Viewer时出现以下错误消息:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fddc02dcf55,pid=20666,tid=20685
#
# JRE version: OpenJDK Runtime Environment (11.0.1+13) (build 11.0.1+13-Ubuntu-3ubuntu116.04ppa1)
# Java VM: OpenJDK 64-Bit Server VM (11.0.1+13-Ubuntu-3ubuntu116.04ppa1,mixed mode,sharing,tiered,compressed oops,g1 gc,linux-amd64)
# Problematic frame:
# C [libGL.so.1+0x89f55]
在Windows上,我正在使用: OpenJDK运行时环境采用OpenJDK(内部版本11.0.4 + 11) OpenJDK 64位服务器VM采用OpenJDK(内部版本11.0.4 + 11,混合模式)