| Developer's Daily | JBuilder Education |
| main | java | perl | unix | DevDirectory |
Introduction
Oftentimes 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. This happens when you're making a small change to an existing file, running a quick test case to determine the validity of an approach, when you're using your favorite editor but still want to use the JBuilder command-line tools, or if 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, the Java interpreter, java, or perhaps other JDK tools such as javadoc or appletviewer.
Unfortunately, JBuilder does not automatically configure your system
so you can access these tools - you have to do this part yourself.
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 does not configure the DOS environment for you, so if you want to access these command-line tools you'll have to configure your system manually. This involves the properly setting the DOS environment variables PATH, CLASSPATH, JAVA_COMPILER, and JAVA_HOME. If these variables are not set, your command-line tools will not work properly. Fortunately Borland has made configuration of these variables easy with the inclusion of a setvars.bat batch program.
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 1 shows the set command 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,
etc. - are currently set.
| Figure 1: | Output from the set command before the configuration shows that none of the variables needed to run JBuilder's command-line tools are configured. |
As mentioned, Borland makes the configuration process easier for you providing a DOS batch file named setvars.bat that 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
Command-line configuration
You can configure your environment in several different ways. In the first method, you can take the old-fashioned approach of modifying the config.sys and autoexec.bat files to run the setvars command each time your computer is booted. In the second and third approaches, you run setvars manually just before you use any command-line tools. In this article we'll demonstrate these three configuration approaches, and let you choose what works best for you in your work environment.
Approach #1: Configuring the autoexec.bat and config.sys files
The basic setup process for this approach is very simple, and it's the
one I use on my Windows 95 computer.
The first step is to include the following command in your autoexec.bat
file:
Note that my installation directory is not the default installation directory. If you selected the default installation directory, C:\JBuilder, you'll issue this command:
To keep these errors from occurring, you'll need to add a line to your config.sys file to increase your DOS environment space. I've found that adding the following line to my config.sys file increases my environment space sufficiently to eliminate these errors:
Depending on the length of your installation path, and the other variables you set, you may need to increase this 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 will look like that
shown in Figure 2. Notice the addition of the environment
variables PATH, CLASSPATH, JAVA_COMPILER, and
JAVA_HOME.
| Figure 2: | Output from the set command after running setvars.bat shows that PATH, CLASSPATH, and other necessary JBuilder variables are now set. |
Now, with these variables set, you can run JBuilder's command-line tools
- bcj, bmj, etc., without any problems.
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 following two approaches, 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.
The way I work with Java, this is the most effective configuration for
me. With as much memory as I have in my computer, allocating 1K of
memory for the environment space is no big deal.
Approach #2: Running setvars from the command-line manually
The second approach to solve the command-line problem is simply to run the setvars command manually before you run the bcj command. Instead of putting the command in your autoexec.bat file, you'll simply run the setvars command like this
Of course, as you've seen before, this will fail if you haven't increased your DOS environment space already, so you'll still need to include the shell=command.com command in your config.sys file.
The only advantage this approach offers compared to the first approach
is that it increases your DOS environment space without filling the increased
memory until you run the setvars command. This is not much of an
advantage, but I included this method here because it compares to the third
method shown below, which is recommended in the JBuilder documentation.
Approach #3: Modifying the MS-DOS properties graphically
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 Windows95 graphical interface. Although this appears easier, this only configures your environment space, and you'll still need to run the setvars command manually each time you want access to the JBuilder command-line tools, like we just showed in the second approach.
To follow this approach, start a DOS session by selecting the Run | Programs | MS-DOS Prompt from the Windows 95 taskbar. If this opens a full-screen DOS window, hit [Alt]-[Enter] to shrink the window from full-screen mode down to a smaller window on the Windows 95 desktop.
Next, left-click on the Control Menu in the upper-left corner of this DOS window, and select Properties. When the MS-DOS Prompt Properties window opens, click on the Memory tab. In this tab group, change the Initial environment setting from the default of Auto to something sufficiently large, such as 1024 or 2048. (Even using my long customized installation path, 1024 was sufficient for my installation.) Then click OK, and a dialog window will warn you that these changes won't take effect until you restart the program. Click OK on that dialog window, then type exit in the DOS window to close it.
Next, start a new DOS session by selecting Start | Programs | MS-DOS Prompt again. This time your initial environment settings will be large enough to run the setvars command successfully from the command line. To run setvars, type
Again I don't see too any advantages to this approach, other than saving
the extra environment space you just configured until you need it when
you run setvars manually.
Running bcj and java
After you've configured your system properly using one of the methods described above, you'll be able to use JBuilder's command-line tools. This includes the Borland Compiler for Java, bcj, to compile your Java code, and the java command to run your programs.
For instance, if you want to compile a file named test.java, you'll type
Conclusion
When you want to use the JBuilder and Java JDK command-line tools, you'll first need to configure your MS-DOS environment properly. Borland has simplified this process by creating the setvars.bat program, but you'll still need to manually increase your DOS environment space using one of the methods shown. Expert users often find that some things are just easier and faster to do at the command-line, and this tip gets your command-line configuration working properly.
Note: This article originally appeared in the Ziff-Davis' Inside
JBuilder Journal, and is reprinted here with the permission of ZDJournals.
The author of the article now works for our company, Developer's
Daily.
Copyright © 1998-2005 DevDaily Interactive, Inc.
All Rights Reserved.