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]

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

HTML 2.0 Checked.
4/96 Marty Hall (hall@apl.jhu.edu).