我在Intellij中有JavaFx(maven)项目和以下运行配置:
(mvn) clean javafx:run
此配置在Windows上运行良好,但是在OSx上导致以下错误:
Graphics Device initialization failed for : es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:243)
at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
at java.base/java.lang.Thread.run(Thread.java:834)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: No toolkit found
at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
... 5 more
我搜索了此错误,它似乎与缺少JavaFx库有关。
但是,如果我执行以下运行配置:
(mvn) clean package
然后它会构建适当的JAR,然后可以在Mac上执行。
因此,我怀疑这可能是与javafx intellij插件有关的问题,但是我不确定如何解决此问题(如果确实存在问题)。
我的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>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.6</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.2</version>
</dependency>
<!-- the reason for having these dependency for all classifiers is here: https://stackoverflow.com/a/52654791/2463035-->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>12.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>12.0.2</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>12.0.2</version>
<classifier>mac</classifier>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<executions>
<execution>
<!-- Default configuration for running -->
<id>default-cli</id>
<configuration>
<mainClass>com.app.MyApplication</mainClass>
</configuration>
</execution>
<execution>
<!-- Configuration for debugging -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005</option>
</options>
<mainClass>com.app.MyApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.app.MainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
执行mvn clean -X javafx:run
后日志中的最后一个条目:
Executing command line: [C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\jbr\bin\java.exe, --module-path, C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-base\12.0.2\javafx-base-12.0.2-win.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-base\12.0.2\javafx-base-12.0.2.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-controls\12.0.2\javafx-controls-12.0.2-win.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-controls\12.0.2\javafx-controls-12.0.2.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-fxml\12.0.2\javafx-fxml-12.0.2-win.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-fxml\12.0.2\javafx-fxml-12.0.2.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-graphics\12.0.2\javafx-graphics-12.0.2-linux.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-graphics\12.0.2\javafx-graphics-12.0.2-mac.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-graphics\12.0.2\javafx-graphics-12.0.2-win.jar
C:\Users\Vasiliy\.m2\repository\org\openjfx\javafx-graphics\12.0.2\javafx-graphics-12.0.2.jar, --add-modules, javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.graphics,javafx.graphics, -classpath, C:\Users\Vasiliy\projects\wellsense-annotator\target\classes
C:\Users\Vasiliy\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar
C:\Users\Vasiliy\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar
C:\Users\Vasiliy\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar
C:\Users\Vasiliy\.m2\repository\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar
C:\Users\Vasiliy\.m2\repository\com\opencsv\opencsv\4.6\opencsv-4.6.jar
C:\Users\Vasiliy\.m2\repository\commons-beanutils\commons-beanutils\1.9.3\commons-beanutils-1.9.3.jar
C:\Users\Vasiliy\.m2\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar
C:\Users\Vasiliy\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:\Users\Vasiliy\.m2\repository\org\apache\commons\commons-collections4\4.2\commons-collections4-4.2.jar
C:\Users\Vasiliy\.m2\repository\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar
C:\Users\Vasiliy\.m2\repository\org\apache\commons\commons-text\1.3\commons-text-1.3.jar
C:\Users\Vasiliy\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar, com.wellsensevu.MyApplication]
任何帮助将不胜感激。
答案 0 :(得分:1)
为javafx-graphics
添加三个分类器后,就解决了构建胖跨平台jar的问题。
但是,在Mac上从终端运行pom(这不是IntelliJ问题),它会失败,并显示错误(No toolkit found
)。
如果您运行:mvn clean -X javafx:run
,则会找到发生此异常的原因:
[DEBUG] Executing command line: [.../Contents/Home/bin/java, \
--module-path, .../target/classes:\
.../.m2/repository/org/openjfx/javafx-base/13/javafx-base-13-mac.jar:\
.../.m2/repository/org/openjfx/javafx-controls/13/javafx-controls-13-mac.jar:\
.../.m2/repository/org/openjfx/javafx-fxml/13/javafx-fxml-13-mac.jar:\
.../.m2/repository/org/openjfx/javafx-graphics/13/javafx-graphics-13-linux.jar:\
.../.m2/repository/org/openjfx/javafx-graphics/13/javafx-graphics-13-mac.jar:\
.../.m2/repository/org/openjfx/javafx-graphics/13/javafx-graphics-13-win.jar,\
--add-modules,...]
请注意,它首先显示了linux
分类器,因为工件是按字母数字顺序排序的,并且三个jar实际上引用了同一模块javafx-graphics
。
由于--module-path
仅解决给定模块的首次出现(请参阅JEP 261或此answer),而忽略其他模块,因此mvn clean javafx:run
仅在Linux上工作。
最后,在当前pom下,胖跨平台jar将在Linux,Mac和Windows上运行,而javafx:run
仅在Linux上运行。
解决方案
为避免每次您要运行javafx:run
时都需要用分类器注释掉图形依赖性,同时保留它们来构建阴影插件,以下基于this answer的解决方案如下:
javafx-graphic
依赖项<profiles>
<profile>
<id>shadeProfile</id>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>mac</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>linux</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<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>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.app.MainClass</mainClass>
</transformer>
</transformers>
<shadedClassifierName>shaded</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
要运行此配置文件,您需要运行:
mvn -PshadeProfile package
这将包括pom中所有现有的依赖项,并且还将包括额外的三个jar。
现在mvn clean javafx:run
和java -jar yourShade.jar
都可以在Linux,Mac和Windows上运行。