JavaStub -- Generating Stub Java and HTML files automatically
Background
One of the tedious tasks when prototyping applets or just testing
a new Java construct is the extra time
required to build the HTML file needed to display the applet from
appletviewer or Netscape. If you want to simply test out a single
command, you spend much more time writing the HTML file or the application
infrastructure than you do the Java code you want to test.
JavaStub tries to simplify this process in two ways by building
stub files automatically from a base filename. First of all, it builds a
stub .java file that can be run as either a applet or an application
with identical results. Secondly, it builds a stub HTML file that loads
the .class file, so that the applet can be tested without writing any
additional HTML.
So just run JavaStub with an argument of Xxx, stick your test code in
paint() in Xxx.java, compile Xxx.java, then either run
Xxx.java or load Xxx.html from your browser.
Note that not all applet functionality can be obtained when running
standalone. For instance, getCodebase, showStatus, and showDocument
will not work. If you want this functionality, I suggest using
Jef Poskanzer's MainFrame class. That class implements the AppletStub
and AppletContext interfaces.
The original of this file is at
http://www.apl.jhu.edu/~hall/java/JavaStub.html. The source code
and class files are at
.../JavaStub.java, and
.../JavaStub.class, respectively. 4/96
Marty Hall
(hall@apl.jhu.edu).
See also my
Java Resources page for applets, class libraries, tutorials, info on
Java security and garbage collection, etc.
Permission is granted for unrestricted use and modification of
JavaStub. No warranty of any kind, of course.
Using JavaStub
JavaStub requires one argument: a base filename (no file extension) in
the current directory. It creates a .java and .html file in that same
directory based upon that base filename. It also takes optional arguments
-width, -height, -justPrint, -nomain, and -test.
java JavaStub Base-Filename
[-width W -height H -print, -nomain, -test]
- Base-Filename. A partial filename (no file extension) in the
current directory. For instance if this filename is HelloWorld, JavaStub
will build a stub HelloWorld.java and HelloWorld.html that references
HelloWorld.class. You would then normally edit HelloWorld.java and
add the code you want to test, compile HelloWorld.java to make
HelloWorld.class, and then either run HelloWorld as an application or
load HelloWorld.html from appletviewer or Netscape. To simply verify
the stubs were formatted correctly (or to check the size of the resultant
applet), you can compile HelloWorld.java and run it (or load
HelloWorld.html) without making any changes at all. JavaStub will
do this automatically if you supply the -test flag.
- -width W. Specifies WIDTH value to be put in the .html
file (and the first argument to resize() when run as an application).
If this is omitted, a default value (from the width variable of
JavaStub) is used instead.
- -height H. Specifies HEIGHT value to be put in the .html
file (and the second argument to resize() when run as an application).
If this is omitted, a default value (from the height variable of
JavaStub) is used instead.
- -print. Indicates that the contents of the .html and .java
files should be printed to the screen instead of written to disk.
- -nomain. Indicates that the .java file should not
have a main() that lets it run as an application with identical
behavior to the applet.
- -test. Indicates that the resultant .java file should
be compiled and then run automatically to verify the stubs were
created properly and to check the specified applet size. The stub
.java file simply displays the class name in a large font. In order
to make use of this option, edit the javac and
browser variables of JavaStub to indicate the pathnames
of your Java compiler and Java-enabled WWW browser.
This process is simplified by making an alias JavaStub that
means java JavaStub. For instance, on UNIX
you could put the following in your .cshrc:
alias JavaStub 'java JavaStub'
Examples
These examples assume that JavaStub.class is in CLASSPATH or the current
directory, and that you want to create CircleTest.java and CircleTest.html.
java JavaStub CircleTest
java JavaStub CircleTest -width 300 -height 250
java JavaStub CircleTest -nomain
java JavaStub CircleTest -print
java JavaStub CircleTest -test
These examples are identical to those above except that they assume that the
alias JavaStub means 'java JavaStub'.
JavaStub CircleTest
JavaStub CircleTest -width 300 -height 250
JavaStub CircleTest -nomain
JavaStub CircleTest -print
JavaStub CircleTest -test
4/96 Marty Hall
(hall@apl.jhu.edu).