How to execute a custom java code during pre installation and pre uninstallation.

Comments

1 comment

  • Avatar
    wojciechka

    Running Java applications after installation - such as during Post Installation or Pre Uninstallation should work normally. You can simply use runProgram, such as:

    <runProgram>
      <program>jre/bin/java</program>
      <programArguments>-jar "path/to/app.jar"</programArguments>
      <workingDirectory>${installdir}</workingDirectory>
    </runProgram>
    

    The above will work if the installer deploys Java runtime into ${installdir}/jre.

    However, running Java in Pre Installation is a bit more difficult - since it will require unpacking entire JRE to a temporary directory.

    Assuming you bundle your Java as "jre-${platform_name}" (i.e. jre-linux, jre-windows, jre-linux-x64) folder in "jre" component, it would require the following actions:

    
    <!-- delete directory if it existed -->
    <deleteFile>
      <path>${system_temp_directory}/jre-temp</path>
    </deleteFile>
    
    <!-- unpack JRE -->
     <unpackDirectory>
       <component>jre</component>
       <destination>${system_temp_directory}/jre-temp</destination>
       <folder>jre${platform_name}</folder>
       <origin>jre</origin>
     </unpackDirectory>
    
    <!-- unpack JAR that is needed -->
     <unpackFile>
       <component>jars</component>
       <destination>${system_temp_directory}/jre-temp/test.jar</destination>
       <folder>jars</folder>
       <origin>test.jar</origin>
     </unpackFile>
    
    <!-- run the application -->
     <runProgram>
       <program>bin/java</program>
       <programArguments>-jar test.jar</programArguments>
       <workingDirectory>${system_temp_directory}/jre-temp</workingDirectory>
     </runProgram>
    
    <!-- clean up -->
     <deleteFile>
       <path>${system_temp_directory}/jre-temp</path>
     </deleteFile>
    

    The jars are assumed to be a test.jar file in "jars" component, "jars" folder.

    The names of components and folders are the short names (<name> tag) for components and folders that contain JRE and JAR files respectively.

    You can find more information on unpacking files before installation here

Please sign in to leave a comment.