> Java > tools > selfinstall
> Java > tools > selfinstall
by ZweiBieren Package com.physpics.tools.selfinstall Java coffee cup logo

A jar file is almost an application. But it needs libraries, and would look better with an icon shortcut. All these accouterments are possible--for MSWindows--with the SelfInstall package. Together with some build.xml magic, SelfInstall wraps Xxxx.jar into InstallXxxx.jar. When the latter is downloaded and clicked, it unwraps into a full folder with an execute-me shortcut that can be copied to anywhere.

Installing from an InstallXxxx.jar file

To install from an InstallXxxx,jar, the user puts it in the desired application directory and clicks it.  After installation InstallXxxx.jar can be deleted. A short cut is created; it can be copied to a menu or the start page and will continue to work to start the application.

The code

src Jdoc class note
package physpics.com.tools.selfinstall
Java steaming cup doc with "J" SelfInstall.java Is executed for a click on an InstallXXX.jar file. Extracts the files to be installed and builds the shortcut

The SelfInstall incorporates jshortcut to write the shortcut icon file to the installation directory.

For apps/fontviewer, InstallFontViewer.jar contains these files

   417 META-INF/MANIFEST.MF
  1039 com/physpics/tools/selfinstall/Pictools.properties
  9130 com/physpics/tools/selfinstall/SelfInstall.class
 62464 jshortcut_amd64.dll
146944 jshortcut_ia64.dll
 58368 jshortcut_x86.dll
  5644 net/jimmc/jshortcut/JShellLink.class
  2746 README.txt
 22382 FontViewer.ico
 26354 fontcategories.txt

JShellLink chooses the dll based on the destination archittecture.

Making an icon

This directory need only include those images to appear on the webpage or for deployment. For the Windows installer there should be a ${project.name}.ico file containing three icons at sizes 16, 32, and 64. (I create .ico files with ImageMagick 6.7.1-10, on Windows. {The cygwin version, 6.4.0.6-2, fails to create proper .ico files.} If the icons have white where they should be transparent, the Imagemagick command is

convert icon16x16.png icon32x32.png icon64x64.png -transparent white icon.ico

Creating InstallXxxx.jar

This directory need only include those images to appear on the webpage or for deployment. For the Windows installer there should be a ${project.name}.ico file containing three icons at sizes 16, 32, and 64. (I create .ico files with ImageMagick 6.7.1-10, on Windows. {The cygwin version, 6.4.0.6-2, fails to create proper .ico files.} If the icons have white where they should be transparent, the Imagemagick command is
convert icon16x16.png icon32x32.png icon64x64.png -transparent white icon.ico

<!-- =========================== -->
<!-- I N S T A L L E R  -  Construct a self-installer .jar file -->

    <target name="installer" 
            description="Build a one-click installer .jar file" 
            depends="init, compile, jar, 
                -define-default-to-be-installed,
                -before-installer,
                -ensure-more-to-be-installed, 
                -do-installerjar, -after-installer"
    />
    <target name="-before-installer" description="overrideable"/>
    <target name="-after-installer" description="overrideable"/>

    <target name="-define-default-to-be-installed">
        <resources id="default.to.be.installed">
                <fileset dir="forweb" includes="README.txt"/>
                <fileset dir="build/classes" includes="assets/**/*"/>
                <fileset dir="${tree.icon.directory}" 
                	includes="${tree.icon.file}"/>
        </resources>
    </target>

    <!-- ensure existence of more.to.be.installed -->
    <target name="-installer-conditions">
        <condition property="have.more.to.be.installed">
            <isreference refid="more.to.be.installed"/>
        </condition>
    </target>
        
    <target name="-ensure-more-to-be-installed" 
                depends="-installer-conditions"
                unless="have.more.to.be.installed">
        <resources id="more.to.be.installed"/>
    </target>

    <target name="-do-installerjar">
        <!-- (the following is an expansion of the antcall
                        suggested in selfinstall/build.xml) -->
        <jar file="forweb/Install${project.name}.jar">
            <fileset dir="${JAVAROOT}/tools/selfinstall/build/classes" 
                      includes="**/*" excludes="**/README.*"/>
            <resources refid="default.to.be.installed"/>
            <resources refid="more.to.be.installed"/>
            <manifest>
                <attribute name="Main-Class"
                        value="com.physpics.tools.selfinstall.SelfInstall"/>
                <attribute name="Built-By" value="${project.author}"/>
                <attribute name="Implementation-Vendor" value="${site.vendor}"/>
                <attribute name="Implementation-Title" value="${project.name}"/>
                <attribute name="Implementation-Version" 
                    value="${project.release.string}"/>

                <!-- create the icon -->
                <section name="${tree.icon.file}">
                    <attribute  name="Shortcut-Name" value="${project.name}"/>
                    <attribute name="Jar-File" value="${project.name}.jar"/>
                    <attribute name="Description"
                        value="${project.short.description}"/>
                </section>
            </manifest>
        </jar>    
    </target>

 

The build.xml in selfinstall has a task that is invoked by other build files to actually create the InstallXXX.jar file

 
Copyright © 2018 ZweiBieren, All rights reserved. Oct 9, 2018 18:11 GMT Page maintained by ZweiBieren