PRB: Environment Variables Are Lost When Running from VJ6 IDEID: Q215413
|
When you run a Java application within the Visual J++ 6.0 integrated development environment (IDE), none of the environment variables are set. However, when you run the application from the command line using jview or wjview, variables are set as expected. Note that this also includes the CLASSPATH environment variable.
When you run an application within the Visual J++ 6.0 IDE, the application's environment is not inherited from the parent process and variables are empty. However, when you run it outside the Visual J++ 6.0 IDE (from the command line or otherwise), the application's environment is inherited from the parent process and environment variables have the values of the parent.
You need to programmatically set environment variables when you run the application within the Visual J++ 6.0 IDE. To work around this problem, you can start the application outside the Visual J++ 6.0 IDE (using jview) and attach to the process for debugging with access to the environment variables (please see the comments in the sample code below).
This behavior is by design.
import com.ms.win32.*;
public class EnvTest
{
public static void main(String args[]) throws Exception
{
// Uncomment the "Thread.sleep(10000); line to work around
// this problem. From a command prompt, run "jview EnvTest"
// and attach to the process (on the Visual J++ 6.0 Debug
// menu, click Processes). Click close on the dialog
// box while the thread is sleeping. The IDE debugger will
// stop at the first break point.
//Thread.sleep(10000);
StringBuffer val = new StringBuffer(256);
Kernel32.GetEnvironmentVariable("TEMP", val, 256);
String output = "The TEMP Environment variable is: ";
if (val.length() == 0)
val.append("Not defined.");
output += val;
User32.MessageBox(0, output, "Application Message", 0);
System.out.println("Press the <ENTER> key to continue.");
System.in.read();
}
}
Not defined.
For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java,
please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/
Additional query words:
Keywords : kbide kbVJ600 kbGrpJava
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: February 19, 1999