Launching Java Applications Quickly
from Win95/NT

by M. Gallant 01/08/98

Instead of shelling to a DOS prompt and running the Java interpreter each time you need to run a standalone Java application (or the Appletviewer), why not set up a MS-DOS command shortcut? If you use the Java Development Kit (JDK) and are like most developers who always want to be on top of the latest release, the first thing you should do is set up your path and classpath specifications to use a system environment variable; for example in the autoexec.bat file for Win95 (similarly in the Network control panel for WinNT):
   set JAVA=C:\jdk1.1.5
   path %JAVA%\bin;C:\WINDOWS;C:\WINDOWS\COMMAND
   set classpath %JAVA%\LIB\CLASSES.ZIP
This allows you to use the Java environment variable in the MS-DOS command shortcut for greater convenience. (In fact, the on-line Win95 support ? tool-tip on the shortcut properties/Program tab/Cmd line field indicates this).
The example we will use here is a standalone Java application parString.class, a handy short utility which searches a text file (the argument of parString) for occurrences of user-specified strings and writes the results cumulatively to an output file javaout.txt.

    

Now we configure a MS-DOS shortcut for this application:
Copy the standard MS-DOS shortcut (in Start Menu/Programs) or right-click the desktop and select New/Shortcut. Type in "command.com" and then edit the entries under the Program tab as follows:

  Cmd line:   %JAVA%\bin\java.exe parString test.txt 
  Working :   C:\WINDOWS\Profiles\mig\Desktop\parstring

where the Working directory entry is the location of any file that the Java application needs to read (as a command-line argument here). Note that the Cmd line path reuses the Java environment variable, so that if you upgrade your JDK and change the environment variable in the autoexec.bat file, the program launching shortcuts will still work.

With this application shortcut set up, the Java application can be launched by double clicking the shortcut. This procedure is also very handy for invoking the JDK Appletviewer in exactly the same manner; for example:

  Cmd line:   %JAVA%\bin\appletviewer.exe testapplet.html
  Working :   C:\WINDOWS\Profiles\mig\Desktop\tests

For comparison, manually launching the appletviewer on a local html file requires one of the following file URL specifications (Win95 JDK1.1.5):

 appletviewer file:///C:/WINDOWS/Profiles/mig/Desktop/tests/testapplet.html
 appletviewer file:/C:/WINDOWS/Profiles/mig/Desktop/tests/testapplet.html
 appletviewer file:/WINDOWS/Profiles/mig/Desktop/tests/testapplet.html
where it is assumed that appletviewer.exe is in the PATH specification.

If you have several applets which you regularly run using appletviewer, why not set up a GUI Java application interface as a "launchpad" for each applet? A typical example of this is a launchpad for all the jdk1.1.5 demonstrations. Another typical example where a DOS shortcut launcher is very convenient is in launching the Java Web Server administration applet. Note that the Program tab has several other useful setup features (like minimizing the DOS parent window when the Java application starts). For those who prefer keyboard launching, the MS-DOS shortcut setup provides Ctrl+Alt+key shortcuts.

Sometimes, when a DOS application is launched from this kind of shortcut, a "not enough memory" failure results. This can be easily fixed by adjusting one of the Memory tab settings of the MS-DOS shortcut. Select the "Initial environment" list and change it from the default "auto" setting to say 2048 bytes. This can also be set globally in the config.sys file using a command like:

   SHELL=command.com /e:2048 /p
where the e:2048 indicates the amount of environment space to allocate for MS-DOS environment variables in bytes, the default being only 256 bytes.
Go Home ET