Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include java.exe in the runtime built

To create a installer for my javafx application, I have followed tutorial . And it as expected makes the installer.

The directory structure it makes is this:

MyApp

  +app

  +runtime

  +MyApp.exe

  +MyApp.ico

The runtime contains the Java runtime. But the issue is, my application creates some Java process and it needs the path of the java.exe. But on browsing through the above folder runtime, it does not contain java.exe.

i.e.

runtime

+jre

    +bin

         +java.dll

          missing java.exe

How do get the path of java.exe so that I can use it to start other java process. Or how do start a java process from java.dll?

PS: This link discusses the same question but does not answer it.

like image 318
Jatin Avatar asked Oct 05 '22 02:10

Jatin


1 Answers

The Native Packaging Cookbook on Fine Tuning the Application Bundle by the Oracle Java Deployment Team contains instructions on how to customize the pieces of the JRE to be included in a Self-Contained Application.

I'll just copy and paste the relevant section here in case the original link goes dead:

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> 

The above discusses copying the sunjce_provider.jar file from the JRE installation to the application bundle, but the procedure for copying any other file, including java.exe should be similar.

Further details of how to initially create the bundle to be customized are in the JavaFX Deployment Guide.

like image 51
jewelsea Avatar answered Oct 13 '22 10:10

jewelsea