如何将 .jar 文件添加到本机包? [英] How to add a .jar file to native bundle?

查看:40
本文介绍了如何将 .jar 文件添加到本机包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 javafx 2.2 中创建一个应用程序,在编译本机包 (EXE) 时,我可以看到在运行时我错过了一个我需要的库.

Hi i'm creating an application in javafx 2.2 and while compiling a native bundle (EXE) I can see that in the Runtime I miss a library I need.

MyApp\runtime\jre\lib\ext\sunjce_provider.jar

MyApp\runtime\jre\lib\ext\sunjce_provider.jar

我尝试在 build.xml 中像这样添加它

I try adding it like this in my build.xml

<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
            nativebundles="exe"
           outdir="${basedir}/${dist.dir}" outfile="${application.title}">
    <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
    <fx:resources>

        ...

        <fx:fileset dir="${platform.home}/jre/lib/ext" includes="sunjce_provider.jar"
                type="data"/>

    </fx:resources>
    <fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>

但那只剩下

MyApp\app\sunjce_provider.jar

MyApp\app\sunjce_provider.jar

有没有办法做到这一点?

Is there a way to accomplish this?

推荐答案

包括应用程序库

本节展示了如何包含您的应用程序所依赖的标准 jar.

This section shows how to include standard jars which your application relies upon.

来自 JavaFX ant 任务参考的示例 build.xml 片段,关键行是 <fx:fileset dir="dist" includes="lib/*.jar"/>:

Sample build.xml snippet from the JavaFX ant task reference, the key line is <fx:fileset dir="dist" includes="lib/*.jar"/>:

<!-- Expect definition of JavaFX ant tasks is already imported -->

<fx:jar destfile="dist/application.jar">
    <!-- Details about application -->
    <fx:application name="Sample JavaFX application"
            mainClass="test.MyApplication"/>

    <!-- Define what auxilary resources are needed -->
    <fx:resources>
        <fx:fileset dir="dist" includes="lib/*.jar"/>
    </fx:resources>

    <!-- What to include into result jar file?
         Everything in the build tree -->
    <fileset dir="build/classes"/>

    <!-- Customize jar manifest (optional) -->
    <manifest>
        <attribute name="Implementation-Vendor" value="Samples Team"/>
        <attribute name="Implementation-Version" value="1.0"/>
    </manifest>
</fx:jar>   

修改 JRE 组件

本节向您展示如何自定义与您的应用程序捆绑在一起的 Java 运行时组件.

This section shows you how to customize the the Java runtime components that are bundled with your application.

请参阅 Java 部署博客,了解在本机打包中包含 sun jce 提供程序(有问题指出:sunjce_provider.jar 在 jre 中用于独立的 javafx 应用程序).

See the Java Deployment blog on including the sun jce provider in native packaging (noted in question: sunjce_provider.jar in jre for standalone javafx application).

相关部分(从博客条目中复制粘贴)是:

Relevant sections (copy and pasted from the blog entry) are:

如果您使用打包工具来生成可安装的包,则可能需要在将应用程序镜像打包到安装程序之前对其进行调整.为什么?例如,您可能希望对应用程序进行签名,因此它似乎不受操作系统的信任(例如取悦 Mac OS X Gatekeeper).

If you are using packaging tools to produce an installable package there could be a need to tweak the application image before it is wrapped into the installer. Why? For example you may want to sign the application, so it does not appear to be untrusted to the OS (for example to please Mac OS X Gatekeeper).

此外,默认情况下,自包含应用程序不包含 Java 运行时的完整副本.我们只包含一组必需的组件.采取这种方法的部分原因是我们希望减小封装尺寸.但是,在某些情况下,您的应用程序可能依赖于这些可选组件,在这种情况下,您需要一种将它们添加到私有运行时的方法.例如,如果缺少 jre/lib/ext/sunjce_provider.jar,https 连接将无法工作.

Also by default a self-contained application does not contain full copy of Java Runtime. We only include set of mandatory components. Part of the reason why this approach was taken is that we want to reduce the package size. However, there are situations where your application may depend on these optional components and in that case you will need a way to add them to the private runtime. For example https connections will not work if jre/lib/ext/sunjce_provider.jar is missing.

目前,这可以通过提供在应用程序映像填充后执行的自定义配置脚本来实现.就像上面带有图标的示例一样,您需要启用详细输出以查找脚本文件的名称,然后将其拖放到打包工具可以找到的位置.请注意,脚本语言也是特定于平台的.目前我们只支持 Mac/Linux 上的 shell 和 windows 上的 Windows 脚本.

Currently this can be achieved by providing a custom config script that is executed after application image is populated. Like in the example above with the icon, you need to enable verbose output to find the name of the script file and then drop it to the location where packaging tools will find it. Note that scripting language is platform specific too. Currently we only support shell for Mac/Linux and Windows Script on windows.

如何找出应用程序映像所在的位置?当前自定义脚本在存储配置文件的目录中运行,但可以使用相对平台特定路径访问应用程序映像.您可以从详细输出或通过将环境变量 JAVAFX_ANT_DEBUG 设置为 true 以保留中间构建工件来导出此路径.

How do you find out where the application image is located? Currently custom scripts are run in the directory where config files are stored but application image can be accessed using relative platform specific path. You can derive this path from verbose output or by setting environment variable JAVAFX_ANT_DEBUG to true to keep intermediate build artifacts.

这是示例脚本(由 John Petersen 提供),您可以使用它在 Windows 平台上将 jre/lib/ext/sunjce_provider.jar 添加到 MyApp 的应用程序包中.使用 Javascript 编写脚本,但您也可以使用 VBScript 编写 Windows 脚本.

Here is sample script (contributed by John Petersen) you can use to add jre/lib/ext/sunjce_provider.jar to the application package of MyApp on the Windows platform. Script using Javascript but you could also use VBScript for Windows scripting.

<?xml version="1.0" ?>  
<package>  
   <job id="postImage">  
    <script language="JScript">  
     <![CDATA[  
        var oFSO = new ActiveXObject("Scripting.FileSystemObject");  
        var oFolder = oFSO.getFolder(".");  
        var from = oFolder.path + "\\MyApp\\app\\sunjce_provider.jar";  
        var to = oFolder.path + "\\MyApp\\runtime\\jre\\lib\\ext";  
        if (!oFSO.FolderExists(to)) {  
          oFSO.CreateFolder(to);  
        }  
        to += "\\";  
        oFSO.CopyFile(from, to);  
     ]]>  
    </script>  
   </job>  
</package> 

这篇关于如何将 .jar 文件添加到本机包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆