【发布时间】:2023-03-09 07:35:02
【问题描述】:
我一直在检查有关同一主题的其他问题,但找不到适合我的具体答案。
我们有一个 Java 8 的旧项目,这是一个我们为 Windows 和 Mac 构建的 JavaFX 应用程序。 我不是 Java 项目专家,开发该应用程序的公司已不存在。
由于 Apple 要求对应用程序进行公证,我们设法做到了。但是他们最近更改了要求,现在失败了: - 二进制文件使用早于 10.9 SDK 的 SDK - 签名不包含安全时间戳
这显示在大量内部库 (dylib) 以及 Contents/MacOS/App 中。 但这是我将来会面临的另一个问题。也许遵循以下说明: Notarize existing Java application for MacOS Catalina
主要问题是我们尝试使用 Java 11 + JavaFX 编译项目,但现在我们在构建应用程序时遇到了问题。 注意:为了做到这一点,我们只需从 JDK 8 更改为 JDK 11 以及下载和附加 JavaFX 11.0.2 库。
第一个问题是无法附加 JavaFX 库,但我们设法通过运行/编辑配置来完成。 它解决了这个问题,但现在当尝试从 Intellij 启动时,它会显示如下错误:
错误:(18, 27) java: 包 netscape.javascript 不存在
错误:(9, 24) java: 包 org.w3c.dom.html 不存在
java 找不到符号 HTMLAnchorElement
这里有什么问题?这些包是否已从 Java 11 中删除? Intellij 允许我关注课程并查找内容。
此外,我们使用 Maven 来构建应用程序。我已经尝试编辑配置等,在 Build, Execution, Deployment -> Maven -> Runner 中添加 VM 选项,但是在尝试打包应用程序时,它找不到 JavaFX 库:
--module-path /path/to/javafx-sdk-11.0.2/lib --add-modules=javafx.controls,javafx.fxml
我应该如何在 Maven 中加载 JavaFX 模块?
因此,此时我已将 JavaFX 库包含在 Intellij 中,但无法从中启动,也无法将 JavaFX 包含在 Maven 中。
感谢您对此的任何指导。
编辑:
我设法通过用新的替换导入来修复 netscape 和 HTMLAnchorElement 错误:
import jdk.nashorn.api.scripting.JSObject;
Element anchorElement = (Element)event.getCurrentTarget();
并通过在 pom.xml 文件中添加以下内容修复了 maven 中 javafx 的问题:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
我可以从 Intellij 启动应用程序,但是在尝试通过 Maven 打包它时,我得到了这个:
问题:无法创建任务或键入 javafx:com.sun.javafx.tools.ant:deploy。 原因:名称未定义
与此相关:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<configuration>
<target name="build-app">
<ant antfile="./javafx.build.xml"/>
</target>
</configuration>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
这是 javafx.build.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="create-app" name="AppName" xmlns:fx="javafx:com.sun.javafx.tools.ant" xmlns:if="ant:if"
xmlns:unless="ant:unless">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath=".;${java.home}/../lib/ant-javafx.jar"/>
<condition property="onmac">
<os family="mac"/>
</condition>
<condition property="onwin">
<os family="windows"/>
</condition>
<target name="create-app" description="create jar file fx" if="os.name">
<echo message="Ant creates javafx app" />
<fx:deploy width="800" height="600" outdir="target/dist" outfile="App" nativeBundles="image" version="1.4.5">
<fx:info title="App Name">
<fx:icon href="installable/mac/logo.icns" kind="default" if:set="onmac" ></fx:icon>
<fx:icon href="src/main/resources/resources/logo_256.ico" kind="default" if:set="onwin"></fx:icon>
</fx:info>
<fx:application name="App Name" mainClass="recorder.DesktopRecorder" />
<fx:resources>
<fx:fileset dir="target/app-module-1.4.5-distribution" includes="*"/>
</fx:resources>
</fx:deploy>
<exec executable="./installable/mac/create-dmg.sh" if:set="onmac"/>
<exec executable="C:\Program Files (x86)\Inno Setup 5\ISCC" if:set="onwin">
<arg value="installable/windows/innosetup_prod.iss" />
</exec>
</target>
我在项目中包含了ant-javafx.jar文件,改成这样:
classpath="./ant-javafx.jar"
但是在创建苹果“app”文件时还是失败了:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project app-module: An Ant BuildException has occurred: The following error occurred while execution this line :
[错误] /path/to/app/javafx.build.xml:24:错误:捆绑器“Mac 应用程序映像”(mac.app)无法生成捆绑包。
[ERROR] 围绕 Ant 部分......@ /path/to/app/target/antrun/build-build-app.xml 中的 4:38
【问题讨论】: