Ant 在 JDK9 上的 maven 构建期间无法创建 .pkg 文件

Posted

技术标签:

【中文标题】Ant 在 JDK9 上的 maven 构建期间无法创建 .pkg 文件【英文标题】:Ant fails to create .pkg file during maven build on JDK9 【发布时间】:2018-03-05 12:52:16 【问题描述】:

我正在将 javaFx 应用程序的构建过程从 JDK8 升级到 JDK9,但遇到了问题。

构建过程由 Maven 运行,并使用 Ant 将 jar 文件捆绑到 pkg 文件(在 Mac Osx 上)和 Windows 中的 MSI 文件中。

Maven 版本:3.5.2。蚂蚁版:

我在构建执行期间遇到异常:

com.oracle.tools.packager.ConfigException: java.lang.RuntimeException: File /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/jmods does not belong to <our project binaries folder>
    at jdk.packager/com.oracle.tools.packager.mac.MacPkgBundler.validate(MacPkgBundler.java:568)
    at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:370)
    at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348)
    at com.sun.javafx.tools.ant.DeployFXTask.execute(DeployFXTask.java:310)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at jdk.internal.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at jdk.internal.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:313)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
    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:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

在 maven 中,我使用以下插件(全部升级到最新版本):

maven 资源插件:3.0.2 maven 依赖插件:3.0.2 exec-maven-plugin: 1.6.0 maven-compiler-plugin: 3.7.0(配置为使用 jdk 9) maven-surefire-plugin: 2.20.1

在我们的 build.xml 中配置的 fx:deply 任务中构建失败,如下所示:

<fx:deploy   install="true"
        verbose="true" nativeBundles="$native.bundles" 
        outdir="$dist.dir/bundle" outfile="$app.name" >

        <fx:application id="$app.id" name="$app.name" mainClass="$javafx.main.class" version="$app.version" />

        <fx:preferences shortcut="true" menu="false" install="true"/>
        <fx:secondaryLauncher 
            mainClass="com.pingidentity.proxy.proxyhelper.ProxyExternalEntryPoint"
            name="ProxyHelperSetup"/>
        <fx:secondaryLauncher 
            mainClass="com.pingidentity.proxy.proxyhelper.AutoUpdatesExternalEntryPoint"
            name="AutoUpdatesSetup"/>
        <fx:secondaryLauncher
            mainClass="com.pingidentity.proxy.proxyhelper.MigrationHelper" 
            name="MigrationHelperSetup"/>
        <fx:resources >
            <fx:fileset dir="$dist.dir" includes="$jar.name"/>
            <fx:fileset dir="$dist.dir/lib" />
            <fx:fileset dir="$resources.dir"  type="license" includes="license.rtf"/>
                <fx:fileset dir="$resources.dir"  type="license" includes="testwelcome.rtf"/>
            <fx:fileset dir="$basedir/UnlimitedJCEPolicy" includes="*.jar" />
            <!-- the attr os="mac" not works, so I created emtpy folder in case of windows -->
            <fx:fileset dir="$dist.dir/uninstaller" />
        </fx:resources>
        <fx:info  title="$app.name" vendor="$vendor" category="public.app-category.productivity">
        </fx:info>

        <fx:platform>
            <fx:jvmarg value="-Xms128m"/>
            <fx:jvmarg value="-Xmx384m"/>
            <fx:jvmarg value="-Xmn64m"/>
        </fx:platform>

        <fx:bundleArgument arg="mac.CFBundleVersion" value="$app.version"/>
        <fx:bundleArgument arg="mac.signing-key-developer-id-app" value="Developer ID Application: Ping Identity Corporation (6U3RF4C84N)"/>
        <fx:bundleArgument arg="mac.signing-key-developer-id-installer" value="Developer ID Installer: Ping Identity Corporation (6U3RF4C84N)"/>
            <fx:bundleArgument arg="mainJar" value="$dist.dir/$jar.name" />

    </fx:deploy>

有什么想法可以让这个在 JDK 9 上工作吗?

【问题讨论】:

您是在 OSX 环境中构建它吗?您是否可以尝试在不同的 OSX 版本或其他操作系统上构建它? 我发现添加这一行会使错误消失: . 【参考方案1】:

我发现添加这一行会使错误消失: build.xml -> fx:deploy ->

<fx:runtime strip-native-commands="false">
    <fx:add-modules value="java.base"/>
    <fx:module-path value="$java.home/jmods"/>
    <fx:module-path value="$basedir/modules"/>
</fx:runtime>

【讨论】:

以上是关于Ant 在 JDK9 上的 maven 构建期间无法创建 .pkg 文件的主要内容,如果未能解决你的问题,请参考以下文章

Ant 到 Maven - 多个构建目标

Ant 在构建期间不读取 IvySettings.xml 文件

java+构建+工具+Ant+Maven+Gradle

Maven学习总结(56)—— MavenGradle Ant 哪一个构建工具最适合你?

构建dubbo分布式平台-maven构建ant-utils工具项目

构建dubbo分布式平台-maven构建ant-utils工具项目