How to add a .jar file to native bundle?

☆樱花仙子☆ 提交于 2019-12-11 04:17:55

问题


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

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>

But that only leaves it at

MyApp\app\sunjce_provider.jar

Is there a way to accomplish this?


回答1:


Including Application Libraries

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

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>   

Modifying the JRE components

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

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:

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).

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.

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.

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.

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> 


来源:https://stackoverflow.com/questions/18241130/how-to-add-a-jar-file-to-native-bundle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!