Reloading

When writing Java, or any other JVM language, to be used in Excel there’s no need to shut down Excel and restart it every time you make a change to your code.

Instead, you can simply tell Jinx to reload your compiled code so you can test it out immediately.

Before you can reload Jinx you need to make sure you have developer_mode enabled in your jinx.ini file.

[JINX]
developer_mode = 1

This setting enables reloading and adds the “Reload Jinx” menu item to Excel. It is enabled by default.

By default, Jinx copies your JAR and class to a shadow folder before it loads them. This is so that the original files aren’t locked by the JVM and you can over-write them when you rebuild your project. When Jinx reloads, it discards the ClassLoader used to load your classes previously, copies the new files, and then re-loads the classes using a new ClassLoader. Once the old JAR and class files in the shadow folder are no longer in use they are cleaned up automatically.

If you need to change the location of the shadow folder you can do so by changing the shadow_path setting in your jinx.ini file.

Manual Reloading

After working on some changes to your code and building your project you can tell Jinx to reload your classes by selecting Reload Jinx from the Jinx menu in the Add-Ins tab.

Jinx Add-Ins Menu

You can also configure the Excel ribbon to have a Reload button. This is done for you in the ribbon.xml file included in the example project.

Jinx Ribbon

A simple ribbon file with just the Reload button would look like this:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
        <tabs>
            <tab id="Jinx" label="Jinx">
                <group id="Tools" label="Tools">
                    <button id="Reload"
                            size="large"
                            label="Reload Jinx"
                            onAction="jinx.reload"/>
                </group>
            </tab>
    </ribbon>
</customUI>

Note the onAction attribute is set to jinx.reload. This binds that ribbon button to Jinx’s reload action.

See Ribbon Toolbars for more information about customizing the ribbon toolbar.

Automatic Reloading

Rather than have to reload manually every time you make a change to your code, Jinx can watch and reload automatically as soon as any of your JAR or class files are updated.

To enable automatic reloading, set auto_reload = 1 in the [JINX] section of your config file.

[JINX]
auto_reload = 1

Programmatic Reloading

Reloading can be triggered programmatically by calling the ExcelAddIn.reload() method. This method schedules the Jinx add-in to reload as soon as possible.

Excluding Classes from Reloading

Sometimes it is not desirable, or possible, to reload certain classes. For classes that are partly implemented in a native library it is often the case that reloading the class causes problems.

For this reason it is possible to exclude classes from being reloaded when Jinx reloads. Any changes made to these classes will not be reflected until Excel is restarted.

To exclude classes from being reloaded use the reload_exclude list in the jinx.ini config file. Wildcards can be used to exclude all classes from a package.

For example,

[JINX]
reload_exclude =
    com.microsoft.sqlserver.jdbc.*
    microsoft.sql.*
    mssql.*
    com4j.*