我在IntelliJ中创建了一款应用程序,当有人在工作时经过我的Mac电脑时,我可以在不被察觉的情况下阅读ePubs(iBook往往很突出).它基本上只是一个没有装饰的JavaFX窗口,带有一个标签,在epub中一次接收一个段落标签,由箭头键控制向前和向后移动. 这个应用程序在我的PC(JDK21)上编译和打包得很好,但当我试图为1.8(工作中的Java版本)构建它时,它一直抱怨这个应用程序的编译版本(55)比Mac上的版本(52)更新.
它可以无错误地清理、构建、打包.但是,当我try 使用命令行"Java-jar readerfx.jar"时,它抛出错误.
我的猜测是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>
到目前为止,我try 的是:
- 下载、解压并将我的Home和PATH变量设置为1.8版本的Java(OpenLogic-OpenJDK-8u402-b06-windows-64)
- 在我的IntelliJ设置中,在Project下,将我的"SDK"设置为1.8
- 在我的IntelliJ设置中的Project下,将我的"Language Level"设置为8
- 在我的IntelliJ设置中,在模块下,将"模块SDK"设置为"Project SDK 1.8"
- 创建了启动主应用程序的启动器应用程序
- 在我的POM.xml文件中,将maven编译器插件配置中的"源"和"目标"变量更改为1.8
- 我try 删除"JavaFX-Controls"和"JavaFX-fxml"的依赖关系,因为Java 1.8的库中仍然有JavaFX,但之后找不到类javaFX.Application.Application,所以我将它们放回..
- 在网上找到的某个地方,我可以将"版本"和"目标"添加到maven-Assembly-plugin的配置中,但当我添加它们时,IntelliJ说"此处不允许元素源".