INPRISE Online And ZD Journals Present:
Configuring your system to use JBuilder command-line tools
By Alvin J. Alexander
Often, as you're developing Java programs, you'll want to be able to compile Java code from the DOS command line or run JDK command-line programs. You may be making a small change to an existing file or running a quick test case to determine the validity of an approach. Or, perhaps you're using your favorite editor but still want to use the JBuilder command-line tools, or you prefer the command line to the JBuilder IDE. In any case, your desire is the same: to gain access to command-line tools, such as JBuilder's bcj or bmj compilers, Java's java interpreter, or other JDK tools, such as javadoc or appletviewer. In this article, we'll show you how to configure your Windows 95 system to run these JBuilder and Java commands from your DOS command prompt.
Before the configuration
The JBuilder installation process doesn't configure the DOS environment for you. So, if you want to access these command-line tools, you'll have to configure your system manually. Doing so involves setting the DOS environment variables PATH, CLASSPATH, JAVA_COMPILER, and JAVA_HOME. If you don't set these variables, your command-line tools won't work properly. Fortunately, Borland has included a setvars.bat batch program that lets you configure these variables easily. Before starting the configuration process, you can look at your current environment variable settings by opening a DOS window and typing the set command. The set command displays the names and values of variables that are currently configured in your DOS environment. Figure A shows the set command's output from a Windows 95 MS-DOS window. Notice that at this point none of the environment variables needed by Java or JBuilder—PATH, CLASSPATH, and so on—are set.

Figure A: Before configuration, the set command yields output like this.
As we mentioned, Borland makes the configuration process easier by providing the setvars.bat DOS batch file, which sets these environment variables for you. This batch file is located in the bin subdirectory of your JBuilder installation directory. For instance, my JBuilder installation directory is C:\Apps\Win95\Borland\JBuilder. The setvars.bat file's complete path is C:\Apps\Win95\Borland\JBuilder\bin\setvars.bat. If you've selected the default JBuilder installation directory, your path will be C:\JBuilder\bin\setvars.bat.
Command-line configuration
You can configure your environment in several ways. In the first method, you take the old-fashioned approach of modifying the config.sys and autoexec.bat files to run the setvars command each time you boot your computer. In the second and third approaches, you run setvars manually just before you use any command-line tools. We'll demonstrate all three configuration approaches and let you choose which is best for your work environment.
Approach #1: Configuring the autoexec.bat and config.sys files
The basic setup process for modifying config.sys and autoexec.bat is very simple; I use this approach on my Windows 95 computer. The first step is to include a command like the following in your autoexec.bat file: C:\JBuilder\bin\setvars C:\JBuilder This line runs the setvars command and gives setvars the path to your JBuilder installation directory. With this information, setvars properly sets the required environment variables. (Note that if you're like me and you don't use the default JBuilder installation directory, you'll need to use the appropriate path in both parts of this line.) Because the setvars command sets some of the environment variables to fairly large values, you'll probably also need to increase your DOS environment space by adding a line to your config.sys file. If you don't increase the environment space, setvars will generate Out of environment space errors. I've found that adding the following line to my config.sys file increases my environment space sufficiently to eliminate these errors: shell=c:\command.com /e:1024 /p Depending on the length of your installation path and the other variables you set, you may need to set the value even higher. After rebooting your computer, open a DOS window and type the set command. Your output should now be much longer than before and look like that shown in Figure B. Notice the addition of the environment variables PATH, CLASSPATH, JAVA_COMPILER, and JAVA_HOME. With these variables set, you can run JBuilder's command-line tools without any problems.

Figure B: The set command yielded this output after we ran setvars.bat.
The advantage of this approach is that you can run these commands any time you open an MS-DOS window or re-boot in MS-DOS mode. Unlike the two approaches we'll discuss next, you won't need to run setvars manually—your environment will always be ready for you when you want to run Java or JBuilder commands at the DOS prompt. Given the way I work with Java, this is the most effective configuration for me. My computer has plenty of memory, so allocating 1 KB of memory for the environment space is no big deal.
Approach #2: Manually running setvars from the command line
The second approach to solving the command-line problem is to run the setvars command manually before you run the bcj command. Instead of putting the command in your autoexec.bat file, you simply run the setvars command like this: C:\JBuilder\bin\setvars C:\JBuilder after you open a DOS window. Of course, as you've seen before, this line will fail if you haven't increased your DOS environment space adequately. You'll still need to include the shell command in your config.sys file. The only advantage this approach offers over the first approach is that it increases your DOS environment space without filling the increased memory until you run the setvars command. This isn't much of an advantage; I included this method to compare to the third method, which is recommended in the JBuilder documentation.
Approach #3: Graphically modifying the MS-DOS properties
The third approach to configure your DOS command-line system is the approach recommended in the JBuilder documentation. In this approach, you configure the DOS environment through the Windows 95 graphical interface. Although this technique appears easier, it only configures your environment space—you'll still need to run the setvars command manually each time you want access to the JBuilder command-line tools. To follow this approach, start a DOS session by selecting the Start | Programs | MS-DOS Prompt from the Windows 95 taskbar. If this opens a full-screen DOS window, press [Alt][Enter] to shrink the window on the Windows 95 desktop. Next, click on the control menu in the upper-left corner of the DOS window and select Properties. When the MS-DOS Prompt Properties dialog box opens, click on the Memory tab. In this tab group, change the Initial Environment setting from the default (Auto) to something sufficiently large, such as 1024 or 2048, as shown in Figure C. (Even using my long, customized installation path, 1024 was sufficient for my installation.) Click OK, and a dialog box will warn you that these changes won't take effect until you restart the program. Click OK, then enter exit in the DOS window to close it.

Figure C: Set the Initial Environment to a number large enough to handle your installation.
Next, start a new DOS session by again selecting Start | Programs | MS-DOS Prompt. This time your Initial Environment settings will be large enough to run the setvars command successfully from the command line. To run setvars, type C:\JBuilder\bin\setvars C:\JBuilder (Use your path, if it differs from the default.) Again, the setvars program creates the environment variables you need to run the bcj, bmj, and other command-line tools. Type set, then examine the command output to be sure you've set the variables PATH, CLASSPATH, JAVA_COMPILER, and JAVA_HOME properly. Again, I don't see many advantages to this approach. As before, it only saves the extra environment space you just configured until you run setvars manually.
Running bcj and java
After you've configured your system properly using one of the methods we've described, you'll be able to use JBuilder's command-line tools. These include the Borland Compiler for Java (bcj) to compile Java code and the java command to run programs. For instance, if you want to compile a file named test.java, type bcj test.java to compile the code. Assuming this successfully creates a file named test.class, you can then run this file through the java interpreter like this: java test This is just a sampling of the JBuilder and Java commands available from the command line. Of course, you can also run javadoc and other Java JDK command-line tools once you've properly configured your command-line environment.
Conclusion
Expert users often find that some tasks are easier and quicker at the command line. When you want to use the JBuilder and Java JDK command-line tools, you'll first need to configure your MS-DOS environment properly, as we've demonstrated in this article. Borland has simplified this process by creating the setvars.bat program, but you still must manually increase your DOS environment space.
Alvin J. Alexander is the president and chief scientist of Mission Data Corporation (www.missiondata.com), an employee-owned software engineering and systems integration firm. You can reach him at alvina@missiondata.com.
Back to Top
Back to Index of Articles
Copyright © 1997, ZD Journals, a division of Ziff-Davis Inc. ZD Journals and ZD Jounals logo are trademarks of Ziff-Davis Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis is prohibited.
|