Extending J

J provides a mechanism to support arbitrary user extensions. You can add a line like this to your preferences file:

where SampleExtension is the name of a class you've written, compiled, and placed in ~/.j or C:\.j. The class must provide the method public void run( ), and the class itself must be declared public. If these conditions are met, your class will be loaded when the editor starts up and the run method will be invoked.

One problem you're likely to run into with this is that any editor method or member variable referenced in your extension class must be explicitly declared public in the editor source; otherwise you'll get an IllegalAccessException. The short-term solution to this is to hack the editor source and make the thing public; the long-term solution is to tell me about it so that I can make sure it stays public in the future.

The easiest way to write your extension class is to develop and debug it in the j's top-level src directory; the loader will pick it up from there, so you don't have to copy it into ~/.j every time you compile it. When you're done you should move it into ~/.j and delete any extraneous copies.

Strictly speaking, your extension class does not have to live in ~/.j or C:\.j. You can also specify the fully qualified pathname of your extension's .class file in your preferences file, like this:

In this case you must specifically append the .class extension, as shown in the example.