Java Tip 25: How to use Visual J++ with the JDK 1.1 beta

Here's a step-by-step guide to using the JDK 1.1 beta with Visual J++

Current versions of Microsoft's Visual J++ Java development system do not support Java 1.1. So how do you integrate Sun's upcoming Java Development Kit (JDK) version 1.1 with Visual J++? Don't panic! This tip will show you the way.

Before you begin, a disclaimer and some warnings

This program modifies the Visual J++ (VJ++) system so that the Sun JDK 1.1 compiler and run time are invoked instead of the Microsoft versions. This is an exclusive change: You cannot (easily) switch between this and the "normal" VJ++ environment. You have to reverse the regedit changes.

The Developer Studio has a number of compile and run-time switches that are not understood by the JDK. These are ignored by the program. Note that the debugging switches are not implemented either -- mainly because you (probably) cannot use the Developer Studio debugger with JDK 1.1 compiled code.

We have not checked that the environment variables are set, and there are other occurrences of "bad coding practice." (These are Tim's, not Rob's, by the way!) Feel free to tidy up the code.

Note: This example is entirely unsupported, and you use it totally at your own risk.

Step 1: Set it up

This program is used as a hook to replace calls to the Microsoft jvc compiler or the jview virtual machine interpreter with calls to the Sun equivalents -- javac and java, respectively.

Set the environment variables `JAVACLASS' and `JAVABIN' to point to your environment. JAVACLASS is a standard classpath, and will have `.' prepended to it. JAVABIN is the directory your Java binary files are in. You can change these environment variable names in the source if you wish.

Compile and link to a stand-alone .exe file, and place it in a location of your choosing.

Modify the registry (using regedit), search for jvc, and replace the entry with the name (and path) of the generated .exe file to point to your executable. Modify the settings for your project by setting the "RuntimeInterpreter" option to be your executable. Enter `-run' as the first parameter for the interpreter.

Now, when you build your project, the Developer Studio will call javac (via the executable) with the given parameters, and all output will go to the normal output window in VJ++. Double-clicking on errors/warnings should take you to the line where the error/warning occurred.

When you execute your project, the Developer Studio will call java for the given class -- and the DOS window will wait until you press "Return."

Step 2: Compile it

The program reads the command line given to javac, and converts each parameter (if necessary) to an equivalent parameter accepted by jvc. Some parameters are ignored entirely (for example, classpath specs). Others have a straight conversion (for example, /g => -g for debugging).

We then invoke the new command line -- that is, call javac with the translated options -- and read the standard error from the compiler. (Any compiler errors or warnings get sent to the standard error.) We translate the standard error into the error message format given by the Microsoft javac and hand these back to the development environment, which has no idea that it was javac, not jvc, that produced the message.

And there you have it. Remember, this technique uses undocumented features; there are no guarantees that it will work with anything but the current Microsoft Visual J++.

Rob Turner and Tim Shaw are leading secret lives, but were last seen painting those mini M&Ms with new and improved colors, including sky blue and blush pink. Rob Turner is an ex-academic who worked in universities in the United Kingdom for seven years before leaving to become a senior systems engineer at Kinesis Products Ltd, a document management company. For the past year Rob has worked on a Java-based document management system called Global Recall. His academic interests were (and still are) programming languages (especially functional languages), compilers, and software development techniques. Tim Shaw leads a secret life in a small hut built in the Bronze-age style on the only small hill in our area. He drinks wheat beer and smokes dried hedge-clippings and his only contact with the outside world is via a high-speed laser link to the local ISP. Try your luck at getting the author's real bio by emailing him.