JavaFX Maven Assembly插件打包生成错误JDK版本的问题求助
Epub阅读器JDK1.8编译后运行版本不兼容问题
我在IntelliJ上开发了一款Epub阅读器,用于Mac工作环境下阅读Epub文档——相比iBook,这款应用是无装饰的JavaFX窗口,通过标签逐段展示内容,支持方向键前后翻页,不会过于显眼。
在本地PC(JDK21)上编译、打包均正常,但为工作环境的JDK1.8构建后,执行java -jar readerfx.jar时报错,提示应用由更高版本(版本号55,对应JDK11)编译,高于Mac上的JDK版本(版本号52,对应JDK1.8)。清理、构建、打包过程无报错,仅运行时出现该问题。
我怀疑是POM文件的依赖版本覆盖了编译器设置,但不确定具体原因。以下是我的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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.reader</groupId> <artifactId>readerfx</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>13</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>13</version> </dependency> <dependency> <groupId>javax.xml.parsers</groupId> <artifactId>jaxp-api</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> <version>1.0.b2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.6.0</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.reader.Launcher</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
我已尝试的解决步骤:
- 下载并配置环境变量指向openlogic-openjdk-8u402-b06-windows-64(JDK1.8)
- 在IntelliJ项目设置中,将SDK设为1.8,语言级别设为8
- 在IntelliJ模块设置中,将Module SDK设为项目SDK 1.8
- 创建Launcher类启动主应用
- 在POM.xml的maven-compiler-plugin配置中设置source和target为1.8
- 尝试移除javafx-controls和javafx-fxml依赖(因JDK1.8自带JavaFX),但出现找不到
javafx.application.Application类的问题,故恢复依赖 - 尝试在maven-assembly-plugin配置中添加source和target,但IntelliJ提示“元素source不允许在此处”
内容的提问来源于stack exchange,提问作者dieterweireldt
相关产品推荐
相关产品推荐

