1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
---|
2 | |
---|
3 | <html> |
---|
4 | |
---|
5 | <head> |
---|
6 | <title>J User's Guide - Extending J</title> |
---|
7 | <LINK REL="stylesheet" HREF="j.css" TYPE="text/css"> |
---|
8 | </head> |
---|
9 | |
---|
10 | <body> |
---|
11 | |
---|
12 | <a href="contents.html">Top</a> |
---|
13 | |
---|
14 | <hr> |
---|
15 | |
---|
16 | <h1>Extending J</h1> |
---|
17 | |
---|
18 | <hr> |
---|
19 | |
---|
20 | <p> |
---|
21 | |
---|
22 | J provides a mechanism to support arbitrary user extensions. You can add a |
---|
23 | line like this to your <a href="preferences.html">preferences</a> file: |
---|
24 | <pre> |
---|
25 | extension=SampleExtension |
---|
26 | </pre> |
---|
27 | where <code>SampleExtension</code> is the name of a class you've written, |
---|
28 | compiled, and placed in <code>~/.j</code> or <code>C:\.j</code>. The class must |
---|
29 | provide the method <code>public void run( )</code>, and the class itself must |
---|
30 | be declared <code>public</code>. If these conditions are met, your class |
---|
31 | will be loaded when the editor starts up and the <code>run</code> method will |
---|
32 | be invoked. |
---|
33 | <p> |
---|
34 | One problem you're likely to run into with this is that any editor method or |
---|
35 | member variable referenced in your extension class must be explicitly declared |
---|
36 | <code>public</code> in the editor source; otherwise you'll get an |
---|
37 | <code>IllegalAccessException</code>. The short-term solution to this is to |
---|
38 | hack the editor source and make the thing <code>public</code>; the long-term |
---|
39 | solution is to <a href="mailto:peter@armedbear.org">tell me about it</a> so |
---|
40 | that I can make sure it stays <code>public</code> in the future. |
---|
41 | <p> |
---|
42 | The easiest way to write your extension class is to develop and debug it in the |
---|
43 | j's top-level <code>src</code> directory; the loader will pick it up from |
---|
44 | there, so you don't have to copy it into <code>~/.j</code> every time you |
---|
45 | compile it. When you're done you should move it into <code>~/.j</code> and |
---|
46 | delete any extraneous copies. |
---|
47 | <p> |
---|
48 | Strictly speaking, your extension class does not have to live in |
---|
49 | <code>~/.j</code> or <code>C:\.j</code>. You can also specify the fully |
---|
50 | qualified pathname of your extension's <code>.class</code> file in your |
---|
51 | preferences file, like this: |
---|
52 | <pre> |
---|
53 | extension=/home/peter/SampleExtension.class |
---|
54 | </pre> |
---|
55 | In this case you must specifically append the <code>.class</code> extension, as |
---|
56 | shown in the example. |
---|
57 | |
---|
58 | </body> |
---|
59 | |
---|
60 | </html> |
---|